我无法在MPMovieplayercontroller
中播放电影。我在谷歌搜索了很多,但每次我都有黑屏。我也尝试检查isPreparedToPlay
属性,但它总是错误的。
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setContentURL:[self.videos objectAtIndex:0]];
NSLog(@"Playing videos : %@", [self.moviePlayer contentURL]);
NSLog(@"Playing videos : %@", [[self.moviePlayer contentURL] absoluteString]);
[self.moviePlayer.view setFrame:CGRectMake (0, 0, 320, 460)];
[self.view addSubview:self.moviePlayer.view];
//self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;
/*[self.moviePlayer.view setFrame:self.view.bounds];
[self.moviePlayer prepareToPlay];
[self.moviePlayer setShouldAutoplay:NO];*/
[self.moviePlayer play];
第一个NSLog打印出一些奇怪的东西(为什么有" ......"?):
/Users/Athos/Library/Developer/CoreSimulator/Devices/15855707-E728-4542-8DAA-3B71362D7DB6/data/Containers/Data/Applicati ... unny.mp4
但第二个是好的(我会手动检查文件是否在那里:
/Users/Athos/Library/Developer/CoreSimulator/Devices/15855707-E728-4542-8DAA-3B71362D7DB6/data/Containers/Data/Application/2ACD0002-1A1E-484C-B4E4-9486EBCFF74A/Documents/BuckBunny.mp4
你有什么线索吗? 提前致谢
答案 0 :(得分:2)
self.moviePlayer = [[MPMoviePlayerController alloc] init];
[self.moviePlayer setContentURL:[NSURL fileURLWithPath:[self.videos objectAtIndex:0]]];
// Use FileURLWithPath
答案 1 :(得分:1)
试试这个:
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"%@/BuckBunny.mp4"];
NSURL *movieURL = [NSURL fileURLWithPath:path];
self.moviePlayer = [[MPMoviePlayerController alloc] init];
if(movieURL!=nil){
[self.moviePlayer setContentURL:movieURL];
[self.moviePlayer.view setFrame:CGRectMake (0, 0, 320, 460)];
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer play];
}