player.rate = 4.0
对我不起作用。
用
AVPlayer
达到4.0的速率是好方法吗,还是有更好的方法?
使用
[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];
Apple已在 iOS 16 和 macOS 13 中修复了此问题。