Android的java.io.IOException异常与音频流 [英] Android java.io.IOException with audio streaming

查看:414
本文介绍了Android的java.io.IOException异常与音频流的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我使用web服务我正在运行IOException异常在流audioplayer

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.

我上面的错误,当我使用以下网址
http://cdnbakmi.kaltura.com/p/672322/sp/67232200/raw/entry_id/0_281db5u2/version/0

但有任何错误,执行我的应用程序时,我与样品网址 HTTP努力://www.pocketjourney.com/downloads/pj/tutorials/audio.mp3

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

我写的波纹管code为我的应用

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.

先谢谢了。

编辑:
我用这个code解决这个问题。

edit: I solve this problem by using this code

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

我使用上述code得到重定向URL。

I get the redirect url by using above code.

推荐答案

当它不是一台服务器的工作(和另一个工作),这意味着问题出在服务器(响应),而不是在你的应用程序。尝试在浏览器首先这些链接。

When its 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.

失败的链接被重定向到另一个URL,它是实际的MP3 URL。
所以,你需要连接的URL并获得可能包含实际MP3 URL的响应。

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.

我觉得这得到新的URL。

I think this get the new url.

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

这篇关于Android的java.io.IOException异常与音频流的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆