MPMoviePlayer流式视频缓冲区大小

时间:2012-12-28 07:21:44

标签: iphone ios streaming buffer mpmovieplayer

有没有办法检测在MPMoviePlayerController中流式传输视频时缓冲了多少数据?

我已经检查了loadState,但这并没有给我足够的缓冲信息。

Youtube的应用程序正是我想要的......

1 个答案:

答案 0 :(得分:7)

您可以尝试在播放视频时获取电影访问日志。

- (void)calculateBufferSize
{
    NSArray *events = self.moviePlayerController.accessLog.events;
    int count = events.count;
    for (int i = 0; i < count; i++)
    {
        MPMovieAccessLogEvent *currentEvent = [events objectAtIndex:i];
        int64_t byte = currentEvent.numberOfBytesTransferred;
        int64_t bytes = currentEvent.numberOfBytesTransferred >> 10;

        NSLog(@"byte = %f M bytes = %lld", (float)byte / (1024 * 1024), bytes);
    }
}

然后你可以通过诸如

来调用上面的内容
[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(calculateBufferSize) userInfo:nil repeats:YES];

之后

[self.moviePlayerController play];

https://developer.apple.com/library/ios/#DOCUMENTATION/MediaPlayer/Reference/MPMovieAccessLog_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40010561