Android MediaPlayer已暂停,音量按钮无法控制多媒体 [英] Android MediaPlayer is paused, volume buttons do not control multimedia
问题描述
我使用在Internet上找到的示例代码播放了示例音乐(.mp3).代码类似于
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();
此行为与我测试过的其他音乐播放器不同.暂停音乐后,三星内置的Music,VLC和其他程序仍显示多媒体音量.
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:似乎其他播放器都可以通过按音量按钮来控制多媒体音量,无论当前播放状态如何,甚至都还没有开始播放.我该怎么办?
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?
推荐答案
我遇到了同样的问题,我通过将以下代码放入onCreate()函数中来解决了这个问题.
I had the same problem and I solved it by putting the following code in my onCreate() function.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
这篇关于Android MediaPlayer已暂停,音量按钮无法控制多媒体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!