【发布时间】:2011-02-22 20:12:46
【问题描述】:
我正在开发一个 Android 2.2 应用程序。
我有以下活动:
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();
}
}
}
如果我按下手机上的主页按钮,声音就会停止。但是如果我重新启动应用程序,媒体播放器会启动,但我什么也听不见。
你知道问题出在哪里吗?
【问题讨论】:
标签: android android-activity media-player android-2.2-froyo