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];
答案 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
我尝试它有效,可以播放视频。