MPMoviePlayer的流媒体视频缓冲区大小

4
有没有一种方法可以检测在使用 MPMoviePlayerController 流式视频时缓冲了多少数据?
我已经检查了 loadState,但那并不能给我足够关于缓冲的信息。
Youtube的应用程序正好有我想要的功能...

1
请参考类似的帖子:http://stackoverflow.com/questions/10346327/mpmovieplayercontroller-when-will-i-know-that-the-downloading-of-the-file-reach - Maulik
1个回答

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


1
谢谢,但我已经找到了更好的解决方案:http://stackoverflow.com/questions/10346327/mpmovieplayercontroller-when-will-i-know-that-the-downloading-of-the-file-reach - Borut Tomazin

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接