1
我正在開發Android 2.2應用程序。MediaPlayer在onPause和onResume後無法工作
我有以下活動:
public class StartActivity extends Activity {
private MediaPlayer mp;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.startpage);
}
@Override
protected void onResume() {
super.onResume();
ImageView ship = (ImageView)findViewById(R.id.greekShip);
ship.startAnimation(AnimationUtils.loadAnimation(this, R.anim.translate_right));
if (mp == null) {
mp = MediaPlayer.create(getApplicationContext(), R.raw.oceanwave);
}
else {
if (mp.isPlaying())
mp.stop();
mp.reset();
try {
mp.prepare();
} catch (IllegalStateException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
mp.start();
}
@Override
protected void onPause() {
super.onPause();
if (mp != null) {
if (mp.isPlaying())
mp.stop();
}
}
}
如果我按我的電話home鍵,聲音將停止。但是,如果我重新啓動應用程序,mediaplayer啓動,但我什麼也聽不到。
你知道問題在哪裏嗎?
一個新的你的意思是釋放的媒體播放器中不是在的onPause調用OnStop方法? – Leebeedev 2015-10-22 10:22:51