How to seek within an audio track using avassetreader?

前端 未结 2 1629
面向向阳花
面向向阳花 2020-12-16 06:58

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 hal

2条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-16 07:41

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

    @property(nonatomic) CMTimeRange timeRange
    

    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.

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

    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.

提交回复
热议问题