【问题标题】:MPMoviePlayerController only play the first time, the third time, the fifth... and so onMPMoviePlayerController 只播放第一次,第三次,第五次……以此类推
【发布时间】: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


【解决方案1】:

这肯定是流问题。

选项:

  • 视频格式不兼容 -- 你可以排除这种情况

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

要排除您自己的代码的任何问题,请尝试在移动 Safari 浏览器中输入流 URL。如果该播放失败,则不是客户端/代码相关问题。

【讨论】:

    猜你喜欢
    • 2011-01-03
    • 2012-10-25
    • 2016-08-15
    • 1970-01-01
    • 1970-01-01
    • 2021-06-18
    • 1970-01-01
    • 2017-07-03
    • 2016-06-12
    相关资源
    最近更新 更多