使用 soundpool 后无法更改铃声音量(<2.1)

发布于 2024-11-15 21:34:51 字数 1932 浏览 7 评论 0 原文

有一个问题,这个问题经常发生。

我正在使用 soundpool 来播放 soundfx。一个 soundfx“silence.mp3”始终循环播放,因此我可以随时更改音量。如果我更改音量,则会显示“媒体音量”。看来这是应用程序的音量。

离开应用程序(后退或主页按钮)后,我无法更改“铃声音量”。

如果启动活动,声音就会播放

@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "onResume");
    if (StbApp.mSoundPool != null){
        Log.d(TAG, "playSounds");
        Log.d(TAG, "menu: " + StbApp.menu);
        StbApp.mSoundPool.play(
                StbApp.menu, 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                0, 
                0, 
                1
        );
        Log.d(TAG, "menu: " + StbApp.silence);
        StbApp.mSoundPool.play(
                StbApp.silence, 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                0, 
                -1, 
                1
        );
    }

我尝试暂停应用程序中使用的所有声音,以确保由于某种原因没有声音播放。 (即使它是启动器活动)

@Override
protected void onPause() {
    Log.d(TAG, "onPause");
    StbApp.mSoundPool.pause(StbApp.gameover);
    StbApp.mSoundPool.pause(StbApp.execution);
    StbApp.mSoundPool.pause(StbApp.menu);
    StbApp.mSoundPool.pause(StbApp.number);
    StbApp.mSoundPool.pause(StbApp.penalty);
    StbApp.mSoundPool.pause(StbApp.players);
    StbApp.mSoundPool.pause(StbApp.quest);
    StbApp.mSoundPool.pause(StbApp.round);
    StbApp.mSoundPool.pause(StbApp.spinning);
    StbApp.mSoundPool.pause(StbApp.silence);

    super.onPause();
}

我无法使用 autoPause(),因为只有 API 级别 8 及更高版本支持该方法。我尝试在设置中强制停止。但这也行不通。我必须重新启动手机才能更改铃声音量。 (索尼爱立信 X10)

有没有办法在 Android 2.1 中离开应用程序后更改铃声音量?

编辑: 我在更多设备上测试了它。摩托罗拉 FlipOut 和 SE X10 mini 上也出现此问题。它适用于 Galaxy S、HTC Legends、SE X8 和 Galaxy S II。

There is a problem, which occured very often.

I am using soundpool to play soundfx. One soundfx "silence.mp3" plays in a loop all the time, so I can change the volume anytime. If I change the volume "media volume" is displayed. It seems it is the volume for the app.

After I leave the app (back or home button) I can't change the "ringer volume".

The sound will play if start the Activity

@Override
protected void onResume() {
    super.onResume();
    Log.d(TAG, "onResume");
    if (StbApp.mSoundPool != null){
        Log.d(TAG, "playSounds");
        Log.d(TAG, "menu: " + StbApp.menu);
        StbApp.mSoundPool.play(
                StbApp.menu, 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                0, 
                0, 
                1
        );
        Log.d(TAG, "menu: " + StbApp.silence);
        StbApp.mSoundPool.play(
                StbApp.silence, 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                StbApp.mAudioManager.getStreamVolume(AudioManager.STREAM_MUSIC), 
                0, 
                -1, 
                1
        );
    }

I try to pause all sounds I use in the app to make sure there are no sound playing for some reason. (Even though it is the launcher activity)

@Override
protected void onPause() {
    Log.d(TAG, "onPause");
    StbApp.mSoundPool.pause(StbApp.gameover);
    StbApp.mSoundPool.pause(StbApp.execution);
    StbApp.mSoundPool.pause(StbApp.menu);
    StbApp.mSoundPool.pause(StbApp.number);
    StbApp.mSoundPool.pause(StbApp.penalty);
    StbApp.mSoundPool.pause(StbApp.players);
    StbApp.mSoundPool.pause(StbApp.quest);
    StbApp.mSoundPool.pause(StbApp.round);
    StbApp.mSoundPool.pause(StbApp.spinning);
    StbApp.mSoundPool.pause(StbApp.silence);

    super.onPause();
}

I can't use autoPause(), because only API level 8 and higher supports the method. I try force stop in settings. But this won't work either. I have to restart the phone in order to change the ringer volume. (Sony Ericsson X10)

Is there a way to be able to change the ringer volume after leaving the app in Android 2.1?

EDIT:
I tested it on some more devices. The problem occured on Motorola FlipOut and SE X10 mini as well. It works on Galaxy S, HTC Legends, SE X8 and Galaxy S II.

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

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

发布评论

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

评论(2

情栀口红 2024-11-22 21:34:51

尝试将“mSoundPool.pause”放在 onStop() 方法而不是 onPause() 上。

如果不起作用,你可以尝试:

setVolumeControlStream(AudioManager.STREAM_RING);

在onStop()的末尾。

Try to put the "mSoundPool.pause" on the onStop() method instead of onPause().

If it doesn't work, you can try:

setVolumeControlStream(AudioManager.STREAM_RING);

at the end of the onStop().

飘逸的'云 2024-11-22 21:34:51

您不必使用静音 mp3 即可更改音量。您可以将此行放在 oncreate 中。

this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  

信息就是从这里来的。
http://www.stealthcopter.com/blog/2010/02/how-to-tell-android-which-volume-mediaringtone-etc-should-be-control-by-your-app/

You don't have to use a silent mp3 to be able to change the volume. You can put this line in oncreate.

this.setVolumeControlStream(AudioManager.STREAM_MUSIC);  

Information came from here.
http://www.stealthcopter.com/blog/2010/02/how-to-tell-android-which-volume-mediaringtone-etc-should-be-controlled-by-your-app/

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