媒体播放器搜索器

发布于 2024-12-07 06:10:42 字数 315 浏览 1 评论 0原文

我认为有人会找到一个简单的解决方案,但我还没有找到直接的方法。我想构建一个搜索栏,用于通过 MediaPlayer 播放音频。我无法在 MediaPlayer 对象中找到类似 onSeekChanged 侦听器的内容,因此我构建了一个 AsyncTask,它仅通过 while(playing) 循环不断刷新并更新持续时间和栏。然而,这似乎不是最好的方法,因为这个 while 循环导致应用程序运行非常缓慢(音频不会滞后,但暂停等按钮会延迟)。所以我想知道构建高效导引头的最佳实施方式是什么。这不是一个困难的问题,因为很多应用程序都使用它,我只是想知道执行此操作的正确方法应该是什么。谢谢!

I would assume that someone would have found an easy solution to this but I haven't found a straight-forward method. I want to build a seeker bar for playing back audio through the MediaPlayer. I haven't been able to find something like an onSeekChanged listener in the MediaPlayer object so I've built an AsyncTask that just keeps refreshing through a while(playing) loop and updates the duration and bar. This doesn't seem to be the best way, however, since this while loop causes the app to run very slowly (the audio doesn't lag, but buttons like pause are delayed). So I want to know what the best implementation is for building a seeker that is efficient. This isn't a difficult question since so many apps use it, I just want to know what the proper way of doing this should be. Thanks!

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

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

发布评论

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

评论(1

摘星┃星的人 2024-12-14 06:10:42

首先,您需要在周期中至少放置 1 毫秒的睡眠时间:

Thread.sleep(1);

其次,您可以计算下一次重新检查所需的时间:

Thread.sleep(1000 - currentPos % 1000);

该算法用于标准 MediaController 中。

First of all you need put sleep at least 1 millisecond in your cycle whit:

Thread.sleep(1);

Second you can calculate needed time for next recheck:

Thread.sleep(1000 - currentPos % 1000);

This algorithm is used in standard MediaController.

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