playableDuration returns 0 in iOS5

隐身守侯 提交于 2019-12-11 08:40:37

问题


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.

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];

 }

回答1:


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

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

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

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...

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.



来源:https://stackoverflow.com/questions/7763200/playableduration-returns-0-in-ios5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!