Mp3没有在Android中播放

时间:2011-11-09 20:15:39

标签: android media-player

我创建了一个简单的启动画面,它有一个声音(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();
        }



}

我试过android MediaPlayer not playing mp3 file 但也没有用。我也咨询了Android文档。但似乎没有任何工作。

1 个答案:

答案 0 :(得分:1)

player.prepare();放在player.start();

之前

看看是否有效