AudioStreamer 未显示正确的播放时间

发布于 2024-12-12 17:07:33 字数 134 浏览 0 评论 0原文

我有一个 ios 应用程序,它通过流式传输并使用 mattgallagher AudioStreamer 库来播放音乐,它不显示真实的播放时间,并且永远不会在 0 秒时停止播放...

有谁知道为什么会发生这种情况?

多谢!

i've one ios application that plays music by streaming and using the mattgallagher AudioStreamer library it doesn't show the real playtime and never stop play at 0 secs...

Does anyone know why this happens??

Thanks a lot!

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

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

发布评论

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

评论(2

守护在此方 2024-12-19 17:07:33

我经历过类似的事情。查看AudioStreamer.m 中的progress 方法

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0) && ![self isFinishing])
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING)
            {
                return lastProgress;
            }
    ...
        }
    }

    return lastProgress;
}

现在,进度显示不正确的原因在于两个if 语句。当您的 AudioStreamer 即将完成时(可能是在加载所有数据时),它的 isFinishing 变为 true,这使其返回进度的缓存值。此外,流媒体状态变为 AS_STOPPING,这使得第二个 if 语句返回 lastProgress。您真正想要的是更新进度,直到流媒体停止。

我对代码的以下修改做到了这一点,并且看起来工作正常。然而,鉴于 AudioStreamer 的总体质量以及它是由 Matt Gallagher 开发的事实,这些 if 语句可能是有原因的。到目前为止,我修改后的代码没有遇到任何崩溃或类似情况,但您应该在您的应用程序中对其进行彻底测试。请注意,一旦流媒体完成,我就不再查询进度。如果你这样做,测试它是否有效:)

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0))
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING && state != AS_STOPPING)
            {
                return lastProgress;
            }
    ...
        }
    }

    return lastProgress;
}

I experienced something similar. Have a look at the progress method in AudioStreamer.m

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0) && ![self isFinishing])
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING)
            {
                return lastProgress;
            }
    ...
        }
    }

    return lastProgress;
}

Now, the reason for the progress not being displayed correctly lies within the two if-statements. When your AudioStreamer is nearly finished (probably when all data is loaded), it's isFinishing becomes true, which makes it return the cached value for progress. Also, the streamer state becomes AS_STOPPING, which makes the second if-statement return the lastProgress. What you really want is to update the progress right until the streamer stops.

My following modification to the code does this and it seems to work fine. HOWEVER, given the general quality of the AudioStreamer and the fact that it's developed by Matt Gallagher, those if statements might be as they are for a reason. So far, I did not experience any crashes or alike with my modified code but you should thoroughly test it in your app. Note, that, once the streamer is done, I don't query the progress anymore. If you do, test if it works :)

- (double)progress
{
    @synchronized(self)
    {
        if (sampleRate > 0))
        {
            if (state != AS_PLAYING && state != AS_PAUSED && state != AS_BUFFERING && state != AS_STOPPING)
            {
                return lastProgress;
            }
    ...
        }
    }

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