我无法停止正在运行的播放列表。它会提供本机方法的错误。使用异步类时播放列表已停止。请查看我的fragment
和 PlayMedia课程。
public static int[] playList= {
R.raw.song1, R.raw.song2,
R.raw.song3, R.raw.song4
};
@OnClick(R.id.tablaPlayControl_mImageView)
public void playTablaSounds() {
if (!tablaPlay) {
tablaPlayControl_mImageView.setImageResource(R.drawable.ic_play);
tablaPlay = true;
playAudio = new PlayMedia(getContext(), playList);
playAudio.execute();
} else {
tablaPlayControl_mImageView.setImageResource(R.drawable.stop);
playAudio.onCancelled();
playAudio.execute();
tablaPlay = false;
}
}
Async claas中的方法 PlayMedia.class 停止播放列表
@Override
public void onCancelled() {
super.onCancelled();
Log.e("Log 1", "" + mediaPlayer);
if ( mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.release();
mediaPlayer = null;
}
}
这是我的logcat
崩溃的地方。请检查。
app.android.atabla E/AndroidRuntime: FATAL EXCEPTION: ain
Process: app.android.atabla, PID: 23104 java.lang.IllegalStateException
at android.media.MediaPlayer.isPlaying(Native Method)
at app.android.atabla.CommonUtils.Utils.PlayMedia.onCancelled(PlayMedia.java:91)