【发布时间】:2012-04-01 22:24:46
【问题描述】:
大家好,我对 MPMoviePlayerController 有一个奇怪的行为
我播放它的视频的几率... 偶数没有!
正如这里所说的MPMoviePlayerController will play once, then throw an error 问题可能是网址,但我无法找到解决方案..
这是我的代码
NSURL *myUrl = [[NSURL alloc] initWithString:CDNRequest];
moviecontroller = [[MMRMovieViewController alloc] initWithContentURL:myUrl];
[[moviecontroller moviePlayer] setScalingMode:MPMovieScalingModeAspectFit];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(playbackFinished:)
name:MPMoviePlayerPlaybackDidFinishNotification object:[moviecontroller moviePlayer]];
[self moviecontroller];
MMRMovieViewController 是一个视图控制器,它只是扩展了 MPMoviePlayerViewController。 这是playbackFinished方法
- (void)playbackFinished:(NSNotification*)notification {
MPMoviePlayerController *moviePlayer = [notification object];
NSNumber* reason = [[notification userInfo] objectForKey:MPMoviePlayerPlaybackDidFinishReasonUserInfoKey];
switch ([reason intValue]) {
case MPMovieFinishReasonPlaybackEnded:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"playback ended");
break;
case MPMovieFinishReasonPlaybackError:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"playback error");
NSError* error = [[notification userInfo] valueForKey:@"error"];
NSLog(@"error=%@", error);
break;
case MPMovieFinishReasonUserExited:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSLog(@"user exited");
break;
default:
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
break;
}
if (moviePlayer == TRUE) {
[moviePlayer setFullscreen:NO animated:YES];
}
[moviePlayer stop];
[moviePlayer removeFromSuperview];
moviePlayer = nil;
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
}
错误日志显示:“rror = "Error Domain=MediaPlayerErrorDomain Code=-12847 \"不支持此电影格式。\" UserInfo=0x5b60030 {NSLocalizedDescription=不支持此电影格式。}" 但有时它会消失!所以不可能是这个原因!
感谢任何帮助!
谢谢!
【问题讨论】:
-
设置断点/NSLog语句并打印出CDNRequest的值。您用于设置 CDNRequest 变量的任何逻辑都可能每隔一段时间将其设置为错误值。
-
播放视频的格式..!
-
这是 CDNRequest 值的样子:cdnselector.xuniplay.fdnames.com/… NSLog 在视频不播放时也会打印此值。格式应为 m3u8
-
可能和这个链接有关 [How to play movies files without file extension on iOS with MPMoviePlayerController or AVPlayer?] stackoverflow.com/questions/5501670/…
标签: iphone mpmovieplayercontroller