MPMoviePlayerController% data buffer

When using MPMoviePlayerController there a way to find out how many percent of data ended up with video buffering?

My goal is to show a progress bar showing how many percent is loaded and show its numerical percentage.

Thanks in advance.

+8
iphone
source share
1 answer

Have you checked the Apple documentation for MPMoviePlayerController ?

http://developer.apple.com/library/ios/#documentation/mediaplayer/reference/MPMoviePlayerController_Class/Reference/Reference.html

Here you can find two properties that can help you. duration and playableDuration , this is not an exact match, but pretty close. One thing that you need to implement yourself is a way to query these properties intelligently, for example, you might want to use NSTimer and get information from your MPMovePlayerController instance every 0.5 seconds.

For example, suppose you have a property called myPlayer type MPMoviePlayerController , you start it in your view controller's init method, etc ...

Then follows the following:

 self.checkStatusTimer = [NSTimer timerWithTimeInterval:0.5 target:self selector:@selector(updateProgressUI) userInfo:nil repeats:YES]; 

And such a method to update the interface:

 - (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 percent sign in our -stringWithFormat , this is another format specifier to allow the % sign. For more information on format specifiers, see here .

+6
source share

All Articles