使用MPMoviePlayerController
时有没有办法找到缓冲视频时完成的数据百分比?
我的目标是显示进度条,显示加载了多少百分比并显示其百分比的数字计数。
提前致谢。
Have you checked out the Apple documentation for the MPMoviePlayerController
?
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.