我使用WebView
查看某些网页内容。有些页面会将我重定向到流式音频。当我使用设备浏览器访问流式音频URL时,它会提示我打开外部播放器或只是播放它。当我用WebView
打开它时,我看到一个空白页。
我的问题是:如何判断链接(或网址)实际上是流媒体音频并相应处理?
网址例如:
http://mobile.internet-radio.com/MobileInternetRadioPlayer.php?radio=dWszLmludGVybmV0LXJhZGlvLmNvbToxMDY5Nw==
答案 0 :(得分:0)
这是响应的HTTP标头:
HTTP/1.1 200 OK =>
Date => Wed, 06 Mar 2013 10:53:40 GMT
Server => Apache/2.2.16
X-Powered-By => PHP/5.3.3-7+squeeze14
Cache-Control => max-age=600
Expires => Wed, 06 Mar 2013 11:03:40 GMT
Connection => close
Content-Type => audio/mpeg
因此,返回Content-Type
是Audio MimeType's之一。这意味着要返回音频数据。
您可以使用HttpResponse.getHeaders()
方法获取标题列表。
答案 1 :(得分:0)
我就这样做了:
public String getMimeType(String strUrl) throws IOException, Exception {
HttpHead httpHead = new HttpHead(strUrl);
HttpResponse response = getHttpClient().execute(httpHead);
Header[] headersArr = response.getHeaders("Content-Type");
String mimeType = headersArr[0].getValue();
return mimeType;
}
使用它:
// check for special content
String mimeType = null;
try {
mimeType = getMimeType(urlStr).toLowerCase();
} catch (Exception e) {
}
if (mimeType != null) {
// AUDIO
if (mimeType.startsWith("audio")){
Uri uri = Uri.parse(urlStr);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "audio/*");
startActivity(intent);
return true;
} else if (mimeType.startsWith("video")){
Uri uri = Uri.parse(urlStr);
Intent intent = new Intent(android.content.Intent.ACTION_VIEW);
intent.setDataAndType(uri, "video/*");
startActivity(intent);
return true;
}
}