Advertisement
Guest User

mediaTest

a guest
Aug 24th, 2012
211
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.95 KB | None | 0 0
  1. import java.awt.BorderLayout;
  2. import java.awt.Component;
  3. import java.io.IOException;
  4. import java.net.MalformedURLException;
  5. import java.net.URL;
  6. import javax.media.CannotRealizeException;
  7. import javax.media.Manager;
  8. import javax.media.NoPlayerException;
  9. import javax.media.Player;
  10. import javax.swing.JFrame;
  11.  
  12. public class MediaPanel extends JFrame {
  13.  
  14.     public MediaPanel() {
  15.         setLayout(new BorderLayout()); // use a BorderLayout
  16.  
  17.         // Use lightweight components for Swing compatibility
  18.         Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);
  19.        
  20.         URL mediaURL = null;
  21.        
  22.         try {
  23.             mediaURL = new URL("http://www.youtube.com/watch?v=Q7_Z_mQUBa8");
  24.         } catch (MalformedURLException ex) {
  25.             System.err.println(ex);
  26.         }
  27.         try {
  28.             // create a player to play the media specified in the URL
  29.             Player mediaPlayer = Manager.createRealizedPlayer(mediaURL);
  30.  
  31.             // get the components for the video and the playback controls
  32.             Component video = mediaPlayer.getVisualComponent();
  33.             Component controls = mediaPlayer.getControlPanelComponent();
  34.  
  35.             if (video != null) {
  36.                 add(video, BorderLayout.CENTER); // add video component
  37.             }
  38.             if (controls != null) {
  39.                 add(controls, BorderLayout.SOUTH); // add controls
  40.             }
  41.             mediaPlayer.start(); // start playing the media clip
  42.         } // end try
  43.         catch (NoPlayerException noPlayerException) {
  44.             System.err.println("No media player found");
  45.         } // end catch
  46.         catch (CannotRealizeException cannotRealizeException) {
  47.             System.err.println("Could not realize media player");
  48.         } // end catch
  49.         catch (IOException iOException) {
  50.             System.err.println("Error reading from the source");
  51.         } // end catch
  52.     } // end MediaPanel constructor
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement