Android Media Player网址音频

时间:2013-06-10 17:23:43

标签: java android url streaming media

我正在创建一个可以从网址流式传输音频的应用。但我得到错误。
这是代码:

   MediaPlayer mediaPlayer = new MediaPlayer();
    try {
        mediaPlayer.setDataSource("http://http://www.glowingpigs.com/audioclip/10.mp3");
    } catch (IllegalArgumentException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (SecurityException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    try {
        mediaPlayer.prepare();
    } catch (IllegalStateException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    mediaPlayer.start();

这是错误:

<br><br>06-10 18:18:27.993: E/MediaPlayer(10319): error (1, -1004)
<br><br>06-10 18:18:27.993: W/System.err(10319): java.io.IOException: Prepare failed.: status=0x1
<br><br>06-10 18:18:28.003: W/System.err(10319):    at android.media.MediaPlayer.prepare(Native Method)
<br><br>06-10 18:18:28.003: W/System.err(10319):    at com.frlmedia.frlradio.MainActivity.onCreate(MainActivity.java:34)
<br><br>06-10 18:18:28.003: W/System.err(10319):    at android.app.Activity.performCreate(Activity.java:4465)
<br><br>06-10 18:18:28.003: W/System.err(10319):    at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.app.ActivityThread.access$600(ActivityThread.java:127)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.os.Handler.dispatchMessage(Handler.java:99)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.os.Looper.loop(Looper.java:137)
<br><br>06-10 18:18:28.013: W/System.err(10319):    at android.app.ActivityThread.main(ActivityThread.java:4441)
<br><br>06-10 18:18:28.023: W/System.err(10319):    at java.lang.reflect.Method.invokeNative(Native Method)
<br><br>06-10 18:18:28.023: W/System.err(10319):    at java.lang.reflect.Method.invoke(Method.java:511)
<br><br>06-10 18:18:28.023: W/System.err(10319):    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
<br><br>06-10 18:18:28.023: W/System.err(10319):    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
<br><br>06-10 18:18:28.033: W/System.err(10319):    at dalvik.system.NativeStart.main(Native Method)
<br><br>06-10 18:18:28.033: E/MediaPlayer(10319): start called in state 0
<br><br>06-10 18:18:28.033: E/MediaPlayer(10319): error (-38, 0)
<br><br>06-10 18:18:28.043: E/MediaPlayer(10319): Error (-38,0)
<br><br>06-10 18:18:28.043: D/TextLayoutCache(10319): Using debug level: 0 - Debug Enabled: 0
<br><br>06-10 18:18:28.053: D/libEGL(10319): loaded /system/lib/egl/libGLES_android.so
<br><br>06-10 18:18:28.053: D/libEGL(10319): loaded /system/lib/egl/libEGL_adreno200.so
<br><br>06-10 18:18:28.053: D/libEGL(10319): loaded /system/lib/egl/libGLESv1_CM_adreno200.so
<br><br>06-10 18:18:28.063: D/libEGL(10319): loaded /system/lib/egl/libGLESv2_adreno200.so
<br><br>06-10 18:18:28.073: I/Adreno200-EGLSUB(10319): <ConfigWindowMatch:2078>: Format RGBA_8888.
<br><br>06-10 18:18:28.093: D/memalloc(10319): /dev/pmem: Mapped buffer base:0x5c62c000 size:35270656 offset:31502336 fd:64
<br><br>06-10 18:18:28.093: E/(10319): Can't open file for reading
<br><br>06-10 18:18:28.093: E/(10319): Can't open file for reading
<br><br>06-10 18:18:28.093: D/OpenGLRenderer(10319): Enabling debug mode 0
<br><br>06-10 18:18:28.163: D/memalloc(10319): /dev/pmem: Mapped buffer base:0x5ec3f000 size:3768320 offset:0 fd:67

您可以删除不需要的错误。

1 个答案:

答案 0 :(得分:3)

我认为您错误输入了网址。

 将http://http://www.glowingpigs.com/audioclip/10.mp3替换为http://www.glowingpigs.com/audioclip/10.mp3

如果查看MediaPlayer class,您可以看到抛出的错误类型。

在你的情况下是:

public static final int MEDIA_ERROR_IO
File or network related operation errors.
Constant Value: -1004 (0xfffffc14)