开发者

Can't change ringer volume after using soundpool (<2.1)

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 o开发者_Go百科r 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.


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().


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/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜