Android: I need a button that kills anything played by the MediaPlayer - android

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.

Related

Android MediaPlayer keeping background music playing

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.

How to know when the sound finished playing using soundPool

I am using sound pool to play a short sound files in android, but I want to play the sounds at for example, If I clicked a button to play a sound and clicked the button again, I don't want to play the sound as long as it is already playing . how ?
It looks like you should use a MediaPlayer Class instead of soundpool to accomplish this result, in combination with an OnClickListener.
A simple StackOverflow search returns the following:
MediaPlayer

(Android) How to tell if a sound is playing in soundpool

Is there a way I can tell if a certain sound is playing in SoundPool???
I.E.
if(MySound./*Command Goes Here*/()==true{
//Do stuff
}
I would appreciate if you could point me in the right direction or give me the code. I am not able to find any thing that does this on the docs.
This is not possible using SoundPool.
See Android SoundPool: get notified when end of played for two other ideas:
Use MediaPlayer, which provides an OnCompletionListener, instead of SoundPool
Use MediaPlayer in conjunction with SoundPool. Load the sound in a MediaPlayer beforehand to get the duration and keep track of whether the sound is done playing based its duration when played with SoundPool.

How to find out if a song is playing or not?

I am developing an application.
Related to my application,
I want to know if any audio song is playing or not in the backgroud through any other
music player apps or the default musicplayer come with mobile.
If anyone knows the solution please help me.
You need to use isPlaying() in the MediaPlayer class.
isPlaying() will return false when the default MediaPlayer application is not currently playing, so you must be using some other music application that we are not aware of. You should probably post your code, if that is the case.

Playing music files in Android

I have a list of music files that should be played with my Android application. Actually user selects a list of files to be played for a specified time, and then clicks on 'start button'. Please tell me how I can implement it so that the following requirements are met:
The program should work, even if power button is pressed or the display is turned off.
Music files should be played one by one.
In order that the music continue after your application activities exit, you need to implement the playing itself as a Service (specifically, a started service). For playing the music, take a look at MediaPlayer. There is a discussion of using a MediaPlayer in a Service in the Media Player guide topic.
To play audio files, you can use Android's MediaPlayer class.
MediaPlayer mp = new MediaPlayer();
mp.setDataSource(audioFilePath);
mp.prepare();
mp.start();
This code snippet will load and play a single audio file. Take a look at the documentation for MediaPlayer to figure out how you might be able to leverage it for what you're trying to accomplish specifically.

Categories

Resources