iOS6 and MPMoviePlayerController - Black View

2019-02-20 06:30发布

I have a MPMoviePlayerController that plays a video embedded within a View. This worked perfectly on iOS5/5.1 etc... but since upgrading to iOS6 this has stopped working and now the view is just black. Does anyone have any ideas or similar issues?

Thanks

3条回答
我想做一个坏孩纸
2楼-- · 2019-02-20 06:52

Try this one......

NSString *resourcePath = [[NSBundle mainBundle] pathForResource:@"ffffd" ofType:@"mp4"];
NSURL *url = [NSURL fileURLWithPath:resourcePath];
MPMoviePlayerViewController *moviePlayer = [[MPMoviePlayerViewController alloc] initWithContentURL:url];
moviePlayer.view.frame = CGRectMake(0, 0, 500, 500);
moviePlayer.moviePlayer.shouldAutoplay=YES;
moviePlayer.moviePlayer.controlStyle = MPMediaTypeMusicVideo;
[moviePlayer.moviePlayer setFullscreen:YES animated:YES];
[self.view addSubview:moviePlayer.view];
[moviePlayer.moviePlayer play];
查看更多
女痞
3楼-- · 2019-02-20 07:04

Actually, MPMediaTypeMusicVideo is defined as MPMediaType, below is the definition: MPMediaTypeMusicVideo = 1 << 11, (2048)

Is it the undocumented thing?

查看更多
我命由我不由天
4楼-- · 2019-02-20 07:08

I was access to the same problem, and finally finding that the key line "[player prepareToPlay]" missing. in iOS5 it does no matters, but in iOS6 it lead to a black screen;

MPMoviePlayerController *player =
[[MPMoviePlayerController alloc] initWithContentURL: myURL];
[player prepareToPlay];
[player.view setFrame: myView.bounds];  // player's frame must match parent's
[myView addSubview: player.view];
// ...
[player play];
查看更多
登录 后发表回答