升级到iOS 5后,MPMoviePlayerController不起作用 [英] MPMoviePlayerController doesn't work after upgrading to iOS 5
问题描述
此代码在iPad 4.3模拟器上完美运行:
This code works perfectly on iPad 4.3 Simulator:
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模拟器上不起作用。我得到一个没有电影和播放控件的黑框。
but it doesn't work on iPad 5 Simulator. I get a black frame with no movie nor playback controls.
我读了关于MPMoviePlayerController的Apple更新日志,但我没有发现任何关于这个问题的内容。你能帮助我吗?
I read the Apple changelog about MPMoviePlayerController, but I didn't found anything about this problem. Can you help me?
推荐答案
我用这种方式解决了问题:在我的头文件中我写道:
I solved the problem in this way: in my header file I wrote:
MPMoviePlayerController *moviePlayer;
使用此属性:
@property(nonatomic, strong) MPMoviePlayerController *moviePlayer;
以及我初始化moviePlayer的方法:
and in the method in which I init the moviePlayer:
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:movieUrl];
self.moviePlayer = player;
似乎将玩家分配给某个属性会保存该玩家。但不要问我为什么......
It seems that assigning the player to a property "saves" the player. But don't ask me why...
这篇关于升级到iOS 5后,MPMoviePlayerController不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!