美好的一天,我一直在为我的 android 程序做一些编码,我尝试在这里用这段代码播放音乐 android 最低版本是 2.2,最高版本是 4.2.2 也使用 eclipse 来做到这一点,设备模拟器是 nexus one
这在全球
MediaPlayer Sound;
这是在 setContentView 下
Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
Sound.start();
这是整个代码
import android.app.Activity;
import android.content.Intent;
import android.media.MediaPlayer;
import android.os.Bundle;
public class Splash extends Activity {
MediaPlayer Sound;
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.splash);
Sound = MediaPlayer.create(Splash.this, R.raw.kalimba);
Sound.start();
Thread timer = new Thread(){
public void run(){
try{
sleep(5000);
} catch(InterruptedException e){
e.printStackTrace();
}finally{
Intent openStartingPoints = new Intent("com.mysampleapp.simplybel.MainActivity");
startActivity(openStartingPoints);
}//this is the end for the finally
}//this is the end for the run
};//this is the end for the thread timer
timer.start();
}//this is the end for the oncreate
@Override
protected void onPause() {
// TODO Auto-generated method stub
super.onPause();
Sound.release();
finish();
}
}
有人可以帮我做这个吗?