I use a MediaPlayer and when the MediaPlayer starts it currently stops all background music the phone is playing (ie: Spotify) and I was wondering how to have the spotify music continue playing after the MediaPlayer audio is complete
You cannot do anything on your side. This behaviour is implemented by "Spotify" devs. Although normally, sounds should not be stopped, but decreaced in volume, it is called audio ducking.
Also it is recommended to implement requesting audio focus and decide play or not to play your audio depending on the status of the audio focus.
Related
I m using Exo Media Player 2.5.0 to stream audio from a remote source . i want to pause the audio when other apps play Audio/Video .
As ADM said, the only way to know if another app is going to play audio is by listening to audio focus changes (after requesting audio focus for your own app first, of course).
Aside from that, you're, unfortunately, at the mercy of the other app also playing nicely and it requesting audio focus when it wants to play.
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?
I had the same problem and I solved it by putting the following code in my onCreate() function.
setVolumeControlStream(AudioManager.STREAM_MUSIC);
I have an app that plays video files with no audio. I'm using the mediaplayer function. I want to have the videos play, but not output anything to audio, as there is no audio tracks. However, Android ducks all other audio output (music, for example) when my app is running. Is there a way to use mediaplayer and completely remove my app from audio streams?
I've reviewed Google's Managing Audio Focus article, and I can't devise a way to do so. I just want to use mediaplayer for the video, and completely forget about audio.
Is there a different function I have to call in mediaPlayer.setAudioStreamType?
you can mute all the audio streams using the below code snippet
AudioManager am = (AudioManager)NextVideoPlayer.this.getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
I want my app to play music while it is running, but I don't want the music to overlap with the music currently being played from a different application (android music app or other external music app such as pandora, grooveshark or winamp).
My question is: is there a way to make sure that nothing else is playing right now regardless of the source?
Thanks!
As of android 2.2 you can use AudioManager.requestAudioFocus(), other audio players should listen for this focus change request and can stop/pause/lower volume of their audio according to what type of audio your focus requests. However not all audio playing apps have bothered to implement this yet.
To be nice you should also listen for audio focus change requests from other apps and pause your apps audio accordingly.
On earlier versions of android calling mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); will usually stop any other music from playing
I have an app that plays several different audio files on a loop, via several different buttons. I want to program a single button that will stop the MediaPlayer, regardless of what audio file is currently being played. Any help with this would be greatly appreciated.
Call stop() on your MediaPlayer object to stop the playback of whatever the MediaPlayer is playing.