如何播放YouTube视频VideoView?

编程入门 行业动态 更新时间:2024-10-09 20:25:52
本文介绍了如何播放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?

本文发布于:2023-11-27 18:47:07,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1639174.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:视频   YouTube   VideoView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!