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];
    }
  • 相关阅读:
    Repository中进行模糊查询
    Spring jpa添加查询条件
    java后端repository层中进行模糊查询
    MyBatis小白问题 1、Invalid bound statement (not found): com.itheima.dao.UserDao.findAll,2、Resources.getResourceAsStream()报错
    Date类型做加减运算
    时间格式转换
    mysql-支持的数据类型
    mysql—表的完整性约束
    数据库—表操作(第二章)
    mysql—使用python操作mysql数据库(第五章)
  • 原文地址:https://www.cnblogs.com/jiackyan/p/3109790.html
Copyright © 2011-2022 走看看