获取本地文档视频文件但黑屏再次出现

时间:2014-04-23 09:49:18

标签: ios

    NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
    NSString *documentsDirectory = [paths objectAtIndex:0];
    NSString *pathVideo = [documentsDirectory stringByAppendingPathComponent:@"MyVideo.mp4"];    

    NSURL *movieURL = [NSURL fileURLWithPath:pathVideo];
    self.moviePlayer = [[MPMoviePlayerController alloc] init];
    [self.moviePlayer setShouldAutoplay:YES];
    [self.moviePlayer setContentURL:movieURL.absoluteURL];
    [self.moviePlayer setMovieSourceType:MPMovieSourceTypeFile];
    [self.moviePlayer setControlStyle:MPMovieControlModeDefault];
    [self.moviePlayer setFullscreen:NO];
    [self.moviePlayer setScalingMode:MPMovieScalingModeNone];
    self.moviePlayer.view.frame = CGRectMake(40, 40, 240, 350);
    [self.view addSubview:self.moviePlayer.view];
    [self.moviePlayer prepareToPlay];
    [self.moviePlayer play];

1 个答案:

答案 0 :(得分:0)

让我们试试:

NSArray *paths =  NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,       NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *pathVideo = [documentsDirectory stringByAppendingPathComponent:@"MyVideo.mp4"];
BOOL isExisted = [[NSFileManager defaultManager] fileExistsAtPath:pathVideo];
// be sure that isExisted is YES == file is existed at path

我尝试它有效,可以播放视频。