如何在iOS中使用AVPlayer实现4.0的播放速度? [英] How to achieve a playback rate of 4.0 with AVPlayer in iOS?

查看:104
本文介绍了如何在iOS中使用AVPlayer实现4.0的播放速度?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

这是一个很好的方法吗?使用 AVPlayer 获得4.0的比率,还是有更好的方法?

Is it a good way to achieve rate of 4.0 with AVPlayer, or there is a better approach?

推荐答案

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

这篇关于如何在iOS中使用AVPlayer实现4.0的播放速度?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆