我想在Lollipop之前的设备上运行此代码,但由于MediasetNextMediaPlayer()
我已经在21+ API上测试了代码并按需要运行。
有3个媒体播放器OnCompletionListener
public void playall(final View view) {
x = 0;
i = 0;
j = 0;
i = i + Sound_id;
int en_sound = getResources().getIdentifier("e" + i, "raw", getPackageName());
mpe = MediaPlayer.create(list_activity.this, en_sound);
mpe.start();
mpe.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
int ar_sound = getResources().getIdentifier("a" + i, "raw", getPackageName());
mpa = MediaPlayer.create(list_activity.this, ar_sound);
mpa.start();
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) {
mpa.setNextMediaPlayer(mpe);
} else {
Toast.makeText(list_activity.this, "Error", Toast.LENGTH_SHORT).show();
}
} catch (RuntimeException e) {
Log.d(TAG, "Error");
}
mpe.setVolume(0, 0);
if (j < (adapterWrapper.getAdapter().getCount())) {
if (x <= 0) {
i = i + 1;
j = j + 1;
}
x = x - 1;
}
mpa.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mediaPlayer) {
int en_sound2 = getResources().getIdentifier("e" + i, "raw", getPackageName());
mpt = MediaPlayer.create(list_activity.this, en_sound2);
mpt.start();
if (j < (adapterWrapper.getAdapter().getCount())) {
try {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
mpt.setNextMediaPlayer(mpa);
} else {
Toast.makeText(list_activity.this, "Error", Toast.LENGTH_SHORT).show();
}
} catch (RuntimeException e) {
Log.d(TAG, "Error");
}
} else {
stop(view);
}
}
}
);
}
}
);
}
logcat的
04-27 16:03:27.210 128-9135/? A/libc: @@@ ABORTING: heap corruption detected by dlmalloc
04-27 16:03:27.210 128-9135/? A/libc: Fatal signal 11 (SIGSEGV) at 0xdeadbaad (code=1), thread 9135 (TimedEventQueue)
04-27 16:03:27.730 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:27.730 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:27.730 120-120/? E/local_camera: We have a problem with the hw connection 0 (Success)
04-27 16:03:27.730 121-121/? E/local_camera: We have a problem with the hw connection 0 (Success)
04-27 16:03:27.734 8882-8882/learnenglish.listenenglish.englisheasy E/MediaPlayer: Error (100,0)
04-27 16:03:27.810 9172-9172/? E/MonoPipe: Failed to fetch local time frequency when constructing a MonoPipe (res = -32). getNextWriteTimestamp calls will be non-functional
04-27 16:03:28.738 9172-9172/? E/WVMExtractor: Failed to open libwvm.so
04-27 16:03:28.742 9172-9172/? A/libc: Fatal signal 11 (SIGSEGV) at 0x00000007 (code=1), thread 9172 (mediaserver)
04-27 16:03:28.922 123-123/? E/Corkscrew: unrecognized DW_CFA_* instruction: 0x10
04-27 16:03:28.962 8882-8882/learnenglish.listenenglish.englisheasy E/MediaPlayer: Error (100,0)
04-27 16:03:28.962 8882-8882/learnenglish.listenenglish.englisheasy E/MediaPlayer: Unable to to create media player
04-27 16:03:28.966 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:28.966 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:28.966 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:28.966 8882-8894/learnenglish.listenenglish.englisheasy E/MediaPlayer: error (100, 0)
04-27 16:03:28.966 8882-8882/learnenglish.listenenglish.englisheasy E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException
at learnenglish.listenenglish.englisheasy.list_activity$2.onCompletion(list_activity.java:513)
at android.media.MediaPlayer$EventHandler.handleMessage(MediaPlayer.java:2046)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5103)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:525)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:737)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:553)
at dalvik.system.NativeStart.main(Native Method)
04-27 16:03:29.234 1333-1398/system_process E/AudioService: Media server died.
04-27 16:03:32.998 9268-9268/? E/MonoPipe: Failed to fetch local time frequency when constructing a MonoPipe (res = -32). getNextWriteTimestamp calls will be non-functional
04-27 16:03:33.238 1333-1398/system_process E/AudioService: Media server started.
04-27 16:03:33.738 9174-9174/? E/local_camera: We have a problem with the hw connection 0 (Success)
04-27 16:03:33.738 9173-9173/? E/local_camera: We have a problem with the hw connection 0 (Success)
[ 04-27 16:03:34.654 58: 58 D/ ]
Socket deconnection
[ 04-27 16:03:36.666 58: 58 D/ ]
Socket deconnection
[ 04-27 16:03:38.682 58: 58 D/ ]
Socket deconnection