我用Splash Music做了一個應用程序。但是,每當我進入應用程序的偏好時,音樂會自動停止,然後永遠不會播放,直到我重新啓動應用程序。當我打開一個活動時,情況也是如此,該活動表明手機處於「正常」模式還是處於「靜音」模式。背景音樂自動停止
這種奇怪行爲的原因是什麼? 這裏是飛濺的音樂代碼,我檢查是否播放音樂或不..
公共類閃屏擴展活動{
MediaPlayer mp; @Override protected void onCreate(Bundle savedInstanceState) { // TODO Auto-generated method stub super.onCreate(savedInstanceState); setContentView(R.layout.splashscreen); mp= MediaPlayer.create(SplashScreen.this, R.raw.got); SharedPreferences pref= PreferenceManager.getDefaultSharedPreferences(getBaseContext()); ; if(pref.getBoolean("music", true)) { mp.start(); } if(pref.getBoolean("loop", true)) { mp.setLooping(true); } Thread timer= new Thread() { public void run() { try { sleep(5000); Class ourclass = Class.forName("com.umer.practice2.Menu"); Intent myintent= new Intent(SplashScreen.this,ourclass); startActivity(myintent); } catch(Exception e) { e.printStackTrace(); } } }; timer.start(); } @Override protected void onPause() { // TODO Auto-generated method stub super.onPause(); finish(); }
}
感謝
如果你顯示你的代碼會更好。有很多方法來實現你的功能 – user1049280