zoukankan      html  css  js  c++  java
  • 本地视频播放-ios

    // 视频播放
    -(void)playMovie
    {
        self.navigationItem.rightBarButtonItem.enabled = YES;
        
        self.movieName = @"1305178253912757X4VMU00207002";
        self.folderName = @"1-11";
        //在VideoFolder文件夹下建立子文件夹
        NSFileManager *fm = [[NSFileManager alloc]init];
        NSString *docs = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES)lastObject];
        NSString *folderPath = [docs stringByAppendingPathComponent:[NSString stringWithFormat:@"VideoFolder/%@/%@.mp4",self.folderName,self.movieName]];
        BOOL exists = [fm fileExistsAtPath:folderPath];
        if (exists) {
            NSURL *urls = [NSURL fileURLWithPath:folderPath];
            movie = [[MPMoviePlayerController alloc]initWithContentURL:urls];
            movie.controlStyle = MPMovieControlStyleDefault;
            [movie  prepareToPlay];
            [movie.view setFrame:CGRectMake(0, 0, 320, [UIScreen mainScreen].bounds.size.height-60)];
            movie.movieSourceType = MPMovieSourceTypeFile;
            movie.initialPlaybackTime = -1;
            [self.view addSubview:movie.view];
            //注册一个播放结束的通知
            [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(movieFinishedCallback:) name:MPMoviePlayerPlaybackDidFinishNotification object:movie];
            [movie play];
        }
        [fm release];
        
    }
    //当视频播放结束的时候关闭视频
    -(void)movieFinishedCallback:(NSNotification*)notify
    {
        //视频播放对象
        MPMoviePlayerController* theMovie = [notify object];
        //销毁播放通知
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:theMovie];
        [theMovie.view removeFromSuperview];
        [movie.view removeFromSuperview];
        // 释放视频对象
        //    [movie release];
        [theMovie release];
    }
    //手动关闭视频
    -(void)closeMovie
    {
        self.navigationItem.rightBarButtonItem.enabled = NO;
        
        [[NSNotificationCenter defaultCenter] removeObserver:self
                                                        name:MPMoviePlayerPlaybackDidFinishNotification
                                                      object:movie];
        [movie.view removeFromSuperview];
    }
  • 相关阅读:
    linux rar安装
    ce
    Hp培训学习注册攻略
    Novell云计算
    bigdata
    Quest *nix Xwindows
    Foglight 5.6.7 控制台jboss报404
    view
    架构-数据库访问-SQL语言进行连接数据库服务器-DB-Library:DB-Library
    架构-数据库访问-SQL语言进行连接数据库服务器:SQL语言进行连接数据库服务器
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3109790.html
Copyright © 2011-2022 走看看