예제 #1
0
  public void actionPerformed(ActionEvent ae) {

    if (ae.getSource() == stopButton) {
      if (player != null) {
        player.stop(); // NOTE: stop() is a synchronous method !
      }
    } else {
      player.stop(); // NOTE: stop() is a synchronous method !
      player.close();
      // waitForState(player.Closed);
      System.out.print("Player Closed - Exiting");
      System.exit(0);
    }
  }
 // Stops the music from playing
 public void pause() {
   try {
     player.stop();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
예제 #3
0
  public static void stop() {
    try {

      Thread.sleep(5000);
      FrameGrabbingControl fgc =
          (FrameGrabbingControl) player.getControl("javax.media.control.FrameGrabbingControl");

      Buffer buf = fgc.grabFrame();

      BufferToImage btoi = new BufferToImage((VideoFormat) buf.getFormat());
      player.stop();
      Image img = btoi.createImage(buf);

      int w = img.getWidth(null);

      int h = img.getHeight(null);

      BufferedImage bi = new BufferedImage(w, h, BufferedImage.TYPE_INT_RGB);

      Graphics2D g2 = bi.createGraphics();

      g2.drawImage(img, 0, 0, null);

      g2.dispose();
      try {
        ImageIO.write(bi, "jpg", new File("C:/ii.jpg"));

      } catch (IOException ex) {
        Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex);
      }
    } catch (InterruptedException ex) {
      Logger.getLogger(Capture_video.class.getName()).log(Level.SEVERE, null, ex);
    }
  }
  /** 初始化播放器 */
  public void initPlayer() {

    try {
      if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.close();
        mediaPlayer = null;
      }
      if (lrcThread != null) {
        lrcThread = null;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #5
0
  public Webcam(Player _player) {
    f = new Frame("SwingCapture");

    setLayout(new BorderLayout());
    setSize(640, 480);
    this.player = _player;
    Component comp;

    try {
      if ((comp = player.getVisualComponent()) != null) {
        add(comp, BorderLayout.CENTER);
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    f.addWindowListener(
        new WindowAdapter() {
          public void windowClosing(WindowEvent e) {
            f.dispose();
            // playerclose();
            // System.exit(0);
          }
        });

    f.add("Center", this);
    f.pack();
    f.setSize(new Dimension(640, 480));
    f.setVisible(true);

    FormatControl formatControl =
        (FormatControl) player.getControl("javax.media.control.FormatControl");
    // player.stop();
    Component co = formatControl.getControlComponent();
    if (co != null) {
      player.stop();
      JDialog d = new JDialog(f, "Format Control", true);
      f.add(co);
      f.pack();
      f.setLocationRelativeTo(f);
      f.setVisible(true);
      f.dispose();
      player.start();
    }
  }
  /** 初始化播放器 */
  private void initMusic() {
    try {
      if (mediaPlayer != null) {
        mediaPlayer.stop();
        mediaPlayer.close();
        mediaPlayer = null;

        SongMessage msg = new SongMessage();
        msg.setSongInfo(songInfo);
        msg.setType(SongMessage.SERVICEPAUSEEDMUSIC);
        ObserverManage.getObserver().setMessage(msg);
      }
      if (lrcThread != null) {
        lrcThread = null;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  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();
    }
  }
 // Stops the track, resets it to the beginning
 public void rewind() {
   player.stop();
   player.setMediaTime(Player.RESET);
 }
예제 #9
0
  public void actionPerformed(ActionEvent e) {

    if (e.getSource() == play_time) {
      dure.setText(toString(lecteur.getMediaTime()) + " - " + toString(lecteur.getDuration()));

      deplacement.setValue(
          (int) (lecteur.getMediaTime().getSeconds() / lecteur.getDuration().getSeconds() * 100));

      if (lecteur.getMediaTime().getSeconds() == lecteur.getDuration().getSeconds()) {
        lecteur.stop();
        lecteur.close();
        lecteur = null;

        deplacement.setValue(0);
        dure.setText("00:00 - " + toString(lecteur.getDuration()));
        play_time.stop();
      }
    }

    if (e.getSource() == open) {
      fc = new JFileChooser();
      fc.setAcceptAllFileFilterUsed(false);
      fc.showOpenDialog(this);

      if (fc.getDialogType() == JFileChooser.APPROVE_OPTION) {
        fichier = fc.getSelectedFile();
        name.setText(fichier.getName().substring(0, (int) fichier.getName().length() - 4));
      }
    }

    if (e.getSource() == play) {
      try {
        if (fichier != null) {
          if (lecteur == null) {
            lecteur = Manager.createPlayer(fichier.toURL());
            lecteur.start();
            play_time.start();
          }

          if (enPause == true) {
            lecteur.start();
            play_time.start();
            enPause = false;
          }
        }
      } catch (Exception ex) {
        ex.printStackTrace();
      }
    }

    if (e.getSource() == pause) {
      if (enPause == false && lecteur != null) {
        lecteur.stop();
        play_time.stop();
        enPause = true;
      }
    }

    if (e.getSource() == stop) {
      if (enPause == false && lecteur != null) {
        lecteur.stop();
        lecteur.close();
        lecteur = null;

        play_time.stop();
        dure.setText("00:00 - 00:00");
        deplacement.setValue(0);
      }
    }
  }
예제 #10
0
 public static void stop2() {
   instance.setsStates(SunoneStates.IN_STOP);
   PLAYSTATUS = NEXTWASSTOP;
   player.stop();
   GUI.getInstance().reinitialiseComposantsLecteur();
 }