Search code examples
androidandroid-emulatorandroid-mediaplayerandroid-audiomanagerandroid-notification-bar

Audio player in Android


I designed an app which plays 12 different audio files based on the item selected in the list view from server. When the audio is playing and I hit home button in the emulator I can see the notification in notification bar but when I click it the audio player is restarting but the previous audio is still playing.

I need the audio player to show me the present state of the audio player when the notification icon is clicked.


Solution

  • When your activity is brought to the foreground you can override using the onResume.

    I'm assuming your using a ProgressBar to display progress. So you can set the progress bar to the current position by using the getCurrentPosition method of media player. (do this in onResume)

    That should set it to proper position. Then restart any CountDown or operation to update ProgressBar and it should work