예제 #1
0
  /** Crea Ftes new form PanelFilm */
  public PanelFilm(URL mediaUrl) throws IOException {
    initComponents();
    setLayout(new BorderLayout());
    Manager.setHint(Manager.LIGHTWEIGHT_RENDERER, true);

    drawFilm = new JPanel();

    try {

      mediaPlayer = Manager.createRealizedPlayer(mediaUrl);
      System.out.println(Manager.createRealizedPlayer(mediaUrl).toString());
      video = mediaPlayer.getVisualComponent();
      System.out.println(mediaPlayer.getVisualComponent());
      controls = mediaPlayer.getControlPanelComponent();

      if (video != null) {
        drawFilm.add(video, BorderLayout.CENTER);
      }

      if (controls != null) {
        drawFilm.add(controls, BorderLayout.SOUTH);
      }
      this.setVisible(false);
      drawFilm.setVisible(true);

      mediaPlayer.start();

    } catch (NoPlayerException noPlayerException) {
      noPlayerException.printStackTrace();
    } catch (CannotRealizeException cannotRealizeException) {
      cannotRealizeException.printStackTrace();
    }
  }
예제 #2
0
  public MediaPanel(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
예제 #3
0
  // Constructor
  public MediaPlayer(URL mediauUrl) {

    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(mediauUrl);

      // get the components for the video and the playback controls
      Component video = mediaPlayer.getVisualComponent();
      Component control = mediaPlayer.getControlPanelComponent();

      if (video != null) {
        add(video, BorderLayout.CENTER); // place the video component in the panel
      }

      if (control != null) {
        add(control, BorderLayout.SOUTH); // place the control component in  the panel
      }
      mediaPlayer.start(); // start playing the media clip
    } catch (NoPlayerException noPlayerException) {
      System.err.println("No media player found: " + noPlayerException);
    } catch (CannotRealizeException cannotRealizeException) {
      System.err.println("Could not realize media player: " + cannotRealizeException);
    } catch (IOException iOException) {
      System.err.println("Error reading from the source: " + iOException);
    }
  }
  // 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();
    }
  }
예제 #5
0
  public Capture_video() {
    try {
      // List out available Devices to Capture Video.
      Vector<CaptureDeviceInfo> list = CaptureDeviceManager.getDeviceList(format);
      System.out.println(CaptureDeviceManager.getDeviceList(null).toString());

      // Iterating list
      for (CaptureDeviceInfo temp : list) {
        // Checking whether the current device supports VfW
        // VfW = Video for Windows
        if (temp.getName().startsWith("vfw:")) {

          System.out.println("Found : " + temp.getName().substring(4));
          // Selecting the very first device that supports VfW
          cam = temp;
          System.out.println("Selected : " + cam.getName().substring(4));
          break;
        }
      }

      System.out.println("Put it on work!...");
      // Getting the MediaLocator for Selected device.
      // MediaLocator describes the location of media content
      locator = cam.getLocator();

      if (locator != null) {

        // Create a Player for Media Located by MediaLocator
        player = Manager.createRealizedPlayer(locator);

        if (player != null) {

          // Starting the player
          player.start();

          // Creating a Frame to display Video

          f.setTitle("Test Webcam");
          f.setLayout(new BorderLayout());
          // Adding the Visual Component to display Video captured by Player
          // from URL provided by MediaLocator
          f.add(player.getVisualComponent(), BorderLayout.CENTER);
          f.pack();
          f.setAlwaysOnTop(true);
          f.setVisible(true);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
  }
예제 #6
0
  private void initWebcam() {
    Vector videoDevices = CaptureDeviceManager.getDeviceList(new VideoFormat(null));
    if (videoDevices.size() > 0) {
      webcam = (CaptureDeviceInfo) videoDevices.get(0);
      Format[] formats = webcam.getFormats();
      Format selectedFormat = null;

      try {
        for (Format f : formats) {
          if (f.toString().contains("640") && f.toString().contains("480")) {
            selectedFormat = f;
            break;
          }
        }
      } catch (Exception e) {
        logger.error(
            "Failed to get required webcam resolution (640x480). Taking default format: "
                + e.getMessage());
        selectedFormat = formats[0];
      }

      try {
        webcamPlayer = Manager.createRealizedPlayer(webcam.getLocator());

        FormatControl fc =
            (FormatControl) webcamPlayer.getControl("javax.media.control.FormatControl");
        System.out.println("Selected webcam format: " + selectedFormat.toString());
        fc.setFormat(selectedFormat);

        webcamPlayer.start();

        webcamAvailable = true;

        Timer timer = new Timer();
        timer.schedule(
            new TimerTask() {
              @Override
              public void run() {
                frameGrabber =
                    (FrameGrabbingControl)
                        webcamPlayer.getControl("javax.media.control.FrameGrabbingControl");
              }
            },
            2500);
      } catch (Exception e) {
        logger.error("Failed to get webcam feed: " + e.getMessage());
      }
    } else {
      logger.error("No webcam available");
    }
  }
  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();
    }
  }
  /**
   * 播放歌曲
   *
   * @param songInfo
   */
  private void playInfoMusic(SongInfo msongInfo) {
    this.songInfo = msongInfo;
    if (songInfo == null) {

      SongMessage msg = new SongMessage();
      msg.setType(SongMessage.SERVICEERRORMUSIC);
      msg.setErrorMessage(SongMessage.ERRORMESSAGEPLAYSONGNULL);
      ObserverManage.getObserver().setMessage(msg);

      return;
    }
    File songFile = new File(songInfo.getFilePath());

    if (!songFile.exists()) {
      logger.error("播放文件不存在!");
      // 下一首
      SongMessage songMessage = new SongMessage();
      songMessage.setType(SongMessage.NEXTMUSIC);
      ObserverManage.getObserver().setMessage(songMessage);

      return;
    }

    try {
      if (mediaPlayer == null) {
        // mediaPlayer = new MediaPlayer();
        // // mediaPlayer.setDataSource(songInfo.getFilePath());
        // //
        // // float playedRate = (float) songInfo.getPlayProgress()
        // // / songInfo.getDuration();
        // // mediaPlayer.seekTo(playedRate);
        // mediaPlayer.setMediaLocator(new MediaLocator(songInfo
        // .getFilePath()));
        File file = new File(songInfo.getFilePath());
        mediaPlayer = Manager.createRealizedPlayer(new MediaLocator(file.toURL()));

        initVolume();

        mediaPlayer.prefetch(); // 获取媒体数据

        double totalTime = mediaPlayer.getDuration().getSeconds();
        double rate = songInfo.getPlayProgress() * 1.00 / songInfo.getDuration();
        mediaPlayer.setMediaTime(new Time(totalTime * rate));
        mediaPlayer.prefetch();
        mediaPlayer.start();
      }
    } catch (Exception e) {
      logger.error("不能播放此文件:" + songInfo.getFilePath());
      e.printStackTrace();

      SongMessage songMessage = new SongMessage();
      songMessage.setType(SongMessage.NEXTMUSIC);
      ObserverManage.getObserver().setMessage(songMessage);
    }
    if (mediaPlayer != null) {
      mediaPlayer.addControllerListener(
          new ControllerListener() {

            @Override
            public void controllerUpdate(ControllerEvent e) {
              // 当媒体播放结束时
              if (e instanceof EndOfMediaEvent) {
                mediaPlayer.setMediaTime(new Time(0));
                mediaPlayer = null;
                SongMessage songMessage = new SongMessage();
                songMessage.setType(SongMessage.NEXTMUSIC);
                ObserverManage.getObserver().setMessage(songMessage);
              }
            }
          });
      // mediaPlayer.setOnCompletionListener(new OnCompletionListener() {
      //
      // @Override
      // public void onProgressChanged() {
      //
      // float playedRate = mediaPlayer.getPlayedRate();
      //
      // long playProgress = (long) (songInfo.getDuration() * playedRate);
      //
      // if (songInfo != null) {
      // songInfo.setPlayProgress(playProgress);
      // SongMessage msg = new SongMessage();
      // msg.setSongInfo(songInfo);
      // msg.setType(SongMessage.SERVICEPLAYINGMUSIC);
      // ObserverManage.getObserver().setMessage(msg);
      // }
      // }
      //
      // @Override
      // public void onCompletion() {
      //
      // SongMessage songMessage = new SongMessage();
      // songMessage.setType(SongMessage.NEXTMUSIC);
      // ObserverManage.getObserver().setMessage(songMessage);
      // }
      // });
    }

    if (lrcThread == null) {
      lrcThread = new Thread(new LrcRunable());
      lrcThread.start();
    }
  }
  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));
  }