playableDuration在iOS5中返回0 [英] playableDuration returns 0 in iOS5

查看:136
本文介绍了playableDuration在iOS5中返回0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还有其他人注意到MPMoviePlayerController类的playableDuration属性在iOS 5中始终返回0.这在以前的iOS版本中可以正常工作.我用它来设置进度条的值.

Has anyone else noticed that playableDuration property of MPMoviePlayerController class always returns 0 in iOS 5. This used to work fine in previous versions of iOS. I use it to set the value of a progress bar.

这是一段代码,过去可以在4.x SDK下正常工作(即,playableDuration属性在缓冲流时返回正确的非零值),但是在SDK 5.x下,它始终返回零./p>

Here is piece of code that used to work under 4.x SDK just fine (i.e., the playableDuration attribute returned the correct non-zero value while buffering the stream), but under SDK 5.x it always returns zero.

- (void) updateMeter {
NSLog(@"playableDuration = %f", streamPlayer.playableDuration);
}

- (void)viewDidLoad
{

[super viewDidLoad];
streamPlayer = [[MPMoviePlayerController alloc] 
initWithContentURL:[NSURL    URLWithString:@"http://99.198.118.250:8158/"]];    

NSTimer *updateBarTimer = [NSTimer scheduledTimerWithTimeInterval:0.5 
                          target:self selector:@selector(updateMeter)    
                          userInfo:nil repeats:YES];

streamPlayer.controlStyle = MPMovieControlStyleEmbedded;
[streamPlayer play];

 }

推荐答案

使用准确的代码,但将URL替换为:

Use your exact code but replace the url with: http://devimages.apple.com/iphone/samples/bipbop/gear1/prog_index.m3u8

对我来说,除非我将播放器指向分段的.m3u8文件,否则您的代码将失败.

For me your code failed unless I pointed the player to a segmented .m3u8 file.

我在计算机上本地对.mp4电影和.mp3音频文件进行了一些测试,并且都工作得很好.

I did some tests with a .mp4 movie and an .mp3 audio file locally on my computer and both worked fine as well.

我在这里进行推测,但是我相信在流媒体播放时,MPMoviePlayerController是否正在使用.m3u8文件来动态推断播放器项目数据?无论如何,这是我的猜测.奇怪的是,如果是这种情况,为什么它对您的网址完全无效?这导致我下一个评论...

I'm speculating here but I believe it's probable that while streaming media, the MPMoviePlayerController is using the .m3u8 file to deduce player item data on the fly? That's my guess anyway. What's curious is that if this is the case, why does it work at all for your url? Which leads me to my next comment...

使用AVFoundation而不是MediaPlayer框架可能会获得更好的结果.我也在自己的工作中也改用了它.它不是预先打包"的,而是提供了更多的控制.

You would probably have better results using AVFoundation rather than the MediaPlayer framework. I switched to it in my own work as well. It's less "prepackaged" but simply provides much more control.

这篇关于playableDuration在iOS5中返回0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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