Play a YouTube video using JavaFX components

I know that we can play a video ( http://zzz/xx/123.flv ), by using the Media View component in JavaFX. In the similar way, is it possible to play a YouTube video in JavaFX ?
Thank you, for any help in advance.
Edited by: prabhakar9885 on Sep 17, 2010 4:00 PM

You might want to take a look at [this thread|http://forums.sun.com/thread.jspa?threadID=5446865], but barring the theoretically possible "hacks" mentioned there, not really.

Similar Messages

  • Play a YouTube video in JavaFX?

    Moderator action: deleted rant and cleaned up what remains.
    I am trying to make this code play an FLV video, and it doesn't show any video. Only Music. How can I convert, for instance, a YouTube video, to play in JavaFX? If I download a YouTube video, how can i encode it?
    package musica;
    import javafx.application.Application;
    import javafx.beans.property.ObjectProperty;
    import javafx.event.ActionEvent;
    import javafx.event.EventHandler;
    import javafx.scene.Scene;
    import javafx.scene.control.Button;
    import javafx.scene.layout.GridPane;
    import javafx.scene.layout.StackPane;
    import javafx.scene.media.Media;
    import javafx.scene.media.MediaErrorEvent;
    import javafx.scene.media.MediaPlayer;
    import javafx.scene.media.MediaView;
    import javafx.scene.text.Font;
    import javafx.scene.text.FontPosture;
    import javafx.stage.Stage;
    import javafx.util.Duration;
    import javax.swing.Action;
    import javax.swing.JFileChooser;
    import javax.swing.JOptionPane;
    //import javafx.io.http;
    * @author André Lopes
    public class Musica extends Application {
        public MediaPlayer MP;
        public Media Media;
        public static String URL;
        public static JFileChooser JFC;
        public static Duration currentTime;
        public MediaView mediaView;
        //Main
        public static void main(String[] args) {
            launch(args);
        public Musica()
         currentTime = Duration.ZERO;
         mediaView= new MediaView(MP);
           URL = "";
         //URL = "http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv";
        @Override
        public void start(Stage primaryStage) {
            primaryStage.setTitle("Hello! This is Yours Music Player!");
            //Botão Play
            Button Play = new Button();
            Play.setText("Play");
            Play.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent event1) {
                    Media = new Media(URL);
                    MP = new MediaPlayer(Media);
                    MP.setStartTime(currentTime);
                    mediaView.setMediaPlayer(MP);
                    MP.play();
                    System.out.println("?"+ MP.getStatus());
                    mediaView.setOnError(new EventHandler<MediaErrorEvent>() {
                    @Override
                    public void handle(MediaErrorEvent arg0) {
                                System.out.println("MP.getStatus: " + MP.getStatus());
            //Botão Hello World
            //Botão pra escolher Musica
            Button SelctFileButton = new Button();
            SelctFileButton.setText("Music Chooser/Finder:");
            SelctFileButton.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                  public void handle(ActionEvent arg0) {
                    System.out.println("Java File Chooser Opened");
                    JFileChooser search = new JFileChooser();
                    search.showDialog(search,URL);
                    URL = search.getSelectedFile().toURI().toString();
                    System.out.println("URL:"+URL);
           //Botão para pausar;
           Button Pause = new Button();
           Pause.setText("Pause");
           Pause.setFont(Font.font(null, FontPosture.ITALIC,15));
           Pause.setOnAction(new EventHandler<ActionEvent>() {
           @Override
                public void handle(ActionEvent arg0) {
                try {
                    currentTime = MP.getCurrentTime();
                    MP.pause();  
                    }catch(java.lang.NullPointerException e)
                     System.out.println("java.lang.NullPointerException \n");  
                     System.out.println("Error: Unable To pause! May happens if you didnt have a music Playing!");  
           //Botão Para Continuar;
           Button Continue = new Button();
           Continue.setText("Continue/UnPause");
           Continue.setOnAction(new EventHandler<ActionEvent>() {
                @Override
                public void handle(ActionEvent arg0) {
                   //MP.setStartTime(currentTime);
                   MP.pause();
            //Grid ! Layout
            GridPane grid = new GridPane();
            StackPane root = new StackPane();
            grid.setHgap(2);
            grid.setHgap(2);
            grid.setVgap(2);
            Scene Scene = new Scene(root,500,500);
            root.getChildren().add(grid);
            root.getChildren().add(mediaView);
            //Scene.getStylesheets().add(Musica.class.getResource("Musica.css").toExternalForm());
            //grid.getStyleClass().add(Musica.class.getResource("Musica.css").toExternalForm());
            primaryStage.setScene(Scene);
            primaryStage.show();
            //Adicionando Botoes no Grid
            grid.add(Play,10,10);
            grid.add(SelctFileButton,11,10);
            grid.add(Pause,10,11);
    }Edited by: 932269 on 06/05/2012 20:36
    Edited by: 932269 on 06/05/2012 20:37
    Edited by: EJP on 8/05/2012 12:02

    After the question title has been cleaned up, I can see now that it relates to youtube video playback.
    Just embed the youtube html5 video player in a webview and stream video from youtube.
    This will work for videos that youtube has made compatible with their html5 player (about 30% it seems).
    Here is a sample embedding a youtube hosted trailer uploaded by sony pictures.
    import javafx.application.Application;
    import javafx.scene.*;
    import javafx.scene.web.WebView;
    import javafx.stage.Stage;
    public class YouTubePlayer extends Application {
      public static void main(String[] args) throws Exception { launch(args); }
      @Override public void start(final Stage stage) throws Exception {
        final WebView webView = new WebView();
        webView.getEngine().loadContent(
          "<iframe width=\"640\" height=\"390\" src=\"http://www.youtube.com/embed/IyaFEBI_L24\" frameborder=\"0\" allowfullscreen></iframe>"
        stage.setScene(new Scene(webView, 660, 410));
        stage.show();
    }If you have any questions, you can read more about youtube embedding here: https://developers.google.com/youtube/player_parameters

  • Play YouTube Video Using Movie URL

    InDesign CS3
    Hello,
    Is it possible to insert a movie that uses a URL to a video on YouTube?  YouTube URL's do not contain the actual file name/type and I believe that is why I am unable to play the video - however I thought I would check and see if anyone has had success doing this.
    My goal is to be able to play the YouTube video within the exported PDF.

    http://www.youtube.com/watch?v=Go8zwKFyT-0
    Worked for me.

  • Why won't apple tv play some youtube videos it used to play?

    Why won't apple tv play some youtube videos it used to play?

    Ah I see what you mean. Do these specs help:
    Format : MPEG-4
    Format profile : Base Media / Version 2
    Codec ID : mp42
    File size : 525 MiB
    Duration : 20mn 59s
    Overall bit rate : 3 494 Kbps
    Encoded date : UTC 2009-08-19 08:38:05
    Tagged date : UTC 2009-08-19 08:38:35
    Video
    ID : 1
    Format : AVC
    Format/Info : Advanced Video Codec
    Format profile : [email protected]
    Format settings, CABAC : Yes
    Format settings, ReFrames : 5 frames
    Codec ID : avc1
    Codec ID/Info : Advanced Video Coding
    Duration : 20mn 59s
    Bit rate mode : Variable
    Bit rate : 3 333 Kbps
    Width : 1 280 pixels
    Height : 720 pixels
    Display aspect ratio : 16/9
    Frame rate mode : Variable
    Frame rate : 23.976 fps
    Minimum frame rate : 23.810 fps
    Maximum frame rate : 24.390 fps
    Resolution : 24 bits
    Colorimetry : 4:2:0
    Scan type : Progressive
    Bits/(Pixel*Frame) : 0.151
    Stream size : 501 MiB (95%)
    Writing library : x264 core 66 r1114 a933a3e
    Encoding settings : cabac=1 / ref=5 / deblock=1:-1:-1 / analyse=0x3:0x113 / me=umh / subme=7 / psy_rd=1.0:0.0 / mixed_ref=0 / me_range=16 / chroma_me=1 / trellis=1 / 8x8dct=1 / cqm=0 / deadzone=21,11 / chromaqpoffset=-2 / threads=6 / nr=0 / decimate=1 / mbaff=0 / bframes=3 / b_pyramid=1 / b_adapt=1 / b_bias=0 / direct=3 / wpredb=1 / keyint=250 / keyint_min=25 / scenecut=40(pre) / rc=2pass / bitrate=3333 / ratetol=1.0 / qcomp=0.60 / qpmin=10 / qpmax=51 / qpstep=4 / cplxblur=20.0 / qblur=0.5 / ip_ratio=1.40 / pb_ratio=1.30 / aq=1:1.10
    Language : English
    Encoded date : UTC 2009-08-19 08:38:03
    Tagged date : UTC 2009-08-19 08:38:35
    Audio
    ID : 2
    Format : AAC
    Format/Info : Advanced Audio Codec
    Format version : Version 4
    Format profile : LC
    Format settings, SBR : No
    Codec ID : 40
    Duration : 20mn 59s
    Bit rate mode : Constant
    Bit rate : 156 Kbps
    Nominal bit rate : 160 Kbps
    Channel(s) : 2 channels
    Channel positions : L R
    Sampling rate : 48.0 KHz
    Resolution : 16 bits
    Stream size : 23.4 MiB (4%)

  • When i try to play a youtube video it plays for only two seconds

    when i try to play a youtube video it plays for only two seconds with sound but the screen stays black. it takes a little more time for the video to load also. then it crashes which ever internet program i am using. But whenever i turn off my plug-ins it works totally fine. how do i fix this? this has never happened to me before. i tried to uninstall flash player and reinstall but it fixes nothing, this has been going on for two days now.
    i use safari and firefox and both dont work

    Click here and download Flash.
    (102455)

  • Safari stop playing embedded youtube videos

    Hi
    I am having trouble with Safari 4.0.5 (6531.22.7) which suddenly refuse to play embedded youtube videos. Safari show the video in a web page but when played the youtube default play display "an error occurred, please try again." and Safari display in the status bar "one error in opening the page, for more information, choose Window->Activity". Now when I look in the activity window it show "forbidden" beside the video file.
    Strangely I can play the same video from the youtube main page without any errors.
    I have already done the following:
    - checked permissions with Disk Utility.
    - Reset Safari
    - Empty caches
    - Removed com.apple.Safari.plist
    - Uninstalled, re-Installed Flash plug-in
    but the problem still persist. Help in resolving will be highly appreciated.

    HI and Welcome to Apple Discussions...
    YouTube streams content using the Flash plugin ... Flash Player support on 64-bit operating systems
    Since you are running Snow Leopard, *try running Safari is opening in 32-bit mode, not 64*. Right or control click the Safari icon in the Applications folder, then click: Get Info In the Get Info window click the black disclosure triangle next to General so it faces down. Select 32 bit mode. Also, (in that same window) *make sure Safari is NOT running in Rosetta.*
    

Web pages now include a small icon or 'favicon' which is visible in the address bar and next to bookmarks. These icons take up disk space and slow Safari down. It is possible to erase the icons from your computer and start fresh. *To delete Safari's icon cache using the Finder, open your user folder, navigate to ~/Library/Safari/ and move this file "webpageIcons.db to the Trash.*
    bpageIcons.db to the Trash.*
    Carolyn

  • Only safari adress bar visible after playing a youtube video.

    Only safari adress bar visible after playing a youtube video, rest of the screen is white, what can I do?

    If you are using Safari for Mac, it could be a Safari extension causing this.
    From the Safari menu bar click Safari / Preferences then select the Extensions tab.
    If you have any installed, turn that off, quit then relaunch Safari, try a video.
    It would really help when you post to tell us which operating system you are using, Mac or  Windows.
    You could also try troubleshooting the Flash plugin which is required for most of the content on YouTube.
    http://kb2.adobe.com/cps/865/cpsid_86551.html#ostype=m,prob1=fnctn,prob2=game,

  • Flash causes pc to freeze when playing 2 youtube videos or flash videos at the same time

    I dont know what has caused this issue but since around january my pc has been freezing to the point where i have to hard reset if i play 2 youtube videos or any flash videos at the same time. the whole pc becomes unresponsive when this happens. all my drivers are up to date so i dont know where this issue is coming from.
    My specs:
    Browser- Firefox 28.0
    OS: Windows 7 home edition 64 bit
    Case: Raidmax Platinum
    Motherboard:ASUS M5A99X EVO AM3
    CPU: AMD fx 8350 (4.6ghz oc)
    Cpu Cooler: ZALMAN CNPS10X Performa 120mm
    GPU: msi GTX 670 power edition
    power Supply: Kingwin Kx 1000w
    RAM:2x4gb(8gb) CORSAIR Vengeance240-Pin DDR3 SDRAM
    HDD: Western Digital Caviar Blue 500gb and 640gb
    Bluray: LG Bluray Drive & Burner

    There's two ways you can go about this Amanda.
    1. Set the length of your images for example 8 seconds each. Offset the photo's like a ladder effect and add the animating keyframes. The red dots in the image below represent the start/finish points of the animation.
    2. The other option is to set the length of all the same, then use keyframes to set the start/ finish of the animation.
    I always use example 1, however example 2 would probably be easier to understand?
    Hope that helps
    Tony

  • How to play a emded video using OSMF?

    Hi all,
    I want to play a emded video using OSMF, the as3 class would be something like this :(of course it does not work)
    [SWF(width = "356", height = "356", backgroundColor = "0x000000", frameRate = "12")]
        public class VideoPlayer4 extends Sprite {
            [Embed(source = '../../../../assets/video/TRAILOR 1280x720.mp4', mimeType = 'application/octet-stream')]
            public var vClass : Class;
            public function VideoPlayer4() {
                var mediaFactory:MediaFactory = new DefaultMediaFactory();
                var mediaElement:MediaElement = mediaFactory.createMediaElement(new vClass());
                mediaPlayer = new MediaPlayer();
                mediaPlayer.media = mediaElement;
                var mediaContainer:MediaContainer = new MediaContainer();
                mediaContainer.addMediaElement(mediaElement);
                mediaContainer.width = 356;
                mediaContainer.height = 356;
                addChild(mediaContainer);
    I have no idea how to do that, please give me some advice.
    Thanks!!

    Hi guys, good news!!
    I found a way to play embed flv using Flash Player 10.1, come & try yourself!!
    package
        import flash.display.Bitmap;
        import flash.display.Sprite;
        import flash.events.*;
        import flash.media.Video;
        import flash.net.NetConnection;
        import flash.net.NetStream;
        import flash.text.TextField;
        import flash.utils.ByteArray;
        public class VideoPlayer6 extends Sprite
           [Embed(source='../../../../assets/video/video.flv', mimeType='application/octet-stream')]
           private var flvClass:Class;
           private var flvData:ByteArray = new flvClass();
           private var connection:NetConnection;
           private var stream:NetStream;
           private var video:Video;
           public function VideoPlayer6()
              connection = new NetConnection();
              connection.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
              connection.addEventListener(SecurityErrorEvent.SECURITY_ERROR, securityErrorHandler);
              connection.connect(null);
           private function netStatusHandler(event:NetStatusEvent):void {
              switch (event.info.code) {
                 case "NetConnection.Connect.Success":
                    connectStream();
                    break;
                 case "NetStream.Play.StreamNotFound":
                    trace("NetStream.Play.StreamNotFound");
                    break;
           private function connectStream():void {
              stream = new NetStream(connection);
              stream.client = { onMetaData:function(obj:Object):void { } };
              stream.addEventListener(NetStatusEvent.NET_STATUS, netStatusHandler);
              stream.addEventListener(AsyncErrorEvent.ASYNC_ERROR, asyncErrorHandler);
              video = new Video();
              video.attachNetStream(stream);
              stream.play(null);
              stream.appendBytes( flvData as ByteArray );
              video.width = 356;
              video.height = 356;
              addChild(video);
           public function stop():void {
              if( video != null ) {
                 removeChild(video);
              if ( stream != null ) {
                 stream.close();
                 connection.close();
                 stream = null;
                 connection = null;
           private function securityErrorHandler(event:SecurityErrorEvent):void {
              trace("securityErrorHandler: " + event);
           private function asyncErrorHandler(event:AsyncErrorEvent):void {
               trace("asyncErrorHandler: " + event);

  • Firefox 3.6.3 wont play embedded youtube videos. It comes up with "an error occured please try again later. this happens all the time

    Firefox 3.6.3 wont play embedded youtube videos. It comes up with "an error occurred please try again later. this happens all the time. If you click to go to youtube the clip plays.
    == This happened ==
    Every time Firefox opened

    I was having the same issue up until I found a solution myself a few minutes ago. If you have "Accept Third Party Cookies" un-checked it will not allow the embedded "Third party" youtube videos to load. You can either Check the box to allow third party cookies or add an exception to allow youtube.com WITHOUT the www. You just want it to be Youtube.Com.
    To do so just go to Tools: Options: Privacy: Exceptions: Type in Youtube.com and click Allow. Then click Close and OK. It should start working immediately.

  • My macbook pro won't play any youtube video. I always get a plug-in failure message! How can I solve it? I already did all updates, reinstalled flash player but nothing helps!

    My macbook pro won't play any youtube video. I always get a plug-in failure message! How can I solve it? I already did all updates, reinstalled flash player but nothing helps!

    1. System Preferences > Other/ Flash Player > Advanced >  Delete  All
         Press the "Delete All" button
         Install Adobe Flash Player.
        http://get.adobe.com/flashplayer/
        Follow the prompts.
        Quit Safari.
        Restart computer. Relaunch Safari.
    2.  Allow  Plug-ins
        Safari > Preferences > Security
        Internet Plug-ins >  "Allow  plug-ins"
        Enable it.
        Press " Manage Website Settings" button for more options.

  • Hi. I just bought my very first mac. I cant get to see youtube videos using safari. it says to upgrade my flashplayer. do I have to download the flashplayer? doesnt safari has it installed?

    hi. I just bought my very first mac. I cant get to see youtube videos using safari. it says to upgrade my flashplayer. do I have to download the flashplayer?

    It's no longer pre-installed for a number of reasons. Not the least of which is Adobe Flash requires such frequent security updates that any version installed at the factory is pretty much garunteed to be dangerously out of date by the time you get the machine in your hands.
    Just go to adobe.com and download the latest version of flash player.

  • Unable to play youtube videos - using proxy (squid)

    Youtube videos do not play in my configuration. Most youtube content appears, but attempting to play a video results in a popup message "This movie could not be played". Sorry for the length of the post, but I'm trying to get enough documentation down here to save some time for the next person who runs into this.
    My basic network configuration is:
    ipod->wireless-router->squid-proxy->pix->internet
    *I am analyzing logfiles from the proxy and the pix, and I have network traces from the proxy.
    There are 2 issues so far with proxy access from the youtube application on the fw v2.2 ipod touch. After hitting the first issue, I made a call to tech support who pointed me to an older apple discussion thread about a similar issue which indicated the problem could be fixed by "reconfiguring the proxy server", but no details were given in that discussion thread about exactly what needed to be 'reconfigured'. I believe have figured out what was going wrong, and I document it as issue 1 below in case anyone else runs into it.
    Issue 1 (which I managed to get solved) is that the youtube application sends a 'Host:' header pointing to gdata.youtube.com, but the requested url is actually iphone-wu.apple.com. Squid rewrites the 'host' header to iphone-wu.apple.com, and the target server fails the request with a 404. A solution (for squid) is to use a redirector to rewrite these url's to actually go to gdata.youtube.com and to set the 'urlrewrite_hostheader off' value.
    Unfortunately, resolving issue #1 was not sufficient to get youtube off the launch pad:
    Issue 2 (which seems unsolveable at the moment) is that the youtube application is ignoring proxy settings for some of its content requests. In addition to the proxy requirement, I have egress firewalling and logging set up. I observe the youtube application asking for many url's via the proxy and then I observe the egress firewall deny an attempt at a direct access to port 80 on an external server BYPASSING the proxy settings. Without opening up the egress firewall rules (and thereby disable requirement for a proxy), this makes the youtube application inoperative.
    If anyone has some insight on how I can get this working, I'd appreciate it. I will attempt another support call tomorrow with my logfiles in hand...

    Thanks for posting! -- I'm glad the info is helpful to you. There is more that I have been deliberately keeping quiet about while trying to work through a support call that was logged 27-dec-08. Without going into a lot of detail, the support call is still open, and I'm still working on getting a resolution from apple engineering. I hope that by providing this information, my support call doesn't get terminated as having been "solved" - which it most definitely has not been. It is my belief that only a firmware update will fix this.
    (And as an aside ... I've spoken with three or four support reps at apple, and all have been very nice and have tried to help out! I've been quite pleased with the front end to their support org. I just really want to hear that someone has LOOKED at the code and found the error and it will be fixed in a future update!)
    A work-around for the youtube and itunes applet failures is to set your squid up as a transparent proxy. That way, the network accesses that these applets make that attempt to bypass the proxy are hidden and the applets "work".
    I would most certainly appreciate any further corroboration of this misbehavior -- more than one site being able to demonstrate these applets bypassing the proxy would be quite helpful.
    (Note also that the lastest firmware 2.2.1 also exhibits this issue)
    Thanks.

  • Problem in Playing YouTube Videos using Safari. It says "500 Internal Server Error" every time I am going to play video?

    Is there anybody who can help me fix this issue?  I encountered this problem for almost to weeks now.  I can't play video on You Tube using Safari browser for my MacBook Pro. Every time I tried to play video on You Tube.  It shows
    "500 Internal Server Error" 
    Sorry, something went wrong.
    A team of highly trained monkeys has been dispatched to deal with this situation. (Followed by codes)
    When I checked my other computer using Google Chrome and Firefox browser.  There is no problem in playing You Tube videos.

    From the Safari menu bar, select
    Safari ▹ Preferences... ▹ Privacy ▹ Remove All Website Data
    and confirm. Test.

  • When I play a youtube video in one tab, then scroll up and down in any tab, the audio from the youtube video gets choppy and cuts out for a second. How to fix?

    I just want to be able to go on other websites and scroll while playing music (smoothly) on youtube in another tab.
    I don't think this happened until after I updated my firefox to 13 and my shockwave flash plug-in to 11.3.300.257
    How can I fix this cutting out and choppy-ness in youtube videos when I scroll?
    Thanks so much!

    Try to disable hardware acceleration.
    *Tools > Options > Advanced > General > Browsing: "Use hardware acceleration when available"
    *https://support.mozilla.org/kb/how-do-i-upgrade-my-graphics-drivers
    Try to "disable the hardware acceleration" in the Flash Player.
    *http://helpx.adobe.com/flash-player/kb/video-playback-issues.html
    See also:
    * https://support.mozilla.org/kb/Cannot+view+full+screen+Flash+videos
    Flash "Display settings" window:
    * http://www.macromedia.com/support/documentation/en/flashplayer/help/help01.html

Maybe you are looking for

  • ORA-326/ORA-334 Physical Standby DB - Not applying logs

    Hi, all, I have a Dataguard, the primary db is a RAC with three nodes, the standby db is a physical standby. the dataguard are all oracle 10.2.0.3 on solaris 9 sparc system Now, my standby db did not apply the archivelogs,there are some errors in sta

  • Flash Builder 4 Beta RDS issue

    I cannot connect to ColdFusion via RDS with my Flash Builder 4 beta 2. I have no issue connecting to CF via RDS in dreamweaver CS3. However whenever I try to connect to a CFC via "connect to DataService" and I get "Enter RDS password and user name"..

  • Oracle SQL developer tool vs toad

    Hi - I am trying to do a feature comparison on these 2 tools and am not very familiar with them could someone please tell me if Oracle SQL developer tool has these features: Project Manager Result Set Compare Chart Designer Toad Report Wizard Pivot &

  • Newly installed Photoshop Elements 3 not launching - help!

    Hi there, just installed Photoshop Elements 3 on the new G5 iMac - both bought a couple of weeks ago from Apple store on-line. Installation of PE3 seemed to go ok. But double-clicking the application makes it blink a couple of times in the dock, and

  • Export dump

    what is maximum size of export data dump on linux, windows,unix; please reply thanks all