此代码在三星GT-I93001中运行良好,同时在三星SGH-M919设备中给出以下错误。两者都有相同的4.4.4版本。可能有人指向我正确的方向。这个设备是否有特定错误?是什么原因?
private final String AUDIO_URL = " http://techslides.com/demos/samples/sample.mp3 ";
this is the issue only in one device.
public void playAudio()
{
mediaPlayer = new MediaPlayer();
try {
mediaPlayer.reset();
mediaPlayer.setDataSource(AUDIO_URL);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepare();
mediaPlayer.setOnPreparedListener(new MediaPlayer.OnPreparedListener(){
public void onPrepared(MediaPlayer mp) {
mp.start();
}
});
} catch (IllegalArgumentException e) {
Log.d(MainActivity.class.getName(), "IllegalArgumentException:" );
e.printStackTrace();
} catch (IllegalStateException e) {
Log.d(MainActivity.class.getName(), "IllegalStateException:" );
e.printStackTrace();
} catch (IOException e) {
Log.d(MainActivity.class.getName(), "IOException:" );
Toast.makeText(MainActivity.this, "str_error_io_exception", Toast.LENGTH_LONG).show();
e.printStackTrace();
}
}
请检查logcat错误:
logcat的:
V/MediaPlayer-JNI: native_setup
01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: constructor
01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: setListener
01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer-JNI: reset
01-03 09:32:21.348 22239-22239/com.example.abc V/MediaPlayer: reset
01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: message received msg=8, ext1=0, ext2=0
01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer-JNI: setAudioStreamType: 3
01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: MediaPlayer::setAudioStreamType
01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: setVideoSurfaceTexture
01-03 09:32:21.358 22239-22239/com.example.abc V/MediaPlayer: prepare
01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: unrecognized message: (8, 0, 0)
01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: callback application
01-03 09:32:21.358 22239-22250/com.example.abc V/MediaPlayer: back from callback
01-03 09:32:23.050 22239-22251/com.example.abc V/MediaPlayer: message received msg=100, ext1=1, ext2=-1004
01-03 09:32:23.060 22239-22251/com.example.abc E/MediaPlayer: error (1, -1004)
01-03 09:32:23.060 22239-22251/com.example.abc V/MediaPlayer: signal application thread
01-03 09:32:23.060 22239-22239/com.example.abc V/MediaPlayer: prepare complete - status=1
01-03 09:32:23.060 22239-22239/com.example.abc D/com.example.abc.MainActivity: IOException:
01-03 09:32:23.060 22239-22239/com.example.abc D/Toast: checkMirrorLinkEnabled returns : false
01-03 09:32:23.060 22239-22239/com.example.abc D/Toast: showing allowed
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: java.io.IOException: Prepare failed.: status=0x1
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.media.MediaPlayer.prepare(Native Method)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at com.example.abc.MainActivity.playAudio(MainActivity.java:56)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at com.example.abc.MainActivity$2.onClick(MainActivity.java:44)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.view.View.performClick(View.java:4753)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.view.View$PerformClick.run(View.java:19562)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.os.Handler.handleCallback(Handler.java:733)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.os.Handler.dispatchMessage(Handler.java:95)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.os.Looper.loop(Looper.java:146)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at android.app.ActivityThread.main(ActivityThread.java:5635)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at java.lang.reflect.Method.invokeNative(Native Method)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at java.lang.reflect.Method.invoke(Method.java:515)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:1291)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1107)
01-03 09:32:23.060 22239-22239/com.example.abc W/System.err: at dalvik.system.NativeStart.main(Native Method)
答案 0 :(得分:1)
检查此代码
if (mediaPlayer == null) {
mediaPlayer = new MediaPlayer();
mediaPlayer.setOnCompletionListener(new MediaPlayer.OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
mediaPlayer.reset();
}
});
}
if (mediaPlayer.isPlaying()) {
mediaPlayer.stop();
mediaPlayer.reset();
}
mediaPlayer.setDataSource(audioUrl);
mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.prepare();
mediaPlayer.start();
}
});
}
if (mediaPlayer.isPlaying() && currentPlaying == getAdapterPosition()) {
mediaPlayer.stop();
mediaPlayer.reset();
}