如何在VideoView上播放Youtube視頻?如何在VideoView上播放Youtube視頻?
我從以下網址
提取採用了RSS(XML解析)許多YouTube視頻網址,但問題是這樣的HTTP鏈接中videoview不播放。
Plaese幫幫我。
如何在VideoView上播放Youtube視頻?如何在VideoView上播放Youtube視頻?
我從以下網址
提取採用了RSS(XML解析)許多YouTube視頻網址,但問題是這樣的HTTP鏈接中videoview不播放。
Plaese幫幫我。
您想將您的gdata網址轉換爲rtsp格式。以下功能將您的網址轉換爲rtsp格式。
public static String getUrlVideoRTSP(String urlYoutube) {
try {
String gdy = "http://gdata.youtube.com/feeds/base/videos/-/justinbieber?orderby=published&alt=rss&client=ytapi-youtube-rss-redirect&v=2";
DocumentBuilder documentBuilder = DocumentBuilderFactory
.newInstance().newDocumentBuilder();
String id = extractYoutubeId(urlYoutube);
URL url = new URL(gdy + id);
HttpURLConnection connection = (HttpURLConnection) url
.openConnection();
Document doc = documentBuilder.parse(connection.getInputStream());
Element el = doc.getDocumentElement();
NodeList list = el.getElementsByTagName("media:content");// /media:content
String cursor = urlYoutube;
for (int i = 0; i < list.getLength(); i++) {
Node node = list.item(i);
if (node != null) {
NamedNodeMap nodeMap = node.getAttributes();
HashMap<String, String> maps = new HashMap<String, String>();
for (int j = 0; j < nodeMap.getLength(); j++) {
Attr att = (Attr) nodeMap.item(j);
maps.put(att.getName(), att.getValue());
}
if (maps.containsKey("yt:format")) {
String f = maps.get("yt:format");
if (maps.containsKey("url")) {
cursor = maps.get("url");
}
if (f.equals("1"))
return cursor;
}
}
}
return cursor;
} catch (Exception ex) {
Log.e("Get Url Video RTSP Exception======>>", ex.toString());
}
return urlYoutube;
}
private static String extractYoutubeId(String url) {
return url;
}
而完整的例子展示瞭如何從Youtube頻道如果你解決它,然後接受的答案裏面的視頻在列表視圖中click here
hello hardik,在這個例子中,視頻在webview中播放而不是mediaplayer,我想在mediaplayer中播放youtube視頻。 –
創建一個活動並將視頻的rtsp URL(用戶單擊的特定視頻的URL)作爲包傳遞,然後編寫波紋管代碼。 '捆綁捆= getIntent()getExtras();' \t \t'最終字符串數據= bundle.getString( 「視頻ID」);' \t \t'最終VideoView VV =(VideoView)findViewById(R.id.VideoView) ;' \t \t'的MediaController MC =新的MediaController(本);' \t \t'mc.setEnabled(真);' \t \t'mc.show(0);' \t \t'vv.setMediaController( mc);' \t \t'vv.setVideoURI(Uri.parse(getUrlVideoRTSP(da ta)));' –
你試過這個嗎? –
。 –