views:

85

answers:

2

I have written a Music player app and it works great but when a flip action happens or when I return the the player view I have to stop the player and restart it at the postion that it was at when the action happened. That all works but it means a breif stop and start.

How can I run the media player in a different thread and still update my seekbar?

Thanks

+1  A: 

Try running the media player within a foreground service. It's a little bit of work, but it's how it should be done anyways.

The service will handle running everything in a background thread and can be set up to post updates to your UI through messages or callbacks.

In addition, a Foreground service does not need to be tied to an activity, so it can continue to run even if you leave your player screen. The service must provide an Ongoing notification to the user that will probably display the current song, artist, click to pause, etc.

CodeFusionMobile
A: 

Hi CodeFusionMobile, i have created two activities,say A and B. The activity A lists the songs, when we click on any song the activity B will be called and creates mediaplayer object in one thread. The mediaplayer thread sends its status to its main thread(i.e.,activity B) and then main thread updates some seek bar. When we are in activity B if we click back we will come to activity A but media player never stops its current running song, this is also fine, but if we press any another song in activty A one more media player thread will be created and then this song will also start playing instead of stopping the previous running song.My question is how can we stop already running media player thread???

Venu Gopal