本文介绍了如何播放YouTube视频VideoView?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何播放YouTube视频VideoView?
How to Play Youtube Video on VideoView?
我在使用RSS(XML解析)从以下网址获取很多的YouTube视频网址
I have fetch many youtube video url using rss(xml Parsing) from following url
gdata.youtube/feeds/base/videos/-/justinbieber?orderby=published&alt=rss&client=ytapi-youtube-rss-redirect&v=2
但问题是这样的HTTP链接是不是在videoview播放。
but problem is this http link is not played in videoview.
Plaese帮帮我吧。
Plaese Help me.
推荐答案您需要将您的GDATA网址RTSP格式。以下功能将您的网址进入RTSP格式。
You want to convert your gdata URL into rtsp format. Following function convert your URL into rtsp format.
public static String getUrlVideoRTSP(String urlYoutube) { try { String gdy = "gdata.youtube/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频道获得视频是的点击此处
And the complete example show how to get videos from Youtube channel in listview is click here
更多推荐
如何播放YouTube视频VideoView?
发布评论