当前位置: 动力学知识库 > 问答 > 编程问答 >

ios - Get Local Document Video File but Black screen come again

问题描述:

 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];

网友答案:

Let's try:

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

I try and it works, can play videos.

分享给朋友:
您可能感兴趣的文章:
随机阅读: