예제 #1
0
  public VideoPlay(URL mediaURL) {
    setLayout(new BorderLayout()); // use a BorderLayout

    // Use lightweight components for Swing compatibility
    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

    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
  // Load decodes the track and creates a Realized Player
  public void load(String filename) {
    Decoder p1 = new Decoder();
    try {
      p1.decode(filename, track.getPath());
      player = Manager.createRealizedPlayer(track.toURL());

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #3
0
  public JMFSound(File f)
      throws NoPlayerException, CannotRealizeException, MalformedURLException, IOException {
    soundFile = f;
    // prepare a dialog to display while playing
    JOptionPane pane = new JOptionPane("Playing " + f.getName(), JOptionPane.PLAIN_MESSAGE);
    playingDialog = pane.createDialog(null, "JMF Sound");
    playingDialog.pack();

    // get a player
    MediaLocator mediaLocator = new MediaLocator(soundFile.toURL());
    Player player = Manager.createRealizedPlayer(mediaLocator);
    player.addControllerListener(this);
    player.start();
    playingDialog.setVisible(true);
  }
  public static void main(String args[]) throws Exception {

    // Take the path of the audio file from command line

    File f = new File("C:\\Users\\Larry\\AppData\\Local\\Temp\\jgoogle_tts-588881786930740869.mp3");
    // Create a Player object that realizes the audio
    final Player p = Manager.createRealizedPlayer(f.toURI().toURL());
    // Start the music
    p.start();
    // Create a Scanner object for taking input from cmd
    Scanner s = new Scanner(System.in);

    // Read a line and store it in st

    String st = s.nextLine();

    // If user types 's', stop the audio

    if (st.equals("s")) {

      p.stop();
    }
  }
  public WebcamCaptureAndFadePanel(String saveDir, String layout) {

    System.out.println("Using " + saveDir + " as directory for the images.");
    saveDirectory = saveDir;

    getImages();
    images_used = new ArrayList<Integer>();
    images_lastadded = new ArrayList<Integer>();
    images_nevershown = new ArrayList<Integer>();

    Vector devices = (Vector) CaptureDeviceManager.getDeviceList(null).clone();
    Enumeration enumeration = devices.elements();
    System.out.println("- Available cameras -");
    ArrayList<String> names = new ArrayList<String>();
    while (enumeration.hasMoreElements()) {
      CaptureDeviceInfo cdi = (CaptureDeviceInfo) enumeration.nextElement();
      String name = cdi.getName();
      if (name.startsWith("vfw:")) {
        names.add(name);
        System.out.println(name);
      }
    }

    // String str1 = "vfw:Logitech USB Video Camera:0";
    // String str2 = "vfw:Microsoft WDM Image Capture (Win32):0";
    if (names.size() == 0) {
      JOptionPane.showMessageDialog(
          null,
          "Ingen kamera funnet. " + "Du må koble til et kamera for å kjøre programmet.",
          "Feil",
          JOptionPane.ERROR_MESSAGE);
      System.exit(0);
    } else if (names.size() > 1) {

      JOptionPane.showMessageDialog(
          null,
          "Fant mer enn 1 kamera. " + "Velger da:\n" + names.get(0),
          "Advarsel",
          JOptionPane.WARNING_MESSAGE);
    }

    String str2 = names.get(0);
    di = CaptureDeviceManager.getDevice(str2);
    ml = di.getLocator();

    try {
      player = Manager.createRealizedPlayer(ml);
      formatControl = (FormatControl) player.getControl("javax.media.control.FormatControl");

      /*
      Format[] formats = formatControl.getSupportedFormats();
      for (int i=0; i<formats.length; i++)
      	System.out.println(formats[i].toString());
      */

      player.start();
    } catch (javax.media.NoPlayerException e) {
      JOptionPane.showMessageDialog(
          null,
          "Klarer ikke å starte" + " programmet pga. feil med kamera. Sjekk at det er koblet til.",
          "IOException",
          JOptionPane.ERROR_MESSAGE);
      System.exit(0);
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(0);
    }

    /*
     * Layout
     *
     * Add
     * - comp
     * - imagepanels
     */

    if (layout.equals("1024v2")) {
      layout1024v2();
    } else if (layout.equals("1280")) {
      layout1280();
    } else {
      layout1024();
    }

    // Capture Window
    if (captureWindow) {
      cw = new JFrame("Capture from webcam");
      cw.setAlwaysOnTop(true);
      cw.setSize(sizeCaptureWindow_x, sizeCaptureWindow_y);
      cw.addKeyListener(new captureWindowKeyListner());
      cw.setUndecorated(true);

      // Add webcam
      if ((comp = player.getVisualComponent()) != null) {
        cw.add(comp);
      }

      // Add panel to window and set location of window
      cw.setLocation(cwLocation_x, cwLocation_y);
    }

    // Text window
    cwText = new rotatedText("");

    /*
     * Timer for update
     */
    Timer thread = new Timer();
    thread.schedule(new frameUpdateTask(), 0, (1000 / fps));
  }