使用 soundpool 后无法更改铃声音量(<2.1)
有一个问题,这个问题经常发生。
我正在使用 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。
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
尝试将“mSoundPool.pause”放在 onStop() 方法而不是 onPause() 上。
如果不起作用,你可以尝试:
在onStop()的末尾。
Try to put the "mSoundPool.pause" on the onStop() method instead of onPause().
If it doesn't work, you can try:
at the end of the onStop().
您不必使用静音 mp3 即可更改音量。您可以将此行放在 oncreate 中。
信息就是从这里来的。
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.
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/