Android java.io.IOException with audio streaming

∥☆過路亽.° 提交于 2020-01-13 05:52:51

问题


When I am running audioplayer in streaming by using webservices I am getting IOException

08-19 09:24:54.235: WARN/System.err(394): java.io.IOException: Prepare failed.: status=0x64
08-19 09:24:54.235: WARN/System.err(394):     at android.media.MediaPlayer.prepare(Native Method)
08-19 09:24:54.235: WARN/System.err(394):     at com.sparsh.xavier.media.activity.AudioPlayerActivity$6$1.run(AudioPlayerActivity.java:183)
08-19 09:24:54.295: WARN/System.err(394):     at android.os.Handler.handleCallback(Handler.java:587)
08-19 09:24:54.295: WARN/System.err(394):     at android.os.Handler.dispatchMessage(Handler.java:92)
08-19 09:24:54.295: WARN/System.err(394):     at android.os.Looper.loop(Looper.java:123)
08-19 09:24:54.295: WARN/System.err(394):     at android.app.ActivityThread.main(ActivityThread.java:4627)
08-19 09:24:54.295: WARN/System.err(394):     at java.lang.reflect.Method.invokeNative(Native Method)
08-19 09:24:54.295: WARN/System.err(394):     at java.lang.reflect.Method.invoke(Method.java:521)
08-19 09:24:54.295: WARN/System.err(394):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
08-19 09:24:54.295: WARN/System.err(394):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
08-19 09:24:54.295: WARN/System.err(394):     at dalvik.system.NativeStart.main(Native Method)
08-19 09:24:55.075: ERROR/AudioService(68): Media server died.

I have the above error when I am using below url http://cdnbakmi.kaltura.com/p/672322/sp/67232200/raw/entry_id/0_281db5u2/version/0

but execute my application with out any errors when I am trying with sample url http://www.pocketjourney.com/downloads/pj/tutorials/audio.mp3

I write bellow code for my application

mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC);
mediaPlayer.reset();
mediaPlayer.setDataSource(audioURL);
mediaPlayer.prepare(); // might take long! (for buffering, etc)
mediaPlayer.start();

please tell me is this problem with my coding or with providing url.

thanks in advance.

edit: I solve this problem by using this code

HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setInstanceFollowRedirects(false);
String redirectUrl = conn.getHeaderField("Location");

I get the redirect url by using above code.


回答1:


When it's not working with one server (and working for another) it means the problem is with the server (response) and not in your app. Try those links in browser first.

The failing link is redirecting to another URL that is actual MP3 URL. So you need to connect to the URL and get the response that may contain the actual mp3 URL.

I think this get the new URL.

HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();
 urlConnection.getURL()// should give you the new URL dynamically created by server.


来源:https://stackoverflow.com/questions/7116947/android-java-io-ioexception-with-audio-streaming

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!