意外的状态行:ICY 200确定为URL的OpenStream()方法? [英] Unexpected status line: ICY 200 OK for URL openStream() method?

查看:622
本文介绍了意外的状态行:ICY 200确定为URL的OpenStream()方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

据为kitakt 4.4的变化出现了一些问题,玩的Shoutcast流(交还ICY,而不是HTTP / 1.x的响应)。

因此​​,对于奇巧的解决办法是重新注册冰冷协议preFIX在JVM中,我们通过这个开流过一次:

 尝试{
        java.net.URL.setURLStreamHandlerFactory(新java.net.URLStreamHandlerFactory(){
            公共java.net.URLStreamHandler中createURLStreamHandler(字符串协议){
                Log.d(LOG,问计流处理程序的协议:+协议+');
                如果(冰冷.equals(协议))返回新com.spoledge.aacde coder.IcyURLStreamHandler();
                返回null;
            }
        });
}
捕获(的Throwable T){
        Log.w(LOG,不能设置ICY的URLStreamHandler  - 也许已经设置 - + T);
}
 

我有问题,打开音频流,使其注册。我叫url.opnestream(流)后,我得到了异常:

  

java.net.ProtocolException:意外的状态行:ICY 200 OK

我怎么能解决呢?


下面是注册的音频,到目前为止,我所做的样本。

 尝试{
    网址URL = NULL;
    URL =新的URL(U);
    的InputStream = url.openStream();

    的startTime = System.currentTimeMillis的();

    布尔ISSD present = android.os.Environment.getExternalStorageState()等于(android.os.Environment.MEDIA_MOUNTED)。

    字符串文件名=文件分割符+radio_+recording_+ channelMetadata.replaceAll(\\ W,)+ System.currentTimeMillis的();

    如果(ISSD present)
    {
        outputSource = Environment.getExternalStorageDirectory()+文件名;
    }
    其他
    {
        outputSource = Environment.getDataDirectory()+文件名;
    }

    如果(contentType.equals(音频/ AACP))
        的FileOutputStream =新的FileOutputStream(outputSource +.ACC);
    否则如果(contentType.equals(音频/ MPEG))
        的FileOutputStream =新的FileOutputStream(outputSource +.MP3);
    其他
        的FileOutputStream =新的FileOutputStream(outputSource +.nieznany_format);

    INT读取动作= 0;
    诠释字节;
    而(((字节= inputStream.read())= -1)及!&安培; isRecording){

        fileOutputStream.write(字节);
        读取动作++;

        停止时间= System.currentTimeMillis的();

        长秒=(Math.abs(startTime时,停止时间));
        INT分钟= 1000 * 60 * 60;

        如果(分钟< =秒)
        {
            Log.d(XXX,录制任务超过停止);
            打破;
        }
    }

    inputStream.close();
    fileOutputStream.close();

}赶上(IOException异常E){
    e.printStackTrace();
    isRecording = FALSE;
}

isRecording = FALSE;
返回null;
 

解决方案

的各种变化为Android 4.4被做了,它似乎是非标准的Shoutcast ICY 头不被Android的支持。

看来,虽然这对 OkHttp 好人固定的问题(的问题1 问题2 )已经几天前。照片 你可以做的,就是干脆直接用OkHttp LIB在你的应用程序,并通过你会使用较新的OkHttp版本(一个与修复),而不是一个附带的Andr​​oid(在这里,你将不得不等待OS更新)。
这也将解决它的运行就可能受到该问题的其他设备应用程序。

According to changes for kitakt 4.4 there were some problems with playing shoutcast streams (those returning "ICY" instead of "HTTP/1.x" response).

So solution for kitkat was to reregister "icy" protocol prefix in JVM once before we opened a stream by this:

try {
        java.net.URL.setURLStreamHandlerFactory( new java.net.URLStreamHandlerFactory(){
            public java.net.URLStreamHandler createURLStreamHandler( String protocol ) {
                Log.d( LOG, "Asking for stream handler for protocol: '" + protocol + "'" );
                if ("icy".equals( protocol )) return new com.spoledge.aacdecoder.IcyURLStreamHandler();
                return null;
            }
        });
}
catch (Throwable t) {
        Log.w( LOG, "Cannot set the ICY URLStreamHandler - maybe already set ? - " + t );
}

I have problem with open audio stream to make it register. After I call url.opnestream(stream) I got exception:

java.net.ProtocolException: Unexpected status line: ICY 200 OK

How could I fix it?


Here is sample of registering audio, so far what I did..

try {
    URL url = null;
    url = new URL(u);
    inputStream = url.openStream();

    startTime = System.currentTimeMillis();

    Boolean isSDPresent = android.os.Environment.getExternalStorageState().equals(android.os.Environment.MEDIA_MOUNTED);

    String fileName = File.separator + "radio_" + "recording_" + channelMetadata.replaceAll("\\W", "") + System.currentTimeMillis();

    if(isSDPresent)
    {
        outputSource = Environment.getExternalStorageDirectory() + fileName;
    }
    else
    {
        outputSource = Environment.getDataDirectory() + fileName;
    }

    if(contentType.equals("audio/aacp"))
        fileOutputStream = new FileOutputStream(outputSource  + ".acc");
    else if(contentType.equals("audio/mpeg"))
        fileOutputStream = new FileOutputStream(outputSource + ".mp3");
    else
        fileOutputStream = new FileOutputStream(outputSource + ".nieznany_format");

    int bytesRead = 0;
    int bytes;
    while (((bytes = inputStream.read()) != -1) && isRecording) {

        fileOutputStream.write(bytes);
        bytesRead++;

        stopTime = System.currentTimeMillis();

        long seconds = (Math.abs(startTime-stopTime));
        int minutes = 1000 * 60 * 60;

        if(minutes<=seconds)
        {
            Log.d("xxx", "recording task exceed stopped");
            break;
        }
    }

    inputStream.close();
    fileOutputStream.close();

} catch (IOException e) {
    e.printStackTrace();
    isRecording = false;
}

isRecording = false;
return null;

解决方案

Various changes were made for Android 4.4, and it seems that the non-standard ShoutCast ICY header is not supported by Android.

It seems though that the good people of OkHttp fixed the issue (issue 1 and issue 2) already a few days ago.
What you can do, is simply use OkHttp lib directly in your application and by that you'll use the newer OkHttp version (the one with the fix) and not the one shipped with Android (where you'll have to wait for an OS update).
This will also fix it for your application running on other devices that might suffer from that issue.

这篇关于意外的状态行:ICY 200确定为URL的OpenStream()方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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