MPMoviePlayerController只播放第一次,第三次,第五次......依此类推

时间:2012-04-01 22:24:47

标签: iphone mpmovieplayercontroller

大家好,我对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 =不支持此电影格式。}“ 但有时它会发生!所以这不是原因!

感谢任何帮助!

谢谢!

1 个答案:

答案 0 :(得分:0)

这肯定是一个流问题。

选项:

  • 视频格式不兼容 - 你有点排除

  • 视频传送服务器设置有缺陷 - 您应该使用Charles或类似的HTTP代理来分析流量

要排除您自己代码的任何问题,请尝试在移动版Safari浏览器中输入流网址。如果那个无法播放,那么它不是客户端/代码相关的问题。