Android MediaPlayer is paused, volume buttons do not control multimedia

一笑奈何 提交于 2021-02-19 03:35:12

问题


I played a sample music (.mp3) using a sample code I found on the Internet. The code is something like

MediaPlayer mp = new ...
mp.setDataSource(...
mp.setAudioStreamType(...
mp.prepare();
mp.start();

The problem is that when the music is paused, the volume buttons do not control multimedia volume but notification volume.

mp.pause();

This behaviour is different from other music players I have tested. Samsung's built-in Music, VLC, and other programs still showed multimedia volume when the music has been paused.

How can I make multimedia volume appear when music is paused?

PS: It seems other players make pressing volume buttons control multimedia volume, no matter what the current playing status is, even playing has not been started at all. How can I do this?


回答1:


I had the same problem and I solved it by putting the following code in my onCreate() function.

setVolumeControlStream(AudioManager.STREAM_MUSIC);


来源:https://stackoverflow.com/questions/28570040/android-mediaplayer-is-paused-volume-buttons-do-not-control-multimedia

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!