MPMoviePlayer正在加载视频,但从未进入readyToPlay状态 [英] MPMoviePlayer loading the video but never enters readyToPlay state

查看:116
本文介绍了MPMoviePlayer正在加载视频,但从未进入readyToPlay状态的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直试图使用MPMoviePlayerController播放视频大约一个星期,但收效甚微!我终于到了加载视频的阶段(或者至少我认为它可以告诉我视频时长).

I have been trying to get a video to play using MPMoviePlayerController for about a week with very little success! I have finally got it to the stage where it loads the video (or at least I presume it does as it can tell me the video duration).

但是,我的视频永远无法播放,因此我只看到一个黑色方块.

However, my video never becomes playable therefore I am just presented with a black square.

我的代码如下:

  - (void)loadMovieWithURL:(NSURL *)movieURL
{
    NSLog( @"Video URL = '%@'", [movieURL path]);
    NSData *data = [NSData dataWithContentsOfURL:movieURL];
    [[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMoviePlayerPlaybackStateDidChangeNotification  object:nil];

    MPMoviePlayerController *mp = [[MPMoviePlayerController alloc] init];
    self.moviePlayer = mp;
    [self.moviePlayer.view setFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height)];
    [self addSubview:self.moviePlayer.view];
    [self.moviePlayer setContentURL:movieURL];
    self.moviePlayer.movieSourceType = MPMovieSourceTypeFile;

    [self.moviePlayer setFullscreen:NO];
    [self.moviePlayer setScalingMode:MPMovieScalingModeFill];
    [self.moviePlayer setControlStyle:MPMovieControlStyleNone];

    //[self.moviePlayer setShouldAutoplay:YES];

    [self.moviePlayer prepareToPlay];
    [self.moviePlayer play];

}

我正在打印大量的值到NSLog只是为了检查它们,所以我想我也应该在下面提供它们,以便更好地了解我所看到的内容:

I am printing out a lot of the values to NSLog just to check them, so thought I should provide them below too just to give a better idea of what I'm seeing:

2013-01-07 15:33:39.858 WildMap_iOS[9887:16703] Video URL = '/Users/elliott/Library/Application Support/iPhone Simulator/6.0/Applications/A233395A-3E8F-4E35-BF42-09D9B743EA33/test.3gp'
    2013-01-07 15:33:40.100 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Disabling autoplay for pause
    2013-01-07 15:33:40.101 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Disabling autoplay
    2013-01-07 15:33:40.176 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Enabling autoplay
    2013-01-07 15:33:40.179 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2013-01-07 15:33:40.180 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2013-01-07 15:33:40.181 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
    2013-01-07 15:33:40.182 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
    2013-01-07 15:33:40.259 WildMap_iOS[9887:16703] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
    2013-01-07 15:33:40.401 WildMap_iOS[9887:16703] [MPAVController] Autoplay: Enabling autoplay
    2013-01-07 15:33:41.344 WildMap_iOS[9887:16703] Is ready to display 0
    2013-01-07 15:33:41.344 WildMap_iOS[9887:16703] Duration: 45.267000

我确实设置了一个通知来检查MPMoviePlayerLoadStateDidChangeNotification,但它从未更改.有没有人遇到过类似的问题,或者知道我的代码可能出什么问题了?如果您需要更多信息,请随时询问.

I did setup a notification to check for MPMoviePlayerLoadStateDidChangeNotification but it never changes. Has anyone had a similar issue, or know what could be wrong with my code? If you need anymore information feel free to ask.

编辑1(测试danh的代码)

EDIT 1 (Testing danh's code)

使用以下内容时:

    NSLog( @"Video URL = '%@'", [movieURL path]);
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.view.frame = self.bounds;
[self addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];

//NSData *data = [NSData dataWithContentsOfURL:movieURL];
[[NSNotificationCenter defaultCenter] addObserver:self  selector:@selector(moviePlayerPlaybackStateDidChange:)  name:MPMoviePlayerPlaybackStateDidChangeNotification  object:nil];

[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerLoadStateChanged:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

我的日志是:

2013-01-08 12:08:16.105 WildMap_iOS[705:16703] [MPAVController] Autoplay: Disabling autoplay for pause
2013-01-08 12:08:16.105 WildMap_iOS[705:16703] [MPAVController] Autoplay: Disabling autoplay
2013-01-08 12:08:16.138 WildMap_iOS[705:16703] [MPAVController] Autoplay: Skipping autoplay, disabled (for current item: 1, on player: 0)
2013-01-08 12:08:16.144 WildMap_iOS[705:16703] [MPAVController] Autoplay: Enabling autoplay
2013-01-08 12:08:16.153 WildMap_iOS[705:16703] [MPAVController] Autoplay: Likely to keep up or full buffer: 0
2013-01-08 12:08:16.153 WildMap_iOS[705:16703] [MPAVController] Autoplay: Skipping autoplay, not enough buffered to keep up.
2013-01-08 12:08:16.157 WildMap_iOS[705:16703] [MPCloudAssetDownloadController] Prioritization requested for media item ID: 0
2013-01-08 12:08:16.177 WildMap_iOS[705:16703] [MPAVController] Autoplay: Enabling autoplay
2013-01-08 12:08:17.244 WildMap_iOS[705:16703] Is ready to display 0
2013-01-08 12:08:17.244 WildMap_iOS[705:16703] Duration: 45.267000

因此,这似乎与从未调用moviePlayerLoadStateChanged的原始代码相同.但是,对于MPMoviePlayerController无法加载视频的持续时间,我还是感到困惑.这可能是编解码器问题吗?下载后是否可以检查视频是否全部正常播放?

So it seems to be the same as the original code where moviePlayerLoadStateChanged is never called. However, I'm still confused as to how the MPMoviePlayerController can pick up the duration of the video if it is unable to load it? Could this be a codec issue? Is there any way to check whether or not the video will work at all after downloaded?

好的,这看起来像是可能的编解码器问题.我现在尝试使用2个类似的URL进行尝试,即1 mov/1 3gp,而mov 1可以播放声音,但没有视频,而3gp会在视频屏幕上短暂显示正在加载",但消失时永远不会更改为已加载状态.谁能建议一种使之正常工作的方法,或者是其他支持更多类型的电影播放器​​?

Okay this looks like a possible codec issue. I have now tried it with 2 similar URLs, 1 mov / 1 3gp, and the mov one will play with sound but no video whilst the 3gp briefly shows "loading" on the video screen but never changes to the loaded state when this disappears. Can anyone suggest a way of getting this working, or another movie player with more types supported?

推荐答案

尝试将所有设置代码替换为:

Try replacing all of your setup code with this:

// get the url as moveURL
self.moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:movieURL];
self.moviePlayer.view.frame = self.view.bounds;
[self.view addSubview:self.moviePlayer.view];
[self.moviePlayer prepareToPlay];

// notice what notification we subscribe to...
[[NSNotificationCenter defaultCenter] addObserver:self
                                         selector:@selector(moviePlayerLoadStateChanged:)
                                             name:MPMoviePlayerLoadStateDidChangeNotification object:nil];

moviePlayerLoadStateChanged:中的日志状态更改.如果这不起作用,则可能是问题所在的网址.

Log state changes in moviePlayerLoadStateChanged:. If that doesn't work, it's probably the url that's the problem.

这篇关于MPMoviePlayer正在加载视频,但从未进入readyToPlay状态的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆