简体   繁体   中英

iOS: Fast forward audio when using AudioQueue

I'm messing around with audio playback using AudioQueue. Does anyone know how you can control the rate of playback so that you can fast forward and fast rewind with audio coming out? AVPlayer has a "rate" property, however I need to be using AudioQueue.

I haven't found anything similar in the Multimedia Programming Guide or in Audio Queue Services Programming Guide. It looks like Mac OS X supports kAudioQueueParam_PlayRate as mentioned by Rocky but that doesn't work on iOS

kAudioQueueParam_PlayRate works on iOS from version 7 onwards. It must be enabled specifically before playback starts in order for it to work:

        var enabled : UInt32 = 1;
        AudioQueueSetProperty(queue!, kAudioQueueProperty_EnableTimePitch, &enabled, 4);
        var algorithm = kAudioQueueTimePitchAlgorithm_Spectral;
        AudioQueueSetProperty(queue!, kAudioQueueProperty_TimePitchAlgorithm, &algorithm, 4);

then you can vary rate and pitch as required:

            AudioQueueSetParameter(q, kAudioQueueParam_PlayRate, Float32(rate));
            AudioQueueSetParameter(q, kAudioQueueParam_Pitch, Float32(pitch));

(sorry for Swift answer on a question tagged objective-c, but that's what I have to use as an example...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM