views:

794

answers:

4

Hi everyone.

I was thinking about implementing an application in java (with GWT gui) that among its options will be able to play youtube video and audio, or at least only audio. 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, play it using java. Any ideas?

Thanks ahead, Alex

+1  A: 

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).

The easiest path, IMHO, is to get the player ID and use the custom player to 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.

Ravi Wallau
A: 

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.

To do the former, check out this GreaseMonkey script for ideas: http://userscripts.org/scripts/review/17972 Essentially, you have to get the HTML for the Youtube page, parse it and extract the URL of the FLV file.

To do the latter, you can use the Java Media Foundation along 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. Jffmpeg is one of these. Another is FFMPEG-Java.

Chinmay Kanchi
+2  A: 

Have a look at Google's YouTube Data API, retrieving a VideoEntry should 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.

Pascal Thivent
Awesome! I didn't know that this even existed.
Chinmay Kanchi
A: 

Use Xuggler's MediaViewer object for a Java media player, and check out the Xuggle-Utils library for a set of utility functions for getting a playable FLV from a Youtube URL.

  • Art
Xuggle