根据kitakt 4.4的变化,播放shoutcast流有些问题(那些返回“ICY”而不是“HTTP / 1.x”响应).
因此,kitkat的解决方案是在我们打开流之前在JVM中重新注册“icy”协议前缀:
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 ); }
我有开放音频流的问题,使其注册.在我调用url.opnestream(stream)后,我得到了异常:
java.net.ProtocolException: Unexpected status line: ICY 200 OK
我该怎么办呢?
这是注册音频的样本,到目前为止我做了什么..
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;