ios AudioQueue 流式传输多首歌曲

发布于 2024-11-29 16:25:16 字数 1092 浏览 2 评论 0原文

我正在使用 AudioQueue 从任意源流式传输音频(该类基本上只需要一个为其提供数据包的委托),我创建了一个包含所有功能的类,让我们调用 AudioQueueClass,我正在使用此类来播放许多音频歌曲,在每首歌之间我释放我的类并创建一个新的 AudioQueueClass 实例来播放下一首歌曲,我看到两个问题,我无法找到原因,也许你们中的一些人遇到了这些问题并且可以解决一盏灯

1- 时不时AudioQueue 播放上一首歌曲的几秒钟,然后返回当前歌曲,不知道为什么会发生这种情况,因为我正在为每首歌曲创建一个新队列,并且我相信我正在适当地处理我的队列 - 一些遵循的代码

2-这个更糟糕,有时当我进入第三或第四首歌时,音频队列停止播放...我相信问题是 AudioQueueInputCallback inCallbackProc 停止被调用,我猜这是因为队列停止了播放和处理数据包,但无法找出原因...另一件事需要注意的是,只有当我从外部源流式传输到设备时才会发生这种情况,如果我只是在本地获取文件数据并将其用作数据包,我会在音乐中听到“口吃”但它恢复并播放良好,而在流媒体情况下,声音只是停止(非常奇怪)

这是我用来处理音频队列的代码,不再发布,因为不确定要发布哪些相关部分,请让我知道您是否想查看任何代码并将其发布

    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];
    }
}

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];
    }
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

萌能量女王 2024-12-06 16:25:16

毫不奇怪,错误根本不在音频流媒体中,这是我编写要流式传输的音乐的方式...在我修复它之后,一切正常...

再次感谢

丹尼尔

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文