Java (Android Studio) Tutorial – The Simple Music Player –




In this video, I’ll share how to develop a simple music player with Android Studio.

You’ll learn:
– Media Player class
– Seekbar
– Thread
– Handler

Hope you enjoy 🙂



Android Studio 2.2.3
Emulator: Genymotion(Nexus4)



Java ( Android Studio ) Tutorial – Music Player –





Working as a freelance programmer in Japan. I try to make coding as simple as possible. Hope you enjoy coding 🙂
  • Brindha D

    Excellent Programming Skills You have Keep it up>>>

    • Sara

      Hi Brindha, thanks for your comment 🙂

  • Purple Pie Technologies

    Hey , Awesome Tutorial Ever Noticed. Crystal Clear Explanation without voice. All the best. keep up the good work.

    • Sara

      Hi Purple Pie Technologies, thank you for your comment! I’m so glad you found my video 🙂

  • Ade Eko Saputra

    hey sara, if my music file have 1 hour long, how to make timelabel for elapsedtime and remainingtime?

    • Sara

      Hi Ade Eko Saputra, thanks for watching 🙂
      Here’s an example of over one-hour long music file.

      public String createTimeLabel(int time) {
       String timeLabel = “”;

       int hour = time / 1000 / 60 / 60;
       int min = time / 1000 / 60;
       int sec = time / 1000 % 60;

       timeLabel += hour + “:”;
       if (min >= 60) {
        timeLabel += min % 60 + “:”;
       } else {
        timeLabel += min + “:”;
       if (sec < 10) timeLabel += "0";
       timeLabel += sec;

       return timeLabel;

      Since the "time" variable is milliseconds, convert milliseconds to hours, minutes, and seconds.
      1 second = 1000 milliseconds.
      1 minute = 1000 * 60 milliseconds.
      1 hour = 1000 * 60 * 60 milliseconds.

      Then, create "timeLabel" to display elapsed time and remaining time.
      % gives you a remainder. For example, when "min" is 78, min % 60 is 18.
      Hope this helps.

  • Mari Emma

    hey, are you know because the “elapsedTimeLabel” and “remainingTimeLabel” have error and in the time is in seconds (sorry I’m no speak English).

  • Yunus YÜRÜK

    likewise, internet URL please

  • Rodolfo

    How can I resolve this error?

    Caused by: java.lang.NullPointerException: Attempt to invoke virtual method ‘void’ on a null object reference at

    Button playBtn;
    SeekBar positionBar;
    SeekBar volumeBar;
    TextView elapsedTimeLabel;
    TextView remainingTimeLabel;
    MediaPlayer mp;
    int totalTime;

  • Rares

    If I want to make an app with more than 1 song?

    • Rishabh Tyagi

      Th app in the link below use to fetch the songs from external memory, thus you can play any song which is present in your mobile.
      This link will direct you to the source code

  • Rishabh Tyagi

    For the source code of a basic music player

  • Rares

    If I start the song and then I exit the app and reenter the song is still playing, but the activity has been reset.