Hey all, here seeking some perspective.
I have an audio player app on macOS built on top of AVPlayer, I want to add the ability to scrub the audio, and hear the audio frames based on the playhead's position whether going forwards or backwards. When going backwards, the audio frame should be played in reverse as well.
The audio tracks live online and are streamed.
I tried playing with AVPlayer.rate, but the time pitch algos built in (.spectral, .varispeed, .timeDomain) all only guarantee up to 32x rate decoding accuracy. So technically, if the user scrubs fast enough, the audio rendered would not necessarily match the playhead's position.
My current solution that works is to cache the raw audio bytes and play the appropriate frame when the user starts scrubbing. I decode the audio data manually using AudioToolbox's AudioFileOpenWithCallbacks into an AVAudioPCMBuffer, then pass it into AVAudioEngine+AVAudioPlayerNode combo.
The problem with that is that means I need to cache this audio data myself (remember this is a stream), and since I don't have access to AVPlayer's own cache I need to also download it myself... which means two downloads for the same track which is less than ideal.
This lead me to take it a step further and hijack AVPlayer's download process by implementing AVAssetResourceLoaderDelegate, that way AVPlayer and my audio scrubbing cache are both fed from the same source.
Now... I feel like I went down a bit of a rabbit hole here. At the end of the day I simply want accurate audio scrubbing in both directions, while keeping in mind I want the audio snippets to play in reverse when the user goes backwards.
Is there really no way to do this that's more "vanilla"? Am I missing something obvious? Genuinely open to any and all suggestions.
Thanks.
0
0
30