[Tutorial] [How to] Manually create Android Media Player controls

I have moved this post to new website. Visit here.


, , , , , , , ,

  1. #1 by savan on September 23, 2011 - 12:37 pm

    hey can you send me this whole code with all file…
    i got error when i am combining all files….
    **Email Removed**

  2. #3 by savan on September 23, 2011 - 12:54 pm

    hey, when i am presing music tab then i got force close error….

    • #4 by Sapan Diwakar on September 23, 2011 - 1:46 pm

      Can you try to debug it using eclipse and see where is the error? I am guessing the you have some problem with initialization of the music player.

  3. #5 by savan on September 23, 2011 - 12:57 pm

    i want to play song from my sd card….

    • #6 by Sapan Diwakar on September 23, 2011 - 1:48 pm

      If you are trying to play a song available locally on the SD card, then try using

       mediaPlayer.setDataSource(getApplicationContext(), myUri);

      to set the Data Source.

  4. #7 by Andrew chang on October 7, 2011 - 8:25 am

    hi. your code is good. thank you. but, i got force close error. threr is mMediaPlayer.prepareAsync() in initMediaPlayer(). how to fix it?

    • #8 by Sapan Diwakar on October 8, 2011 - 5:18 am


      Could you post the complete stack trace?

  5. #9 by ebtihal on November 25, 2011 - 7:23 am

    Hi ,
    thank you so much .
    I really get interested .

    I have quistion
    how can I play video from raw folder ??

    thank you so much

    • #10 by Sapan Diwakar on December 3, 2011 - 7:51 pm


      I haven’t tried playing videos with Android but I guess it can be done using VideoView.

  6. #11 by Chris Powell on December 8, 2011 - 10:42 pm

    Hi There, i’ve pretty much duplicated your code from the source you provided in the downloadable files.

    Currently I’m having trouble getting anything to play, Eclipse isn’t reporting any kind of error anyway, i’ve matched up the Android Manifest and String.xml file.

    What happens is the program loads fine, etc, I click the play button and nothing happens, it just turns into a pause button them almost immediately turns back into a play button, i changed the url to my file on the internet, which definitely works: http://k002.kiwi6.com/hotlink/08bd3jix81/01_gimme_some_lovin.mp3

    I’m at a bit of a loss really, any ideas?

  7. #12 by westsidewill on April 3, 2012 - 2:09 am

    Great writeup! I was having issues with implementing song titles and understanding the state diagram of the mediaplayer. I still have to stare at the state diagram really hard to understand what is going on, but this example definitely gave me a good base to work from.

    Thanks so much!

  1. All About Mail

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s