问题描述:

 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.

相关阅读:
Top