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

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 .
发布了142 篇原创文章 · 获赞 44 · 访问量 225万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览