While using MPMoviePlayerController
is there any way to find how much Percentage of data finished while buffering the video?
My aim is to show the progress bar that showing how much percentage is loaded and show its numeric count of percentage.
Thanks in advance.
Have you checked out the Apple documentation for the MPMoviePlayerController
?
http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html
Here you can find two properties that might help you. duration
and playableDuration
, it's not an exact fit, but pretty close. One thing you will need to implement yourself is a way to intelligently query these properties, for example maybe you might want to use an NSTimer
and fetch the info from your MPMovePlayerController
instance every 0.5 seconds.
For example assume you have a property called myPlayer
of type MPMoviePlayerController
, you will initiate it in your init method of the view controller etc...
Then followed by this:
self.checkStatusTimer = [NSTimer timerWithTimeInterval:0.5
target:self
selector:@selector(updateProgressUI)
userInfo:nil
repeats:YES];
And a method like this to update the UI:
- (void)updateProgressUI{
if(self.myPlayer.duration == self.myPlayer.playableDuration){
// all done
[self.checkStatusTimer invalidate];
}
int percentage = roundf( (myPlayer.playableDuration / myPlayer.duration)*100 );
self.progressLabel.text = [NSString stringWithFormat:@"%d%%", percentage];
}
Note the double percentage sign in our -stringWithFormat
, this is another format specifier to resolve to a %
sign. For more on Format specifiers see here.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With