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?
相关问题
- CALayer - backgroundColor flipped?
- Core Data lightweight migration crashes after App
- back button text does not change
- iOS (objective-c) compression_decode_buffer() retu
- how to find the index position of the ARRAY Where
相关文章
- 现在使用swift开发ios应用好还是swift?
- TCC __TCCAccessRequest_block_invoke
- xcode 4 garbage collection removed?
- Unable to process app at this time due to a genera
- How can I add media attachments to my push notific
- didBeginContact:(SKPhysicsContact *)contact not in
- Custom Marker performance iOS, crash with result “
- Why is my library not able to expand on the CocoaP
AVAssetReader
is amazingly slow when seeking. If you try to recreate anAVAssetReader
to seek while the user is dragging a slider, your app will bring iOS to its knees.Instead, you should use an
AVAssetReader
for fast forward only access to video frames, and then also use anAVPlayerItem
andAVPlayerItemVideoOutput
when the user wants to seek with a slider.It would be nice if Apple combined
AVAssetReader
andAVPlayerItem
/AVPlayerItemVideoOutput
into a new class that was performant and was able to seek quickly.Be aware that
AVPlayerItemVideoOutput
will not give back pixel buffers unless there is anAVPlayer
attached to theAVPlayerItem
. This is obviously a strange implementation detail, but it is what it is.If you are using
AVPlayer
andAVPlayerLayer
, then you can simply use the seek methods onAVPlayer
itself. The above details are only important if you are doing custom rendering with the pixel buffers and/or need to send the pixel buffers to anAVAssetWriter
.AVAssetReader has a property, timeRange, which determines the time range of the asset from which media data will be read.
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.