📄 jmfmediaplayer.java
字号:
} /** * Gets the ratio between width and height of the video image * * @return DOCUMENT ME! */ public float getAspectRatio() { if (player == null) { return 0; } float aspectRatio = (float) (getVisualComponent().getPreferredSize() .getWidth() / getVisualComponent() .getPreferredSize() .getHeight()); return aspectRatio; } /** * Starts the Player as soon as possible. is not synchronized in JMF */ public synchronized void start() { if ((player == null) || (getState() == javax.media.Controller.Started)) { return; } // do not try to start at the end of the media, the JMF player blocks // start playing at the beginning of the media data if ((getMediaDuration() - getMediaTime()) < 40) { setMediaTime(0); } // tell JMF to start the player player.start(); // wait for the player to be in the started state while (getState() != javax.media.Controller.Started) { try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } // make sure all managed controllers are started startControllers(); } /** * Stop the media player */ public synchronized void stop() { if (player == null) { return; } // only freeze media time if it is not frozen yet if (frozenMediaTime < 0) { frozenMediaTime = getMediaTime(); } // make sure all managed controllers are stopped stopControllers(); // tell JMF to stop the player player.stop(); // wait for the player to stop while (player.getState() == javax.media.Controller.Started) { try { Thread.sleep(50); } catch (InterruptedException e) { e.printStackTrace(); } } // make sure that all interval playing is finished if (playingInterval) { stopPlayingInterval(); } // make sure the player is at the correct time after this stop setMediaTime(frozenMediaTime); // undefine the freeze time frozenMediaTime = -1; // the following code is needed because JMF sometimes forgets its player rate // First an other rate than the current (shouldBe) rate must be set because // the JMF player thinks it is playing at the shouldBeRate and ignores calls // to setRate for the rate value it thinks it is playing at. player.setRate(0.995f * shouldBeRate); player.setRate(shouldBeRate); } /** * Tell if this player is playing * * @return DOCUMENT ME! */ public boolean isPlaying() { if (player == null) { return false; } return getState() == javax.media.Controller.Started; } /** * DOCUMENT ME! * * @return the step size for one frame */ public long getMilliSecondsPerSample() { return milliSecondsPerSample; } /** * DOCUMENT ME! * * @param milliSeconds the step size for one frame */ public void setMilliSecondsPerSample(long milliSeconds) { milliSecondsPerSample = milliSeconds; } /** * Return the players state * * @return DOCUMENT ME! */ private int getState() { if (player == null) { return javax.media.Controller.Prefetched; } return player.getState(); } /** * Gets the volume as a number between 0 and 1 * * @return DOCUMENT ME! */ public float getVolume() { if (player.getGainControl() == null) { return 0; } return player.getGainControl().getLevel(); } /** * Gets the volume as a number between 0 and 1 * * @param level DOCUMENT ME! */ public void setVolume(float level) { if (player.getGainControl() == null) { return; } player.getGainControl().setLevel(level); } /** * Set the offset to be used in get and set media time for this player * * @param offset the offset in milli seconds */ public void setOffset(long offset) { this.offset = offset; mediaDescriptor.timeOrigin = offset; } /** * DOCUMENT ME! * * @return the offset used by this player */ public long getOffset() { return offset; } /** * Sets the Clock's media time in milli seconds. is not synchronized in JMF * * @param time DOCUMENT ME! */ public synchronized void setMediaTime(long time) { if (player == null) { return; } // do not set media time on a started player if (isPlaying()) { stop(); } time = time + offset; player.setMediaTime(new Time(time * 1000000)); // set the media time for the connected controllers setControllersMediaTime(time - offset); } /** * DOCUMENT ME! */ public void nextFrame() { setMediaTime(getMediaTime() + getMilliSecondsPerSample()); } /** * DOCUMENT ME! */ public void previousFrame() { setMediaTime(getMediaTime() - getMilliSecondsPerSample()); } /** * Gets this Clock's current media time in milli seconds. * * @return DOCUMENT ME! */ public long getMediaTime() { if (player == null) { return 0; } // return frozen media time if it is set if (frozenMediaTime >= 0) { return frozenMediaTime; } return (long) (1000 * player.getMediaTime().getSeconds()) - offset; } /** * Gets the current temporal scale factor. * * @return DOCUMENT ME! */ public float getRate() { if (player == null) { return 0; } return player.getRate(); } /** * Sets the temporal scale factor. * * @param rate DOCUMENT ME! */ public synchronized void setRate(float rate) { if (player == null) { return; } // do not set rate on a started player if (isPlaying()) { stop(); } // set the rate for the connected controllers setControllersRate(rate); shouldBeRate = rate; player.setRate(rate); } /** * The encoded frame duration is not (yet?) detected by JMF, or it is not yet implemented * in this player. * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#isFrameRateAutoDetected() */ public boolean isFrameRateAutoDetected() { return false; } /** * Get the duration of the media represented by this object in milli * seconds. * * @return DOCUMENT ME! */ public long getMediaDuration() { if (player == null) { return 0; } return (long) (1000 * player.getDuration().getSeconds()) - offset; } /** * DOCUMENT ME! * * @param layoutManager DOCUMENT ME! */ public void setLayoutManager(ElanLayoutManager layoutManager) { if (this.layoutManager == null) { detachItem = new JMenuItem(ElanLocale.getString("Detachable.detach")); detachItem.addActionListener(this); popup.insert(detachItem, 0); } this.layoutManager = layoutManager; } /** * DOCUMENT ME! */ public void updateLocale() { infoItem.setText(ElanLocale.getString("Player.Info")); durationItem.setText(ElanLocale.getString("Player.duration") + ": " + TimeFormatter.toString(getMediaDuration())); if (detachItem != null) { if (detached) { detachItem.setText(ElanLocale.getString("Detachable.attach")); } else { detachItem.setText(ElanLocale.getString("Detachable.detach")); } } } /* * */ public void actionPerformed(ActionEvent e) { if (e.getSource().equals(detachItem) && (layoutManager != null)) { if (detached) { layoutManager.attach(JMFMediaPlayer.this.getVisualComponent()); detachItem.setText(ElanLocale.getString("Detachable.detach")); detached = false; } else { layoutManager.detach(JMFMediaPlayer.this.getVisualComponent()); detachItem.setText(ElanLocale.getString("Detachable.attach")); detached = true; } } else if (e.getSource() == infoItem) { new FormattedMessageDlg(this); } } /** * DOCUMENT ME! * * @param player DOCUMENT ME! */ void printControls(Player player) { System.out.println("Player info: " + player); Control[] controls = player.getControls(); for (int i = 0; i < controls.length; i++) { System.out.print("\t" + i + ": "); System.out.println(controls[i].getClass()); /* if (controls[i] instanceof FormatControl) { FormatControl fc = (FormatControl) controls[i]; System.out.println("\tFormatcontrol format: " + fc.getFormat()); System.out.println("\tControl Component: " + fc.getControlComponent()); } if (controls[i] instanceof FrameGrabbingControl) { System.out.println("\t - is framgrabbing control"); } if (controls[i] instanceof FramePositioningControl) { System.out.println("\t - is framepositioning control"); }*/ } } /** * DOCUMENT ME! */ public void cleanUpOnClose() { } // Code coppied from Greg's version of JMFVideoPlayer // ALex heeft deze code verbeterd in de client/util package, die code gaan gebruiken zodra de nieywe package structuur er is /** * DOCUMENT ME! * $Id: JMFMediaPlayer.java,v 1.8 2007/01/15 08:20:53 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.8 $ */ private class NoMouseComponent extends java.awt.Container { /** * DOCUMENT ME! * * @param ml DOCUMENT ME! */ public void addMouseListener(java.awt.event.MouseListener ml) { // no mouselistener for you! } } /** * DOCUMENT ME! * $Id: JMFMediaPlayer.java,v 1.8 2007/01/15 08:20:53 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.8 $ */ protected class MouseHandler extends MouseAdapter { /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void mousePressed(MouseEvent e) { if (SwingUtilities.isRightMouseButton(e) || e.isPopupTrigger()) { popup.show(player.getVisualComponent(), e.getPoint().x, e.getPoint().y); } } /** * On a double click on the visual component of this player it will become * the first (largest) player. * @param e the mouse event */ public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() >= 2) { if (layoutManager != null) { layoutManager.setFirstPlayer(JMFMediaPlayer.this); } return; } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -