简体   繁体   中英

ios AudioQueue streaming multiple songs

I am using AudioQueue to stream audio from an arbitrary source (the class basically just needs a delegate that provides it with packets), I've made a class that wraps all the functionality lets call is AudioQueueClass, I am using this class to play many songs, in between each song I release my class and create a new AudioQueueClass instance to play the next song, I am seeing two problems which I haven't been able to find the cause maybe some of you have run into these issues and can shed a light on it

1- Every now and the AudioQueue plays a few seconds of a previous song and then comes back to the current song, not sure why this could be happening as I am creating a new queue for each song, and I believe I am disposing of my queues appropriately --some code to follow

2- This one is even worse, sometimes when I'm into the 3rd or 4th song the audio queue stops playing... I believe the problem is that AudioQueueInputCallback inCallbackProc stops being called, which I guess is because the queue stopped playing and processing packets, but cannot find out why...Another thing to note is that this only happens when I stream to the device from an outside source, if I merely get the file data locally and use that as packets I hear a "stutter" in the music but it recovers and plays fine, whereas in the streaming case the sound just stops (pretty weird)

Here is the code I am using to dispose of the audio queue, not posting any more because not sure what relevant parts to post, please let me know if you want to see any of the code and ill post it

    AudioQueueFlush(audioQueue);
AudioQueueStop(audioQueue, true);
if (audioFileStream)
{
    err = AudioFileStreamClose(audioFileStream);
    audioFileStream = nil;
    if (err)
    {
        [self failWithErrorCode:AS_FILE_STREAM_CLOSE_FAILED];
    }
}

//
// Dispose of the Audio Queue
//
if (audioQueue)
{
    err = AudioQueueDispose(audioQueue, true);
    audioQueue = nil;
    if (err)
    {
        [self failWithErrorCode:AS_AUDIO_QUEUE_DISPOSE_FAILED];
    }
}

Turns out not surprisingly the error was not in the Audio streamer at all, it was the way i was writing the music to be streamed...after i fixed it everything worked out alright...

Thanks Again

Daniel

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