MPMoviePlayerController 获取视频缓冲大小

操作系统:ios5.1

最近在完成一个流媒体相关的任务,需要在线播放视频,还要获取视频缓冲的大小,以便计算视频加载的速度。

我选择了MPMoviePlayerViewController在线播放视频,实现上其实很简单。

关于视频缓冲的大小的获取,代码如下:

    NSArray *events = playerViewController.moviePlayer.accessLog.events;
    int count = events.count;
    for (int i = 0; i < count; i++)
    {
        MPMovieAccessLogEvent *currentEvent = [events objectAtIndex:i];
        double byts = currentEvent.indicatedBitrate;
        int64_t byte = currentEvent.numberOfBytesTransferred;
        int64_t bytes = currentEvent.numberOfBytesTransferred >> 10;
        NSMutableString *strBytes = [[NSMutableString alloc] initWithCapacity:100];
        [strBytes appendFormat:@"totalSize = %d byte", bytes];
        if (bytes > 1024)
        {
            bytes = bytes >> 10;
            [bytesS setString:@""];
            [bytesS appendFormat:@"total = %d M", bytes];
        }
        NSLog(@"byte = %f M bytes = %lld", (float)byte / (1024 * 1024), bytes);
    }

在播放代码[player play];之后,New一个timer执行上面的代码。

[NSTimer scheduledTimerWithTimeInterval:0.5 target:self selector:@selector(moviePlay) userInfo:nil repeats:YES];

你可能感兴趣的:(MPMoviePlayerController 获取视频缓冲大小)