Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MPMoviePlayerController % of data bufferd

Tags:

iphone

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.

like image 767
Subin Kurian Avatar asked Aug 03 '12 13:08

Subin Kurian


1 Answers

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.

like image 96
Daniel Avatar answered Nov 15 '22 06:11

Daniel