1

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

 }
RawMean
  • 8,374
  • 6
  • 55
  • 82

1 Answers1

0

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.

GnarlyDog
  • 1,247
  • 1
  • 17
  • 24
  • Thanks Chris. Even with the test url above I get playableDuration values that are always zero. Can you confirm that with the above code (and your url) on iOS5, you get non-zero values for playableDuration? – RawMean May 05 '12 at 23:44
  • I copy/pasted your code directly into the view controller of a new Xcode 4.3.2 single view project replacing the existing viewDidLoad with yours. I then included the MediaPlayer framework. I also had to add an MPMoviePlaybackController streamPlayer ivar into the interface. The playableDuration property returned zeros just like you are reporting. I then changed the url to the one I included above and was able to get the playableDuration. I just did the exact same procedure right now (only takes a second) with the same result. I tested using the iPad 5.1 simulator. – GnarlyDog May 06 '12 at 07:24