Android Application Development Tutorial – 17 – Adding Music with MediaPlayer

Facebook –
GitHub –
Google+ –
LinkedIn –
reddit –
Support –
thenewboston –
Twitter –






37 responses to “Android Application Development Tutorial – 17 – Adding Music with MediaPlayer”

  1. Tamim man Avatar

    Peach Grandma hahahaha…..!!

  2. Nishat Sayyed Avatar

    plz tell me which screen recorder do you use???…..and how to zoom in ???i really want to know….how to zoom into a recorded video???plz help someone…

  3. Kartik Sood Avatar

    i am using android studio and after coding this uptill this video .. when i emulate this app . a dialog appears "Register New file type Association" and i have to associate .mp3 withsome given types.with what do i do that

  4. avi D Avatar

    I was able to make my own music player after watching such tutorials.
    check it out guys & give it review if you like it

  5. Kristijan Ujevic Avatar

    I know i'm a few years too late but I just have to write this…

    This tutorial might actually be bad for you in the long run, there are so many wrong explanations about programming concepts up to this point that i just couldn't bare with it anymore.

    For example:
    Keyword "this" is a reference to the current object, NOT the class as it was stated in this particular episode.

    the list goes on

    Basically you have to learn to crawl before you can run. Pick up some general programming tutorials or books, or even better go to a computer science college and come back in a few years once you have mastered programming in general and you will see that this tutorial makes no sense.

    This should be viewed as constructive criticism, you think you're helping people but actually you're making it harder for them in the long run.

    If you're here to learn Android development, look elsewhere.

  6. Mike Napoli Avatar

    great tutorial! helped me accomplish the app I have been working on which uses the media player for beach sounds to fall asleep to. it's called Beach Sound Central, check it out!

  7. Emre Çakır Avatar

    If your mp3 file keeps playing after transited to main screen, just add "mySong=null;" under the release method. It should work fine.

  8. Jason Zimmerman Avatar

    if i had a penny for every time you say for the most part. no just kidding. i realize it has to be hard to explain everything in detail. well FOR THE MOST PART. LOL. LOVE YOUR TUTORIALS

  9. Ibrahima SOW Avatar

    I Reealy can't thank you Bucky for what you have done..
    After following these series, I managed to publish my first music player app, here it is :

  10. Gaurav Chauhan Avatar

    it's not working ,when i right this (MediaPlayer ourSong=MediaPlayer.create(MyClass.this, R.); ) statement it is not giving me the reference of raw folder . i checked the file it doesn't contains any ref. to raw folder.

  11. Armands Avatar

    anybody doing this in android studio?

  12. Solayman Khan Avatar

    Worked Perfectly !! Thanks yaar !!

  13. santanu bhowmick Avatar

    This works. but how can i play music from online sites?  

  14. WSEize Avatar

    Naked grandma tutorial 😀

  15. Tyler5794 Avatar

    If anybody has any issues with the app crashing as soon as it starts, try changing your file extension. Mine was .wma and when I converted it to .mp3 it worked fine.

  16. AbdulRahman Awad Avatar

    I don't have a raw file what to do ?!

  17. Attila László Szél Avatar

    Thank you so much,TheFlamingJez! Your resolve is helpful for me. 🙂

  18. Drake Bell Avatar

    Love you Travis !!!!Your Tutorials are awesome !

  19. Saurabh Gupta Avatar

    splash cannot resolved to a type error 

  20. Javier Calderon Avatar

    ok for people that have no sound going on I found the solution. You need to take the Splash out and just have this instead of Splash.this. Take out Splash and it will work.

    Correct version:
    ourSong = MediaPlayer.create(this, R.raw.tetris_theme);

    Incorrect Version:
    ourSong = MediaPlayer.create(Splash.this, R.raw.tetris_theme);

  21. shruti goyal Avatar

    my app is crashing becoz of ourSong.release(). If i dont give that then it does not crash . I am not understading why it is happening so ????

  22. claudia crespo Avatar

    thank you so so much <3 !

  23. 3RandomFails Avatar

    Thank you man! Awesome videos! And I even ended up making an app of my own 🙂 please check it out

  24. 3RandomFails Avatar

    Thank you man! Awesome videos! And I even ended up making an app of my own 🙂 please check it out

  25. Jack Laurence Garay Avatar

    The grandma jokes becomes faker and not funnier as you repetitively use it. Nevertheless, this series is so far the best series of tutorials for Android Development, keep it up!

  26. Ankit Bhagat Avatar

    Application crashes when I do that. Can someone please help me out?

  27. billyblackburn87 Avatar

    That is actually really fucking cool

  28. Patryk Kotarski Avatar

    Can anybody help me understanding whats wrong with my program? The splash page doesn't even show.

    Here's the code of

    package com.Thenewboston.patryk;

    import android.content.Intent;
    import android.os.Bundle;

    public class Splash extends Activity {

    MediaPlayer ourSong;
    protected void onCreate(Bundle JustRandomVar) {
    // TODO Auto-generated method stub


    ourSong = MediaPlayer.create(Splash.this, R.raw.progr);

    Thread timer = new Thread() {
    public void run() {
    try {
    } catch (InterruptedException e)
    } finally {
    Intent openStartingPoint = new Intent("com.Thenewboston.patryk.MAINACTIVITY");

    protected void onPause() {
    // TODO Auto-generated method stub


    AND HERE IS THE CODE OF AndroidManifest.xml

    <?xml version="1.0" encoding="utf-8"?>
    <manifest xmlns:android=""
        android:versionName="1.0" >

            android:targetSdkVersion="18" />

                    <action android:name="android.intent.action.MAIN" />
                    <category android:name="android.intent.category.LAUNCHER" />
                    <action android:name="com.Thenewboston.patryk.MAINACTIVITY" />
                    <category android:name="android.intent.category.DEFAULT" />


    Thank you all for answering 3:

  29. Alok Pandey Avatar

    working well… "For the most part" … 😛 ..nice tutorials man.. 

  30. BeastInertia Avatar

    crashes when I try to launch the app, It works when I remove everything done in this video though (displays the splash image)

    I've noticed that when I add the mp3 to the raw folder in finder I don't get that music icon Travis is getting in the ProjectExplorer next to the mp3  filename, is the icon meant to change? I feel this may be related to why it crashes. (Also yes I have been cleaning the project after adding music haha) Any advice would be appreciated! i've tried changing it to onDestroy at the bottom but even without the onPause it just doesn't load anything and crashes straight away!

  31. Charlie Guan Avatar

    "Grandma put your clothes on"…. hahahaha!!!

  32. BartMan5impson Avatar

    There is a glitch with the song part! If you rotate the device while the song is playing the song starts playing again and they overlap. So you have two songs playing at the same time. Idk if that made sense..

  33. Farah Nazifa Avatar

    ourSong.release() fails to stop the song after 5secs…" the app stops working" –  pops up…when i OK it, it works normally, any solution to this error message?

  34. Szabolcs Magyari Avatar

    In emulator i hear the song, but in my cellphone dont. Why?

  35. Jon Fuchs Avatar

    Just a small note, if you defined ourSong in the onCreate method, wouldn't the music stop anyway after onCreate is finished because ourSong goes out of scope ?
    I haven't tried it yet so I might be wrong.

Leave a Reply

Your email address will not be published. Required fields are marked *