开发者

How to make the volume rocker affect a stream not currently playing?

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 th开发者_开发百科e 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.)


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

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜