如何使音量摇杆影响当前未播放的流?

发布于 2024-11-02 09:13:19 字数 265 浏览 9 评论 0原文

我正在使用 SoundPool 通过 Android 应用程序中的媒体流 (STREAM_MUSIC) 播放音效。它工作得很好,只是当使用音量摇杆改变音量时,大多数时候它改变的是铃声音量,而不是媒体音量。问题似乎是声音效果只是间歇性地播放。如果我在播放音效时碰巧按下音量键,媒体音量实际上会改变,但大多数时候应用程序是安静的。这使得用户几乎不可能控制应用程序的音量。

如何解决这个问题,以便在我的应用程序处于焦点状态时音量摇杆始终改变媒体音量? (我想我可以在后台连续播放无声曲目,但这真的很难看。)

I am using SoundPool to play sound effects through the media stream (STREAM_MUSIC) in my Android app. It works well except that when using the volume rocker to change the volume, most of the time it changes the ringtone volume, not the media volume. The problem seems to be that the sound effects are only played intermittently. If I happen to press the volume rocker while a sound effect is being played, the media volume does in fact change, but most of the time the app is silent. This makes it almost impossible for the user to control the volume of the app.

How can this be solved so that the volume rocker always changes the media volume while my app is in focus? (I guess I could play a silent track continously in the background but that would be really ugly.)

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

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

发布评论

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

评论(1

黑色毁心梦 2024-11-09 09:13:19

您必须在 Activity 中像这样设置音量控制。可能在 onCreate 方法中。

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  

更多音量控制选项 此处

You'll have to set the volume control like this in your Activity .. probably in the onCreate method.

    this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  

More volume control options here

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