Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android MediaPlayer is paused, volume buttons do not control multimedia

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?

like image 836
Damn Vegetables Avatar asked Dec 06 '25 12:12

Damn Vegetables


1 Answers

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

setVolumeControlStream(AudioManager.STREAM_MUSIC);
like image 66
inga Avatar answered Dec 08 '25 22:12

inga



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!