MPMoviePlayer - 黑屏 - iOS 5 - 没有视频播放
在 iOS 4 中,这段代码可以播放电影:
-(IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
//[self.view addSubview:moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
//[moviePlayerController release];
}
现在,我只看到黑屏。没有控制,什么都没有。视频路径正确,我测试过。如果我通过单击按钮添加一个白色的子视图,它就可以工作。所以调用该方法。
提前致谢!
In iOS 4 this Code worked to play a movie:
-(IBAction)playMovie:(id)sender
{
NSURL *url = [NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"testbild1" ofType:@"m4v"]];
MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
UIView *testview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
[testview addSubview:moviePlayer.view];
[self.view addSubview:testview];
//[self.view addSubview:moviePlayer.view];
//[moviePlayer setFullscreen:YES animated:YES];
}
- (void)moviePlaybackComplete:(NSNotification *)notification
{
MPMoviePlayerController *moviePlayerController = [notification object];
[[NSNotificationCenter defaultCenter] removeObserver:self
name:MPMoviePlayerPlaybackDidFinishNotification
object:moviePlayerController];
[moviePlayerController.view removeFromSuperview];
//[moviePlayerController release];
}
Now, I only get a blackscreen. No controls, nothing. Video path is correct, I tested that. If I add just a white Subview by button click, it works. So the method is called.
Thanks in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我通过放入 .h 文件解决了这个问题。
带有 ARC 的 iOS 5 的工作方式与 iOS 4 不同。.m
文件必须是:
I have solved the issue by putting in the .h file
iOS 5 with ARC works differently than iOS 4.
The .m file must be:
如果您使用的是 iOS 5.0 或 5.1,请检查您的 moviePlyer 是否有如下设置。
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
如果是这样,当您设置
[moviePlayer setFullScreen:YESanimated:YES];
然后将调用 MPMoviePlayerPlaybackDidFinishNotification 通知,而不是调用 MPMoviePlayerWillExitFullscreenNotification 或 MPMoviePlayerDidExitFullscreenNotification
If you are on iOS 5.0 or 5.1, check your moviePlyer has a setting like below.
[moviePlayer setControlStyle:MPMovieControlStyleFullscreen];
If so, when you set
[moviePlayer setFullScreen:YES animated:YES];
then MPMoviePlayerPlaybackDidFinishNotification notification will be called instead of being called MPMoviePlayerWillExitFullscreenNotification or MPMoviePlayerDidExitFullscreenNotification