views:

166

answers:

2

Hi there

I have followed the steps to create my media player object but I cant understand why it is not playing the music track. I used the following code:

mp = new MediaPlayer();
    mp.create(this, R.raw.testmed); 
    mp.setVolume(100, 100);


    mp.start();

but no sound is playing through the emulator, and furthermore when i check the method mp.isPlaying() it returns false. What have I missed?!

Many thanks

A: 

Try out this tutorial - http://www.androidcompetencycenter.com/2009/02/android-audio-support/

sbidwai
Here is another sample: http://github.com/commonsguy/cw-advandroid/tree/master/Media/Audio/
CommonsWare
I keep getting the message "start called in state 1" in red on my Log, and still no sound.
Greenhouse Gases
can you let me know what Android version you working with? Tutorial I mentioned is a bit old, will update it with new version things
sbidwai
+1  A: 

You have to call all methods necessary to actually start the player. Take a look at Android Media Player state diagram

I think you need to prepare the player before starting. When the player is prepared, it can be started. This is done through a onPreparedListener:

mp = new MediaPlayer();
mp.create(this, R.raw.testmed);
mp.setVolume(100, 100);
mp.setOnPreparedListener(this);
mp.prepare();

Then you will need to define this and it should work:

public void onPrepared(MediaPlayer player) {
   mp.start();
}
slhck