I have an app with a playlist and a media player UI.
The issue I am having is when I am playing music, and I re-enter the activity (using a menu), it restarts the media file (because it is calling the onCreate method from the top).
I need to implement the mediaplayer as a servive instead but I have no idea on how to do this! Everywhere I look online is just non-relevant and super confusing articles/code.
Can anyone assist with helpful tutorials or articles related to this?
My code can be found here: https://github.com/becausewesley/MusicalStructureApp
THANKS IN ADVANCE!!
This article Creating Media player service shows step by step on how you can implement a service to create a Mediaplayer application to run in the background. Hope this helps!
Related
I have an application which uses exoplayer to play videos.
When the user is on player page and presses the power button to close the screen I want the audio to keep playing in the background and notification should be visible to user with controls of play, pause , video metadata etc similar to what we have for every music playing app.
I can keep the audio of video playing from exoplayer using setPlayWhenReady(true).
But I am stuck in for notification. Should I be using MediaBrowserServiceCompat or I will have to create custom notification to handle it?
I think what you should do is to create ForegroundService and create notification as you mentioned to have the ForegroundService working. I think this post might help you:
https://androidwave.com/foreground-service-android-example/
Use a foreground service to implement something like this.This can help you
I'am currently working a mobile application for radio streaming. The problem is when I exit the application the audio stops playing. any idea about this? I really need a help. thank you
You can use service to do that.
Follow the link
Just play the song using foreground service showing music player notification in the notification panel.
You have to create a Service and run it on the foreground. Here is the link to a comprehensive implementation.
I am working on live radio app.
I parse list of channels and show in list view , My problem is when i click on particular channel first time than it plays that channel according to assign link. but when you go out of application and come back and again you click on same channel (Which is playing currently ) it restart the media-player and start playing it again.
so to solve this problem i used manifest "singleTask" to solve this problem.But now when i try to click another link ( other than currently playing) than it wont play the current selected channel from Listview item and its assign link..
So can anybody please tell me How can i have code for activity and service to solve this problem , I am student so i don't have much experience.
Also I am checking for internet if you are connected to internet than it parse the json otherwise it will show message but it only check once when you start your application So how can i check net connection background?
Thank you
You need to set up a Service to play music in background.
There is a sample project called RandomMusicPlayer embedded with the SDK which could help you a lot to achieve it. (In Eclipse: New Project > Android > Android Sample Project)
Move your player to the Service, bind it in activity a send commands from your activity, there is plenty tutorials for this.
Similar question
Service activity communication
Service media player
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.
I want to detect events like "Video is playing" "Video has been paused" "Video Play has stopped".
I do not want to write my own player. I just need to log the events of the default video player that has been called. Is there any broadcast event that I can register to for the default player in android?
It is not possible unless you have a custom rom.
I'm not sure exactly what you need, but the answer is "maybe".
Specifically:
It is possible to detect if an activity was paused? (thread problem)
Q: It is possible to detect if an activity was paused?
A: Yes see here. Just override the onPause in your activity
It might be as simple as that.
Alternatively, look at the Media Player state diagram and available methods here:
http://developer.android.com/reference/android/media/MediaPlayer.html
There is a possibility to bnd to Android's music player service. It is described here. You can obtain the current track and stuff, but I'm not sure whether you can register to events. Let us know if you find out more.