如何在iOS中使用AVPlayer达到4.0的播放速率?

问题描述 投票:0回答:2

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

AVPlayer
达到4.0的速率是好方法吗,还是有更好的方法?

ios objective-c avplayer
2个回答
7
投票

使用

[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];

0
投票

Apple已在 iOS 16 和 macOS 13 中修复了此问题。

© www.soinside.com 2019 - 2024. All rights reserved.