📄 nativemediaplayerwindowsds.java
字号:
if (time < 0) { time = 0; } mediaPosition.setCurrentPosition(new DoubleFloat( ((float) time + offset) / 1000)); setControllersMediaTime(time); } /** * No native frame stepping available but use maximum precision NTSC has * non integer frame durations so rounding errors should be avoided */ public void nextFrame() { if (mediaControl.getState(new Int32(0)).getValue() != STATE_PAUSE) { mediaControl.pause(); } double pos = mediaPosition.getCurrentPosition().getValue(); pos += (millisPerSample / 1000); mediaPosition.setCurrentPosition(new DoubleFloat(pos)); setControllersMediaTime(getMediaTime()); } /** * No native frame stepping available but use maximum precision NTSC has * non integer frame durations so rounding errors should be avoided */ public void previousFrame() { if (mediaControl.getState(new Int32(0)).getValue() != STATE_PAUSE) { mediaControl.pause(); } double pos = mediaPosition.getCurrentPosition().getValue(); pos -= (millisPerSample / 1000); if (pos < 0) { pos = 0; } mediaPosition.setCurrentPosition(new DoubleFloat(pos)); setControllersMediaTime(getMediaTime()); } /** * Gets this players current media time in milli seconds. * * @return DOCUMENT ME! */ public long getMediaTime() { double pos = 0.0005 + mediaPosition.getCurrentPosition().getValue(); // 0.0005 to avoid rounding errors return (long) (1000 * pos) - offset; } /** * Gets the current temporal scale factor. * * @return DOCUMENT ME! */ public float getRate() { return (float) mediaPosition.getRate().getValue(); } /** * Sets the temporal scale factor. * * @param rate DOCUMENT ME! */ public synchronized void setRate(float rate) { mediaPosition.setRate(new DoubleFloat(rate)); setControllersRate(rate); } /** * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#isFrameRateAutoDetected() */ public boolean isFrameRateAutoDetected() { return frameRateAutoDetected; } /** * Get the duration of the media represented by this object in milli * seconds. * * @return DOCUMENT ME! */ public long getMediaDuration() { return duration; } /** * 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())); saveItem.setText(ElanLocale.getString("Player.SaveFrame")); 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(getVisualComponent()); detachItem.setText(ElanLocale.getString("Detachable.detach")); detached = false; } else { layoutManager.detach(getVisualComponent()); detachItem.setText(ElanLocale.getString("Detachable.attach")); detached = true; } getVisualComponent().addNotify(); } else if (e.getSource() == infoItem) { new FormattedMessageDlg(this); } else if (e.getSource() == saveItem) { ImageExporter export = new ImageExporter(); export.exportImage((BufferedImage) getCurrentFrameImage()); } } /** * Grabs the current video frame and converts it to an Image object. * * @return the current video frame */ public Image getCurrentFrameImage() { return getFrameImageForTime(getMediaTime()); } /** * Tries to grab the frame for the specified time and convert it to a * BufferedImage. The player will be set to the specified media time. * * @param time the media time to grab the frame for * * @return the frame image or null */ public Image getFrameImageForTime(long time) { if (time != getMediaTime()) { setMediaTime(time); } BufferedImage image = null; try { mediaControl.pause(); // calling getCurrentImage with two valid Int32 objects causes // an E_OUTOFMEMORY exception Int32 bufSize = new Int32(); Int32 imPointer = null; // fill the buffer size basicVideo.getCurrentImage(bufSize, imPointer); int bufferSize = (int) bufSize.getValue(); //System.out.println("Buffer Size: " + bufferSize); //imPointer = new Int32(); PrimitiveArray myArray = new PrimitiveArray(UInt8.class, bufferSize); ExternalArrayPointer pArray = new ExternalArrayPointer(myArray); Parameter[] params = new Parameter[] { new Pointer(new Int32(bufferSize)), pArray }; ((IBasicVideoImpl) basicVideo).getCurrentImage2(params); byte[] data = myArray.getBytes(); image = DIBToImage.DIBDataToBufferedImage(data); } catch (ComException ce) { ce.printStackTrace(); } return image; } /** * DOCUMENT ME! * $Id: NativeMediaPlayerWindowsDS.java,v 1.15 2007/03/19 16:54:03 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.15 $ */ private class VisualComponent extends Panel implements ComponentListener, HierarchyListener { /** * Creates a new VisualComponent instance */ public VisualComponent() { videoWindow.setWindowStyle(new Int32(Wnd.WS_CHILD)); // videoWindow.setAutoShow(new Int32(-1)); addComponentListener(this); addHierarchyListener(this); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void componentResized(ComponentEvent e) { if (videoWindow.getVisible().getValue() != -1) { return; } Int32 left = new Int32(); left.setValue(0); Int32 top = new Int32(); top.setValue(0); Int32 width = new Int32(); width.setValue(getWidth()); Int32 height = new Int32(); height.setValue(getHeight()); videoWindow.setWindowPosition(left, top, width, height); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void hierarchyChanged(HierarchyEvent e) { //System.out.println("hier"); if (isDisplayable()) { long handle = WindowTools.getWindowHandle(this); LongPtr ownerWindow = new LongPtr(); ownerWindow.setValue(handle); if (videoWindow != null) { videoWindow.setOwner(ownerWindow); videoWindow.setMessageDrain(ownerWindow); setVisible(true); videoWindow.setVisible(new Int32(-1)); } } } /** * DOCUMENT ME! */ public void addNotify() { //System.out.println("addNotify"); super.addNotify(); long handle = WindowTools.getWindowHandle(this); LongPtr ownerWindow = new LongPtr(); ownerWindow.setValue(handle); if (videoWindow != null) { videoWindow.setOwner(ownerWindow); videoWindow.setMessageDrain(ownerWindow); } } /** * DOCUMENT ME! */ public void removeNotify() { //System.out.println("removeNotify"); if (videoWindow != null) { videoWindow.setVisible(new Int32(0)); videoWindow.setOwner(new LongPtr()); } super.removeNotify(); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void componentShown(ComponentEvent e) { //System.out.println("show"); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void componentHidden(ComponentEvent e) { //System.out.println("hide"); } /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void componentMoved(ComponentEvent e) { //System.out.println("move"); } /** * DOCUMENT ME! * * @throws Throwable DOCUMENT ME! */ protected void finalize() throws Throwable { System.out.println("finalize visual component"); super.finalize(); } } /** * Temporary class to take care of state changes after the player finished * playing an interval or reached end of media As soon as active * callback can be handled this class will become obsolete */ private class PlayerStateWatcher implements Runnable { /** * DOCUMENT ME! */ public void run() { while (playing && (getMediaTime() < stopTime)) { try { Thread.sleep(300); } catch (Exception e) { e.printStackTrace(); } } // if at stop time (i.e. not stopped by hand) do some extra stuff if (playing) { mediaControl.stopWhenReady(); stopControllers(); // some mpeg2 codecs need an extra set media time to render the correct frame // if needed undo stop time correction, see setStopTime for details if (getMediaTime() == (stopTime + 1)) { setMediaTime(stopTime); // sometimes needed for mpeg2 } else { setMediaTime(getMediaTime()); // sometimes needed for mpeg2 } setStopTime(duration); mediaControl.pause(); playing = false; } } } /** * DOCUMENT ME! * $Id: NativeMediaPlayerWindowsDS.java,v 1.15 2007/03/19 16:54:03 hasloe Exp $ * @author $Author: hasloe $ * @version $Revision: 1.15 $ */ private class MouseHandler extends MouseAdapter { /** * DOCUMENT ME! * * @param e DOCUMENT ME! */ public void mouseClicked(java.awt.event.MouseEvent e) { if (e.getClickCount() >= 2) { if (layoutManager != null) { layoutManager.setFirstPlayer(NativeMediaPlayerWindowsDS.this); } return; } JPopupMenu.setDefaultLightWeightPopupEnabled(false); if (SwingUtilities.isRightMouseButton(e)) { popup.show(getVisualComponent(), e.getPoint().x, e.getPoint().y); } } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -