我无法使用orroids MediaPlayer传输wav音频文件。
波形文件的URL已成功验证并在设备上单独下载。 这些下载的文件没有问题,但是当相同的文件流式传输到播放器时,它根本不会播放并出错。
01-18 09:25:00.963: E/MediaPlayer(8825): error (1, -4)
01-18 09:25:00.963: W/System.err(8825): java.io.IOException: Prepare failed.: status=0x1
01-18 09:25:00.963: W/System.err(8825): at android.media.MediaPlayer.prepare(Native Method)
01-18 09:25:00.963: W/System.err(8825): at com.movivation.wavetrial.AudioPlayer.playMedia(AudioPlayer.java:174)
01-18 09:25:00.963: W/System.err(8825): at com.movivation.wavetrial.AudioPlayer.onCreate(AudioPlayer.java:92)
01-18 09:25:00.963: W/System.err(8825): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
01-18 09:25:00.963: W/System.err(8825): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:2633)
01-18 09:25:00.963: W/System.err(8825): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:2685)
01-18 09:25:00.963: W/System.err(8825): at android.app.ActivityThread.access$2300(ActivityThread.java:126)
01-18 09:25:00.963: W/System.err(8825): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2038)
01-18 09:25:00.963: W/System.err(8825): at android.os.Handler.dispatchMessage(Handler.java:99)
01-18 09:25:00.963: W/System.err(8825): at android.os.Looper.loop(Looper.java:123)
01-18 09:25:00.963: W/System.err(8825): at android.app.ActivityThread.main(ActivityThread.java:4633)
01-18 09:25:00.963: W/System.err(8825): at java.lang.reflect.Method.invokeNative(Native Method)
01-18 09:25:00.973: W/System.err(8825): at java.lang.reflect.Method.invoke(Method.java:521)
01-18 09:25:00.973: W/System.err(8825): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:858)
01-18 09:25:00.973: W/System.err(8825): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:616)
01-18 09:25:00.973: W/System.err(8825): at dalvik.system.NativeStart.main(Native Method)
01-18 09:25:00.973: I/MediaPlayer(8825): Info (1,26)
播放文件的代码:
private void playMedia(boolean isWebUrl) {
mPlayer = new MediaPlayer();
mPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mPlayer.setOnCompletionListener(new OnCompletionListener() {
@Override
public void onCompletion(MediaPlayer mp) {
Log.d(tag, "Ending thread");
isPlaying = false;
if (pd != null) {
pd.dismiss();
}
}
});
mPlayer.setOnPreparedListener(new OnPreparedListener() {
@Override
public void onPrepared(MediaPlayer mp) {
Log.d(tag, "starting");
mPlayer.start();
mSeekbar.setProgress(0);
mSeekbar.setMax(mPlayer.getDuration());
Log.d(tag, "seek started");
new PlayAsync().execute();
}
});
mSeekbar.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
}
@Override
public void onProgressChanged(SeekBar seekBar, int progress,
boolean fromUser) {
if (fromUser) {
mPlayer.seekTo(progress);
mSeekbar.setProgress(progress);
}
}
});
try {
if (isWebUrl) {
Log.d(tag, "playing tmp file");
mPlayer.setDataSource(url);
} else {
File f = new File(fileurl);
FileInputStream fis = new FileInputStream(f);
mPlayer.setDataSource(fis.getFD());
}
Log.d(tag, "calling prepare");
mPlayer.prepare(); //originally i use prepareAsync()
} catch (IllegalArgumentException e) {
e.printStackTrace();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
我尝试播放的文件实际上是一个wave文件,我没有找到任何关于上述错误的具体说法。
任何有关波形流或错误本身的指针都将受到高度赞赏。 感谢。
答案 0 :(得分:0)