Isuru
Isuru

Reputation: 3958

Mp3 not playing in Android

I create a simple splash screen which has a sound(mp3)

    package in.isuru.Hello;

    import android.app.Activity;
    import android.content.Intent;
    import android.media.MediaPlayer;
    import android.os.Bundle;

    public class Splash extends Activity {


        MediaPlayer player;

        @Override
        protected void onCreate(Bundle savedInstanceState) {
            // TODO Auto-generated method stub
            super.onCreate(savedInstanceState);
            //splash is a xml layout
            setContentView(R.layout.splash);
            //haha is a mp3 file.
            player = MediaPlayer.create(Splash.this, R.raw.haha);
            player.start();
                //Timer to pause 5 seconds before go to next intent
            Thread timer = new Thread(){
                public void run(){
                    try{
                        //player starts playing mp3 file
                        sleep(5000);
                    }catch(InterruptedException e){
                        e.printStackTrace();
                    }finally{
                        Intent openStartingPoint = new Intent("in.isuru.HELLO");
                        startActivity(openStartingPoint);
                    }
                }
            };
            timer.start();
        }

        @Override
        protected void onPause() {
            // TODO Auto-generated method stub
            super.onPause();
            player.release();
            finish();
        }



}

I tried android MediaPlayer not playing mp3 file too but it didn't work. I consulted Android Documentation too. but nothing seems to work either.

Upvotes: 1

Views: 921

Answers (1)

DJ Burb
DJ Burb

Reputation: 2392

put player.prepare(); before player.start();

See if that works

Upvotes: 1

Related Questions