有一种播放启动画面时播放音乐的方法吗? 这是我的启动画面代码:
// Splash screen timer
private static int SPLASH_TIME_OUT= 2000;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
// This method will be executed once the timer is over
// Start main activity
Intent i = new Intent(SplashScreen.this, MyActivity.class);
startActivity(i);
// close activity
finish();
}
}, SPLASH_TIME_OUT);
}
我在res / raw中创建了原始文件夹并输入了我的歌曲,如何在运行启动画面时播放它?
答案 0 :(得分:0)
MediaPlayer mPlayer = MediaPlayer.create(xxx.this, R.raw.xxx);
答案 1 :(得分:0)
只需你可以使用,
myMediaPlayer = MediaPlayer.create(this, R.raw.loveme);
if (myMediaPlayer != null) {
myMediaPlayer.start();
} else {
myMediaPlayer.reset();
try {
myMediaPlayer.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
myMediaPlayer.start();
}
}