MPMoviePlayerController doesn't work after upgrading to iOS 5

拟墨画扇 提交于 2019-12-11 04:06:51

问题


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];

but it doesn't work on iPad 5 Simulator. I get a black frame with no movie nor playback controls.

I read the Apple changelog about MPMoviePlayerController, but I didn't found anything about this problem. Can you help me?


回答1:


I solved the problem in this way: in my header file I wrote:

MPMoviePlayerController *moviePlayer;

with this property:

@property(nonatomic, strong) MPMoviePlayerController *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...




回答2:


You don't mention what type of URL you are trying to play, however, if it's an HTTP Live Streaming resource (.m3u8 file), then be aware that iOS 5.0 seems to have tightened up on validating the contents of the m3u8 index file.

Specifically, I've discovered that:

  1. No individual segment can be more than twice as long as the #EXT-X-TARGETDURATION value;

  2. The #EXTINF value (segment length in seconds) can, now, only be an integer value.

If one of these is your problem, running your application under the iOS 5.0 simulator should show a warning in the debugger console.




回答3:


For HLS on iOS5, the TARGETDURATION value is really not the target duration but needs to be the maximum duration. So it should be set to the largest segment in the file.



来源:https://stackoverflow.com/questions/7796329/mpmovieplayercontroller-doesnt-work-after-upgrading-to-ios-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!