升级到 iOS 5 后 MPMoviePlayerController 不工作

标签 mpmovieplayercontroller ios5

此代码在 iPad 4.3 模拟器上完美运行:

NSString *source = [mediaObject objectForKey:@"source"];
NSString *videoPath = [NSString stringWithFormat:@"%@/%@", path, source];
NSURL *videoUrl = [NSURL fileURLWithPath:videoPath];

MPMoviePlayerController *videoPlayer = [[MPMoviePlayerController alloc] initWithContentURL:videoUrl];
videoPlayer.shouldAutoplay = NO;

videoPlayer.view.frame = CGRectMake(xPos, yPos, width, height);

[backgroundImageView addSubview:videoPlayer.view];

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(videoPlaybackStateDidChange:) name:MPMoviePlayerPlaybackStateDidChangeNotification object:videoPlayer];

但它在 iPad 5 模拟器上不起作用。我得到一个没有电影或播放控件的黑框。

我阅读了有关 MPMoviePlayerController 的 Apple 变更日志,但我没有发现任何有关此问题的信息。你能帮帮我吗?

最佳答案

我是这样解决问题的:在我的头文件中我这样写:

MPMoviePlayerController *moviePlayer;

具有此属性:

@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;

在我初始化 moviePlayer 的方法中:

MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;

似乎将玩家分配给某个属性可以“拯救”玩家。但是不要问我为什么...

关于升级到 iOS 5 后 MPMoviePlayerController 不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7796329/

相关文章:

youtube - 在 MPMoviePlayerController 中播放 Youtube 视频或播放 RTSP - 3GP 链接

ios - 禁用 MPMoviePlayerController 中的控件

ios - MPMoviePlayerViewController 播放头(时间)通知

ios - MPMoviePlayerController 不显示视频

ios - 您将如何以及在何处使用 instantiateViewControllerWithIdentifier

ios - iOS-在 View Controller 中,放置用户 session 管理代码的最合逻辑的地方在哪里?

iphone - MPMoviePlayer 锁屏播放/暂停音频

iphone - UIPickerView根据数据显示数据

xcode - 如何为 iPhone 和 iPad 制作 .xib 文件?

ios - cocoa - 获取 iphone 地址组