我正在使用 StreamProxy 类,以便使用MediaPlayer
. 所以,我写了一些代码如下来启动本地服务器:
ProxyStream proxyStream = new ProxyStream();
proxyStream.init();
proxyStream.start();
至此,本地服务器创建成功,并获得了特殊端口。(port 41257
获得)。我知道我们可以通过尝试将链接作为http://127.0.0.1:41257/http://printf.ir/music/01.mp3
. 现在,我想使用 MediaPlayer 对象进行流式传输并尝试如下代码:
this.mediaPlayer.setDataSource("127.0.0.1:41257/http://printf.ir/music/01.wma");
this.mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
this.mediaPlayer.prepare();
在运行时,异常发生在第三行代码中,我将其粘贴在这里:
05-17 18:49:49.989: W/System.err(10444): java.io.IOException: Prepare failed.: status=0x1
05-17 18:49:49.989: W/System.err(10444): at android.media.MediaPlayer.prepare(Native Method)
05-17 18:49:49.989: W/System.err(10444): at com.exmaple.stream.StreamMediaPlayerActivity.onClick(StreamMediaPlayerActivity.java:83)
05-17 18:49:49.989: W/System.err(10444): at android.view.View.performClick(View.java:2485)
05-17 18:49:49.989: W/System.err(10444): at android.view.View$PerformClick.run(View.java:9080)
05-17 18:49:49.989: W/System.err(10444): at android.os.Handler.handleCallback(Handler.java:587)
05-17 18:49:49.989: W/System.err(10444): at android.os.Handler.dispatchMessage(Handler.java:92)
05-17 18:49:49.989: W/System.err(10444): at android.os.Looper.loop(Looper.java:130)
05-17 18:49:49.989: W/System.err(10444): at android.app.ActivityThread.main(ActivityThread.java:3687)
05-17 18:49:49.989: W/System.err(10444): at java.lang.reflect.Method.invokeNative(Native Method)
05-17 18:49:49.989: W/System.err(10444): at java.lang.reflect.Method.invoke(Method.java:507)
05-17 18:49:49.989: W/System.err(10444): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:867)
05-17 18:49:49.989: W/System.err(10444): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:625)
05-17 18:49:49.989: W/System.err(10444): at dalvik.system.NativeStart.main(Native Method)
如何使用 MediaPlayer 进行流式传输?!请帮我解决这个问题。
谢谢你的提前:)