Results 1 to 4 of 4
  1. #1
    avalancha is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default (Youtube-) Video in a Swing GUI

    Hey everyone,

    I'm currently trying to get a video playable in my Swing GUI but I just can't seem to do it, I really need your help please.
    With google and the JMF I got this far:
    Java Code:
    import java.awt.BorderLayout;
    import java.awt.Component;
    import java.io.IOException;
    import java.net.MalformedURLException;
    import java.net.URL;
    import javax.media.CannotRealizeException;
    import javax.media.Manager;
    import javax.media.NoPlayerException;
    import javax.media.Player;
    import javax.swing.JFrame;
     
    public class MediaPanel extends JFrame {
     
        public MediaPanel() {
            setLayout(new BorderLayout()); // use a BorderLayout
     
            // Use lightweight components for Swing compatibility
            Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
            
            URL mediaURL = null;
            
            try {
                mediaURL = new URL("http://www.youtube.com/watch?v=Q7_Z_mQUBa8");
            } catch (MalformedURLException ex) {
                System.err.println(ex);
            }
            try {
                // create a player to play the media specified in the URL
                Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
     
                // get the components for the video and the playback controls
                Component video = mediaPlayer.getVisualComponent();
                Component controls = mediaPlayer.getControlPanelComponent();
     
                if (video != null) {
                    add(video, BorderLayout.CENTER); // add video component
                }
                if (controls != null) {
                    add(controls, BorderLayout.SOUTH); // add controls
                }
                mediaPlayer.start(); // start playing the media clip
            } // end try
            catch (NoPlayerException noPlayerException) {
                System.err.println("No media player found");
            } // end catch
            catch (CannotRealizeException cannotRealizeException) {
                System.err.println("Could not realize media player");
            } // end catch
            catch (IOException iOException) {
                System.err.println("Error reading from the source");
            } // end catch
        } // end MediaPanel constructor
    }
    But all I get when I run this is
    Java Code:
    Warning: The URL may not exist. Please check URL
    No media player found
    I have really spent a lot of time playing around with this, other links, other formats, other code, but this is the farthest I got and I need a couple of trained eyes to look at this I guess...

    Any advice is greatly appreciated!

    Best regards,
    Patrick

  2. #2
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: (Youtube-) Video in a Swing GUI

    You should add a call to the printStackTrace() method in the catch blocks for better error information.
    If you don't understand my response, don't ignore it, ask a question.

  3. #3
    avalancha is offline Member
    Join Date
    Aug 2012
    Posts
    2
    Rep Power
    0

    Default Re: (Youtube-) Video in a Swing GUI

    Quote Originally Posted by Norm View Post
    You should add a call to the printStackTrace() method in the catch blocks for better error information.
    Well the underlaying problem here is - I think - that it doesn't even go into one of my catch blocks!
    I have tried this out with a couple more "System.out.println("I'm here");
    Java Code:
    Warning: The URL may not exist. Please check URL
    is not triggered by one of those

    Where would you place the calls?

  4. #4
    Norm's Avatar
    Norm is online now Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,421
    Rep Power
    25

    Default Re: (Youtube-) Video in a Swing GUI

    Where would you place the calls?
    in the catch blocks
    If you don't understand my response, don't ignore it, ask a question.

Similar Threads

  1. YouTube Direct and Video IDs
    By LaPasticca in forum Web Frameworks
    Replies: 2
    Last Post: 02-25-2012, 02:42 PM
  2. Program for download video from Youtube.
    By check_check in forum Networking
    Replies: 2
    Last Post: 08-20-2011, 06:41 PM
  3. tomcat embedded youtube video
    By crank6015 in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 06-04-2011, 01:30 AM
  4. youtube Video downloads
    By Gloomy in forum New To Java
    Replies: 2
    Last Post: 09-06-2010, 05:40 AM
  5. download youtube video
    By lalit.wientech in forum Networking
    Replies: 11
    Last Post: 03-24-2010, 04:30 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •