如何在iOS中使用AVPlayer实现4.0的播放速度?

时间:2015-06-10 01:52:33

标签: ios objective-c avplayer

player.rate = 4.0对我不起作用。

使用AVPlayer获得4.0的速度是一种好方法,还是有更好的方法?

1 个答案:

答案 0 :(得分:2)

使用[AVComposition scaleTimeRange:toDuration:]生成快动作AVAsset

float rate = 4.0;
AVAsset *asset = [AVAsset assetWithURL:someURL];
AVMutableComposition *composition = [AVMutableComposition composition];
NSError *error = nil;
[composition insertTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
                     ofAsset:asset
                      atTime:kCMTimeZero error:&error];
[composition scaleTimeRange:CMTimeRangeMake(kCMTimeZero, asset.duration)
                 toDuration:CMTimeMultiplyByFloat64(asset.duration, 1 / rate)];
AVPlayerItem *playerItem = [AVPlayerItem playerItemWithAsset:composition];
AVPlayer *player = [AVPlayer playerWithPlayerItem:playerItem];