如何使用avassetreader在音轨中进行搜索? [英] How to seek within an audio track using avassetreader?

查看:86
本文介绍了如何使用avassetreader在音轨中进行搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我熟悉如何使用AVAssetReader从ipod库中流式传输音频数据,但是我对如何在音轨中进行搜索一无所知.例如从中点开始播放,等等.从头开始,然后依次获取连续的样本很容易,但是肯定有一种可以随机访问的方法吗?

I'm familiar with how to stream audio data from the ipod library using AVAssetReader, but I'm at a loss as to how to seek within the track. e.g. start playback at the halfway point, etc. Starting from the beginning and then sequentially getting successive samples is easy, but surely there must be a way to have random access?

推荐答案

AVAssetReader具有timeRange属性,该属性确定将从中读取媒体数据的资产的时间范围.

AVAssetReader has a property, timeRange, which determines the time range of the asset from which media data will be read.

@property(nonatomic) CMTimeRange timeRange

此属性的值与CMTimeRangeMake(kCMTimeZero,asset.duration)的交集确定从中读取媒体数据的资产的时间范围.

The intersection of the value of this property and CMTimeRangeMake(kCMTimeZero, asset.duration) determines the time range of the asset from which media data will be read.

默认值为CMTimeRangeMake(kCMTimeZero,kCMTimePositiveInfinity).开始读取后,您无法更改此属性的值.

The default value is CMTimeRangeMake(kCMTimeZero, kCMTimePositiveInfinity). You cannot change the value of this property after reading has started.

因此,如果您想在音轨的中间位置,则需要创建一个从asset.duration/2到asset.duration的CMTimeRange,并将其设置为AVAssetReader上的timeRange.

So, if you want to seek to the middle the track, you'd create a CMTimeRange from asset.duration/2 to asset.duration, and set that as the timeRange on the AVAssetReader.

这篇关于如何使用avassetreader在音轨中进行搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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