我创建了一个简单的启动画面,它有一个声音(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文档。但似乎没有任何工作。
答案 0 :(得分:1)
将player.prepare();
放在player.start();
看看是否有效