Alert icon
We're changing our privacy policy. This stuff matters.  Learn more  Dismiss

Android Tutorial & Lessons 9: Adding sound with MediaPlayer

Loading...

Sign in or sign up now!
Alert icon
Upgrade to the latest Flash Player for improved playback performance. Upgrade now or more info.
39,490
Loading...
Alert icon
Sign in or sign up now!
Alert icon

Uploaded by on Jan 26, 2011

Android Tutorial & Lessons 9: Adding sound with MediaPlayer:

Here is the link for learning more about android Activity: http://developer.android.com/reference/android/app/Activity.html

Whats up CornFanz, thanks for watching my videos, I would love it if you subscribe and give me some feedback.


In this lesson you will:
-Add some sound to our Splash Screen in our myMain class
-Learn about the start, pause, & release methods from the MediaPlayer class
-Get a better understanding of why we added the onDestroy, onResume, & onPause methods.
-Understand the differences between setting up a local variable & a variable that can be use by the whole class

Next we will be learning about the how to use the buttons to actually do something, YAY!


This video is the 9th in a web series that I am creating to help you learn Android programming so you can create apps and eventually how to learn to write games for android phones. I want to explain things in a way that everyone can understand, even if you have no experience with Java, XML, C, OpenGL, or as a matter of fact, any other programming language.




If you do have a lot of experience with programming, these first videos will be really slow for you, but my goal is to get everyone sprinting, but for now we have learn to crawl.

follow me on twitter: @cornboyz

  • likes, 5 dislikes

Link to this comment:

Share to:

Uploader Comments (CornboyzAndroid)

  • i still cant get the splash jpeg to show up, but the sound works great, whats up with that? the splash.xml shows the jpeg just fine in graphical mode....

  • @billybong78 do you have your thread method as "start" or as "run" cause it needs to be, whateverYouCalledYourThread.st­art()

    hope that helps

  • hey, I had a 20 second sound to play on the startup, but it didn't play through, in other words the sound seemed to "destroy" itself when it switched to myMenu?? Can you tell me why it did this. I have everything setup the same as you but I had the timer set to 20000 for the 20 sec sound, I then changed it to 1000 to see if the sound would play through to the myMenu, but it would stop playing

  • @MrStewdaddy hey man, I kind of forgot how we set this up, But I believe we destroyed the mediaplayer sound within the onPause method, or one of those methods. So the reason the music stops is that we called the method whateverYouNameYourSound.relea­se(); which will kill the sound. Hope that makes sense?!?!

  • your virtual device is running so fast... how can i make it work fast ?

  • @MuhammadRaza2009 you can start the emulator by going to the window tab>android sdk and avd manager>then click on the emulator you want and press start. then you can programming while it is loading up, and once it is loaded, when you run your application it will start pretty quickly. So basically don't close the emulator, so you won't have to wait for it to load every time you want to test your application.

Video Responses

see all

All Comments (82)

Sign In or Sign Up now to post a comment!
  • i tried it but it couldnt direct from the splash activity to the "main.xml"....

    meaning after the splash activity, an error "the application ___ has stopped unexpectedly. Please try again."... how do you fix it??

  • is it same if i put the "mpSplash.start();" on while loop? and then stop(); it when activity start();

  • hahaha i like your way to teach us..

    "hi man, can i listen that?"

    it is so simple to understand, nice approach dude..

  • Hey can anyone advice me. i manage to have all the coding right. but when i launch it on the emulator, eclipse say source not found and on the emulator screen was black. what happened?

  • hey dude, one quick question. I've followed everything up until the end of this video and it's all running smoothly except the code we left off with after this video gives me a forceclose. The logo>audio>mymain all starts up followed by a forceclose. any ideas? thanks bro. very informative videos by the way and considering I knew jack about this before today, your videos are helping amazingly.

  • hey man, how to play sound when Menu items are pressed?

    What I want to do is after playing the sound when menu list items are pressed, each list items of Menu will open respective activity.

  • so I did everything you did, when you tested the sound before you did the pause, destroy, or resume. Your sound worked, but when I do mine (5 seconds like yours) however it never played. I also tried a 3 minute song with the 5 seconds but I don't hear anything. did my sounds on the emulator get muted? if so, how can i fix that. I got the ringer volume on full so how come my sounds aren't even playing?

  • damn your funny haha! makes java so much funnier. cant imagin my self joking with a mic :O

  • what if i specify launcher for mymenu instead of splash in mainfest.xml is it going to launch mymenu instead of splash need to work on it... health tip alcohol kills

  • i have a question we do have two activities here say splash activity and my menu activity in form of two .java files why is that only splash activity is called first we didnt specified any main method asking copailer to start executing instructions from a point is that mainfest.xmal launcher action does it launching splash activity first. need clarification here travis

Loading...

Alert icon
0 / 00Unsaved Playlist Return to active list
    1. Your queue is empty. Add videos to your queue using this button:
      or sign in to load a different list.
    Loading...Loading...Saving...
    • Clear all videos from this list
    • Learn more