Android: Use running MediaPlayer - android

I' developing an Android app and in this app I've got a Android MediaPlayer and I want to ask, if I can access with this MediaPlayer to a running MediaPlayer, that was started by an other app?
For example I start a song with the Android Music app and the user opens my app. Is there a method to access and control this stream of the Android Music? So I can stop the music with stop() and start it start() and all the other functions?

If you are asking if there's a way to control a Media Player running in some other app from your app, then no. There is no way to do that.
If the other app is a service though, and that service allows control over its media player through intents, then you could control the other media player, but I'd be surprised if you got that lucky.

Related

How to check if external media player is playing in android?

I want to stop my media player if external media player is playing.
I've implemented following code but it is called even when my app media player is playing.
if (audioManager.isMusicActive()) {
return;
}
How to distinguish between in-app media player and external media player?
Any help would be appreciated.
Two or more Android apps can play audio to the same output stream
simultaneously. The system mixes everything together. While this is
technically impressive, it can be very aggravating to a user. To avoid
every music app playing at the same time, Android introduces the idea
of audio focus. Only one app can hold audio focus at a time.
Further,
A well-behaved audio app should manage audio focus according to these
general guidelines:
Call requestAudioFocus() immediately before starting to play and
verify that the call returns AUDIOFOCUS_REQUEST_GRANTED. If you design
your app as we describe in this guide, the call to requestAudioFocus()
should be made in the onPlay() callback of your media session. When
another app gains audio focus, stop or pause playing, or duck the
volume down. When playback stops, abandon audio focus. Audio focus is
handled differently depending on the the version of Android that is
running:
You can check the more detail from developer link.

Voice command for android music player app

I am working on an android music player and I wanna have hand-free voice commands,i.e., don't need to press any button to start recording. the app should keep listening all the time. Is there a way ?
You could use the Houndify SDK for voice recognition. It can be triggered without a button press, and it has music domains for searching and controlling music playback.
http://www.soundhound.com/houndify

How do I allow my app to continue running when it is not in the foreground, or the phone is locked

I'm making a internet radio android application that streams using MediaPlayer. However, I want it to continue streaming music in the background when the phone is locked, or I'm using another application.
I can't find anything online for this and it's very frustrating, does anyone have any solutions or tutorials I can use?
You need to use a service and you can play media player from there, you probably will need your activity later to communicate with your service to get some information from the player ( by binding your activity to the service or using broadcast receiver)

how to detect when Music is played using Native Music Player?

I am making an app in which I've made a Service which plays Music from URLs. The thing is that my music Service is playing music correctly BUT when user plays any song with Native music player then BOTH(Native Player and My Music Service) are playing music simultaneously. I want to stop My Music Service when user started playing music with native player.
Is there any Broadcast Intent which i can register to Detect the
music player is started?
Is it possible to detect Music player Started?
Any Other Solution?
Any suggestions would appreciated.
I'll suggest a different approach, that I believe it's the correct approach.
the issue on your approach is that you're suggesting to check for one specific app. And there're tons of different music players, plus radio players, plus video players, plus games... and all of those should stop your music in case they want to play something.
So how you do it?
It's all explained in the Android Developers website.
You have to register an OnAudioFocusChangeListener, so, whenever a different app request to have the audio focus, your app can stop the music.
Step 1: Detect if the user has opened native music app. For this , you need to know the package name of your native music app.
Then refer to my answer here: Android how to know an app has been started and range apps priority according the starting times
Using that , the list taskinfo will have the list of all running activities, and as explained there, the first element of the list will be the activity in the foreground.
STEP 2: Once you detect native music app being activated using STEP 1 (by polling for it in the background) , then stop your app's service.
NOTE: You should do this in a background (using asynctask) or another service.
NOTE 2: The limitation of this method is that you can't actually stop the music player when the user clicks play in the native music app, since this method will help you detect only if the native music app is opened or not.

Android media player(android.media.MediaPlayer) two music concurrently

Before open my application I played some of the music from default music player. With that background music I opened my application with the mediaplayer (android.media.MediaPlayer) to play the mp3 available in assets.
The default doesn't stop the music and I am getting two music concurrently from the device.
How do I stop or pause music of the default music player whenever my app started playing the music?
I think thats impossible. The default music player is a different app and out of your control. android does not allow controlling other app features from your app.
I had the same problem. I was trying to stop the background music of the default music player (if it is playing) when my VoIP SIP application receives an incoming call. I came up with:
AudioManager am = (AudioManager)getSystemService(Context.AUDIO_SERVICE);
am.setStreamMute(AudioManager.STREAM_MUSIC, true);
This does not stop or pause the music, but it make the music stream silent. Do not forget to unmute it later. This solution works well only if your second sound does not use the same stream.

Categories

Resources