I am creating an Android music player based on the tutorial from Android Hive here is the link.
http://www.androidhive.info/2012/03/android-building-audio-player-tutorial/
Which is tutorial for creating an music player like this.
Now I have successfully created my customized music player using this tutorial but their is a problem in that i.e. it doesn't play music in background. So searched for it and found this post
Playing BG Music Across Activities in Android
and I have found that I have to run MediaPlayer class from Android Service
. So I used Android Service , created methods for play and pause and now my background music is running successfully.
Now here is the main problem
How can I update this components from the service which are dependent on MediaPlayer object like seekbar, Timer e.t.c. I am not able to get that.
Because these are dependent on media player object and MediaPlayer object is now in Service.
I am just near to finish my Music app now. I have study this code of the Android Default Music app. which help me a lot.
You can see that here: Platform_pkg_App_for_Music
Best way is to use Custom
BroadcastReceiver
, You can send song name , artist etc details inPutExtra
and insideActivity
you need to createOnReceiver()
and you can get this details usingintent.getStringExtra("message");
Write this in ServiceA.java
Write this in ActivityA.java
Now register
Receiver