I want to add background music to my app - android

I want the user to get the music file from his collection and play it on background of the app. I don't know how to get the path of the music file to use it in my app

Use services to play back ground music in your app
Check out here

Related

How to restart automatically a song of a different app from my app?

I played a song from another music player, and I have my own app that plays an audio, for now I can pause the song once my app plays the audio with requestAudioFocus(), so I would like to get back the previous song to play it again when my audio finish, is there a way to do it? I think it is like when you are listening music and you received a call, the music stops, and when the call ends you can listen the music again.
Let me show you what I did so far.
First I played my favorite song on a music player(a different app)
enter image description here
Second I made my own app to play and audio file when the button is clicked
enter image description here
and I use this code to stop my favorite music from my app
enter image description here
so then my favorite music is paused
enter image description here
Finally What I want to get is my favorite song being autmatically played again.
I got the answer, so first notice u can't influence on other apps as Vlad said, I tested on two different apps, Google Play Music, and the default Radio, I was very happy to see the expected results.

Unable to play media player in Background

I have Implemented A media player But the Problem is that when i press back button .music stop.but it runs when the app is in background.
Proper approach is to implement media-player inside service. That way music playback will persist when users uses other applications or gets outside of your app.
Remember to call startForeground() with ongoing notification.

Switch between two activities and keep music playing

Here is what I want to achieve in my app: I have 3 menus in the startup page: PLAY , INSTRUCTIONS , HIGH SCORE.
I have theme music playing in the background with the help of MediaPlayer object. I just want that the theme music should be playing for the PLAY and INSTRUCTIONS menu, uninterrupted, i.e, if the activity changes from MAIN MENU to INSTRUCTIONS and vice-versa , the music should be playing uninterrupted. But the music should stop as soon as the PLAY activity is started. I don't know the best way to do it, but all I can think of is sending the MediaPlayer object that started the theme music to PLAY's oncreate and stop it there. is there any way to do this?
You want to use a Service to play the music (and to do so off of the main thread). Here are relevant pages on
Services
Media playback

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-how to get background music of other app

First,I'm trying to do a music plug-in.
Then,the app need acquire state of other app's background music (playing or pause/stop).
1.If other app's background music is play ,then my plug-in not do anything.
2.If the background music is pause/stop,then my plug-in will have some operation.
I have seached a lot about the android music.but I have find the way to get current state of music play.I can only get isActive.but this method whether on play or pause ,the return value are same:true.that make me craze for one week.
then i try otherway but in the upper layer the player are control by mediaplay,which i can get the class object from.
So could anyone tell me is there a way that can tell the music play state? thanks for your any help.

Categories

Resources