控制音量键调整的声音类型

andoid 声音分成了好几类,最常用到的就是 通话声音  多媒体声音(音乐)

 

就目前的经历,如果activity时用MediaPlayer类播放着音乐的话,音量键默认调整的声音类型的 多媒体。否则默认控制的是 通话声音。

 

若activity 未播放音乐也要改变的是  多媒体 声音的话,则可在onCreate里执行如下函数即可。

setVolumeControlStream(AudioManager.STREAM_MUSIC);

---------------------- 更详细的见 SDK ---------------------------------

public final void setVolumeControlStream(int streamType)

Since:

Suggests an audio stream whose volume should be changed by the hardware volume controls.

The suggested audio stream will be tied to the window of this Activity. If the Activity is switched, the stream set here is no longer the suggested stream. The client does not need to save and restore the old suggested stream value in onPause and onResume.

Parameters
streamType The type of the audio stream whose volume should be changed by the hardware volume controls. It is not guaranteed that the hardware volume controls will always change this stream's volume (for example, if a call is in progress, its stream's volume may be changed instead). To reset back to the default, use .

你可能感兴趣的:(Stream,音乐,audio)