我正在使用MediaPlayer,当用户通过按下(我想要发生这种情况)离开活动时,它会在后台继续播放,但是当用户返回时,他们无法控制已播放的MediaPlayer,因为第mediaPlayer = new MediaPlayer()
行实例化一个新的。
我也无法让mediaPlayer.create()
工作,因为我使用连接到soundcloud需要
mediaPlayer1.reset();
mediaPlayer1.setDataSource(getResources().getString(R.string.Basic_lesson_1));
mediaPlayer1.prepareAsync();
行。只有当一个新MediaPlayer尚不存在时,如何才能实例化它?
答案 0 :(得分:1)
创建全局静态媒体播放器并始终执行验证,如@Pravin所说 同时创建媒体播放器。
if(mediaPlayer == null){
mediaPlayer = new MediaPlayer()
}
答案 1 :(得分:0)
private static MediaPlayer mediaPlayer1 = null;
//SomeActivity's onCreate()
if(mediaPlayer1 == null)
mediaPlayer1.create(...);
答案 2 :(得分:0)
如何在backKeyPress上唤起方法stop()