iOS 播放沙盒视频

来源:互联网 发布:星盘哪些数据最重要 编辑:程序博客网 时间:2024/06/05 20:34

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{

    

    NSString* path =[NSString stringWithFormat:@"%@/Documents/%@",NSHomeDirectory(),[recordArryobjectAtIndex:indexPath.row]];//本地路径

    //视频URL

   NSURL *url = [NSURLfileURLWithPath:path];

    //视频播放对象

    

   NSLog(@"==%@",url);

    

    self.navigationController.navigationBarHidden =TRUE;

    

    Recordmovie = [[MPMoviePlayerControlleralloc] initWithContentURL:url];

    

    Recordmovie.controlStyle =MPMovieControlStyleFullscreen;

    

    Recordmovie.movieSourceType =MPMovieSourceTypeFile;

    

    [Recordmovie.viewsetFrame:self.view.bounds];

    

    Recordmovie.initialPlaybackTime =0;

    

    

    

    [self.viewaddSubview:Recordmovie.view];

    

    

    

    

    [Recordmovie prepareToPlay];

    

    [Recordmovie play];


     

    //注册一个播放结束的通知

    [[NSNotificationCenterdefaultCenter] addObserver:self

                                            selector:@selector(myMovieFinishedCallback:)

                                                name:MPMoviePlayerPlaybackDidFinishNotification

                                              object:Recordmovie];

    

    

}


#pragma mark -------------------视频播放结束委托--------------------


/*

 @method 当视频播放完毕释放对象

 */

-(void)myMovieFinishedCallback:(NSNotification*)notify

{

    //视频播放对象

   MPMoviePlayerController* theMovie = [notify object];

    

    

    

    //销毁播放通知

    [[NSNotificationCenterdefaultCenter] removeObserver:self

                                                   name:MPMoviePlayerPlaybackDidFinishNotification

                                                 object:theMovie];

    [theMovie.viewremoveFromSuperview];

    

    self.navigationController.navigationBarHidden =NO;


    

}

0 0
原创粉丝点击