I want to write an application that monitors a music player. In my app I want to start a service, that listens to some media player (best case: any media player; worst case: a specific media player), to get the 10 most listened audio tracks' titles and authors. Is this possible? I searched the web for hours, but I found nothing relevant.
Thanks in advance.
Is this possible?
Not really. There might be some music players that broadcast this information that you could track, but I do not know of any, and that'd be a privacy issue if they did.
Related
On the newest FireTV OS for the Fire Stick Lite 2020 I noticed that when we play a third party app like Spotify for example music keeps playing when we press the home button. This is normal behavior, however when I launch my app I request the audio focus using the AudioManager and OnAudioFocusChangeListener (because I'm also playing music and don't want it to be noisy) so the 3rd party music stops playing. However, when I press play on the FireTV to control my media(Using ExoPlayer) it pauses my app, takes me back to the Spotify app and I lose focus of my own application.
Youtube and Twitch handle this well, so I was wondering if there is anything I am missing or any documentation I should refer to.
Any help is appreciated.
Found the answer. Seems like I wasn't Media Session... According to
https://developer.android.com/guide/topics/media-apps/working-with-a-media-session
We would need to use Media Session to tell the System that there is a media session happening in your app and each time you tell the system that your player is active or playing then your application would have priority over the media controllers on the remote and no other application can access it unless you state that your media session is no longer active.
This helped too! https://developer.android.com/codelabs/supporting-mediasession
Hope this helps anyone else!
I basically have an audio application that will be playing some music. I want to be able to pause/stop/mute the music when there is an interrupt.
These interrupts include: GPS directions, Phone Call, GPS, etc. (if there are more audio interupts, please let me know)
I already implemented the phone call interrupt, stops the music when phone call received and plays after phone call ends.
How would I do the other interrupts?
EDIT:
I noticed that Android's Play Music application does this. But I am unable to find the source code of that, not sure if that would be helpful.
Make sure you correctly ask for and release Audio Focus as described here:
http://developer.android.com/training/managing-audio/audio-focus.html
With multiple apps potentially playing audio it's important to think about how they should interact. To avoid every music app playing at the same time, Android uses audio focus to moderate audio playback—only apps that hold the audio focus should play audio.
Basically this allows the framework to handle interrupts properly as you cannot specifically code for every situation.
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.
I am just messing around with an app that streams audio and I wanted to give it a feature similar to Pandora/Google Music/etc where if you press home or lock the screen the audio continues to play in the background.
How exactly can I accomplish this? Is it through a broadcast receiver or a service? If I knew more closely what I was looking for Google would be more helpful.
Thanks!
It's a service. Anytime you want to do something that takes a lot of time like playing music, downloading a lot of data from a server, etc. it should be a service. The basic technique is to always have the service play the music and then have your activity connect to it to show the status and update the tracks, etc.
I have created an application that read messages with voice. I would like to pause any running media player when a message arrives in order to make the voice more clear. Is there any intent that could achieve this aim? I have noticed that google navigator, for example, is able to pause media player (and other music app like pandora).
Thanks in advance
Tobia Loschiavo
This is not an intent, but have you tried AudioManager and requestAudioFocus?
Sadly its only from API 8