Java GUI 中的 YouTube 播放器
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1971952/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
YouTube Player in Java GUI
提问by Alex
I was thinking about implementing an application in Java (with a GWT GUI) that among its options will be able to play YouTube video and audio, or at least only audio.
我正在考虑用 Java(带有 GWT GUI)实现一个应用程序,它的选项之一将能够播放 YouTube 视频和音频,或者至少只能播放音频。
The problem is that I can't seem to find any API or source code that enables it. What I want is that given a URL for a video in YouTube, one can play it using Java.
问题是我似乎找不到任何启用它的 API 或源代码。我想要的是给定一个 YouTube 视频的 URL,可以使用 Java 播放它。
采纳答案by Pascal Thivent
Have a look at Google's YouTube Data API, retrieving a VideoEntryshould be pretty trivial (see for example Interact with YouTube from Java ). Playing them from Java may require a bit more work and I guess you'll need to embed a SWF Player. Or maybe check gwt2swf, a Flash/Flex Widget for GWT.
看看谷歌的YouTube 数据 API,检索 aVideoEntry应该非常简单(参见例如Interact with YouTube from Java)。从 Java 播放它们可能需要更多的工作,我想您需要嵌入一个 SWF 播放器。或者检查gwt2swf,一个用于 GWT 的 Flash/Flex 小部件。
回答by Art Clarke
回答by Ravi Wallau
I guess in order to do that you would have to make our Java application play Flash videos. There is this Java Flash Player API, but I am really not sure how it will work. You will have to check the terms and conditions of YouTube to check if this is allowed - and also to check if you can get more of the video information with the YouTube API(from the video URL).
我想为了做到这一点,您必须让我们的 Java 应用程序播放 Flash 视频。有这个Java Flash Player API,但我真的不确定它会如何工作。您必须查看 YouTube 的条款和条件,以检查是否允许这样做 - 还要检查是否可以使用YouTube API(从视频 URL)获取更多视频信息。
The easiest path, IMHO, is to get the player ID and use the custom playerto open a browser page only with the player on it. It will not be embedded inside your application, but it should work as a charm.
恕我直言,最简单的方法是获取播放器 ID 并使用自定义播放器打开仅包含播放器的浏览器页面。它不会嵌入到您的应用程序中,但它应该具有魅力。
回答by Chinmay Kanchi
Youtube video is encoded using Adobe's Flash Video format. Essentially, what you need to do is get the FLV file and find some way to play it using Java.
Youtube 视频使用 Adobe 的 Flash 视频格式进行编码。本质上,您需要做的是获取 FLV 文件并找到某种使用 Java 播放它的方法。
To do the former, check out this GreaseMonkey script for ideas: http://userscripts.org/scripts/review/17972Essentially, you have to get the HTML for the Youtube page, parse it and extract the URL of the FLV file.
要执行前者,请查看此 GreaseMonkey 脚本以获取想法:http: //userscripts.org/scripts/review/17972本质上,您必须获取 Youtube 页面的 HTML,对其进行解析并提取 FLV 文件的 URL。
To do the latter, you can use the Java Media Foundationalong with a library that provides codecs. There seem to be several wrappers available for FFMPEG, which can handle most of the common codecs found in FLV files. Jffmpegis one of these. Another is FFMPEG-Java.
要完成后者,您可以使用Java Media Foundation以及提供编解码器的库。FFMPEG 似乎有几个包装器可用,它们可以处理 FLV 文件中的大多数常见编解码器。Jffmpeg就是其中之一。另一个是FFMPEG-Java。

