https://play.google.com/store/apps/details?id=com.sirius.fm.radio这是我的应用程序网址。

在其中,我从喊播流传输音频,它工作正常,直到android release kitkat更新,最近我在android kitkat上运行应用程序时遇到了问题,它没有在kitkat OS版本中播放广播。

这是我正在使用的流URL

http://s8.voscast.com:7112

这是我正在使用kitkat版本的错误日志

07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425): Unable to initialize the MediaPlayer for fileUrl=http://s8.voscast.com:7112
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425): java.net.ProtocolException: Unexpected status line: ICY 200 OK
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.RawHeaders.setStatusLine(RawHeaders.java:108)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.RawHeaders.fromBytes(RawHeaders.java:308)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.HttpTransport.readResponseHeaders(HttpTransport.java:135)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.HttpEngine.readResponse(HttpEngine.java:644)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.execute(HttpURLConnectionImpl.java:347)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.getResponse(HttpURLConnectionImpl.java:296)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.android.okhttp.internal.http.HttpURLConnectionImpl.getInputStream(HttpURLConnectionImpl.java:179)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.sirius.fm.radio.StreamingMediaPlayer.downloadAudioIncrement(StreamingMediaPlayer.java:117)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.sirius.fm.radio.StreamingMediaPlayer$startRadio.doInBackground(StreamingMediaPlayer.java:88)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at com.sirius.fm.radio.StreamingMediaPlayer$startRadio.doInBackground(StreamingMediaPlayer.java:1)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at android.os.AsyncTask$2.call(AsyncTask.java:288)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at java.util.concurrent.FutureTask.run(FutureTask.java:237)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1112)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:587)
07-17 06:15:22.911: E/com.sirius.fm.radio.StreamingMediaPlayer$startRadio(1425):    at java.lang.Thread.run(Thread.java:841)
07-17 06:15:22.941: E/on post exte(1425): post exte

在所有其他版本的android中,例如Micromax Canvas 4 A210Samsung Galaxy s3等。其中没有kitkat版本,它可以正常工作。

在kitkat设备中,例如Lg OptimusNexus 5Nexus 4时,它不起作用,它显示上述错误

任何帮助/指南行将不胜感激。

不管怎么说,还是要谢谢你

最佳答案

终于我得到了解决方案

我将以下方法替换为新方法

URLConnection cn = new URL(mediaUrl).openConnection();
        cn.setRequestProperty("Icy-metadata", "1");
        cn.connect();
        InputStream stream = cn.getInputStream();
        if (stream == null) {
            Log.e(getClass().getName(),"Unable to create InputStream for mediaUrl:" + mediaUrl);
        }

将上述方法替换为以下所述的一种新方法
final int CONNECT_TIMEOUT_MILLIS = 60 * 1000; // 30s
              final int READ_TIMEOUT_MILLIS = 85 * 1000; // 45s

         OkHttpClient client = new com.squareup.okhttp.OkHttpClient();
            client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
            client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
           OkUrlFactory okUrlFact= new OkUrlFactory(client);

        HttpURLConnection con=   okUrlFact.open(new URL(mediaUrl) );
        con.setRequestProperty("Icy-metadata", "1");
        con.connect();

希望对您有所帮助

谢谢

10-06 08:41