📄 nativemediaplayerwindowsds.java
字号:
fileSourceOutputPinInfo.disconnect(); } } break; } } */ // we have the file source filter output pin and the default filters, connect everything IPinInfoImpl pinInfoIn = new IPinInfoImpl(); IPinInfoImpl pinInfoOut = new IPinInfoImpl(); // connect the file source to the default splitter's input pin IDispatch pinDisp = defaultSplitterFI.findPin(new BStr("Input")); pinDisp.queryInterface(pinInfoIn.getIID(), pinInfoIn); fileSourceOutputPinInfo.connect(pinInfoIn); System.out.println("Filter: " + defaultSplitterFI.getName().getValue() + " In: " + pinInfoIn.getName().getValue()); // check which output pins are available // direction == 0 means input, direction == 1 means output defaultSplitterFI.getPins().queryInterface(splitterPinColl.getIID(), splitterPinColl); long outCount = splitterPinColl.getCount().getValue(); for (int i = 0; i < outCount; i++) { splitterPinColl.item(new Int32(i)).queryInterface(pinInfo.getIID(), pinInfo); if (pinInfo.getDirection().getValue() == 0) { continue; } if (pinInfo.getName().getValue().equals("Video")) { System.out.println("Filter: " + defaultSplitterFI.getName().getValue() + " Pin: " + pinInfo.getName().getValue() + " - " + pinInfo.getDirection().getValue()); //handle the video chain, item 0 = in, item 1 = out videoDecoderFI.getPins().queryInterface(pinColl.getIID(), pinColl); pinColl.item(new Int32(0)).queryInterface(pinInfoIn.getIID(), pinInfoIn); System.out.println("Filter: " + videoDecoderFI.getName().getValue() + " Pin: " + pinInfoIn.getName().getValue() + " - " + pinInfoIn.getDirection().getValue()); pinInfo.connect(pinInfoIn); //pinInfo.render(); pinColl.item(new Int32(1)).queryInterface(pinInfoOut.getIID(), pinInfoOut); System.out.println("Filter: " + videoDecoderFI.getName().getValue() + " Pin: " + pinInfoOut.getName().getValue() + " - " + pinInfoOut.getDirection().getValue()); videoRendererFI.getPins().queryInterface(pinColl.getIID(), pinColl); pinColl.item(new Int32(0)).queryInterface(pinInfoIn.getIID(), pinInfoIn); System.out.println("Filter: " + videoRendererFI.getName().getValue() + " Pin: " + pinInfoIn.getName().getValue() + " - " + pinInfoIn.getDirection().getValue()); pinInfoOut.connect(pinInfoIn); } else if (pinInfo.getName().getValue().equals("Audio")) { // handle the audio chain System.out.println("Filter: " + defaultSplitterFI.getName().getValue() + " Pin: " + pinInfo.getName().getValue() + " - " + pinInfo.getDirection().getValue()); audioDecoderFI.getPins().queryInterface(pinColl.getIID(), pinColl); pinColl.item(new Int32(0)).queryInterface(pinInfoIn.getIID(), pinInfoIn); System.out.println("Filter: " + audioDecoderFI.getName().getValue() + " Pin: " + pinInfoIn.getName().getValue() + " - " + pinInfoIn.getDirection().getValue()); pinInfo.connect(pinInfoIn); pinColl.item(new Int32(1)).queryInterface(pinInfoOut.getIID(), pinInfoOut); System.out.println("Filter: " + audioDecoderFI.getName().getValue() + " Pin: " + pinInfoOut.getName().getValue() + " - " + pinInfoOut.getDirection().getValue()); audioRendererFI.getPins().queryInterface(pinColl.getIID(), pinColl); pinColl.item(new Int32(0)).queryInterface(pinInfoIn.getIID(), pinInfoIn); System.out.println("Filter: " + audioRendererFI.getName().getValue() + " Pin: " + pinInfoIn.getName().getValue() + " - " + pinInfoIn.getDirection().getValue()); pinInfoOut.connect(pinInfoIn); } } // recreate objects, in case of new mediaControl final IMediaPositionImpl mp = new IMediaPositionImpl(); mediaControl.queryInterface(mp.getIID(), mp); mediaPosition = mp; final IVideoWindowImpl vw = new IVideoWindowImpl(); mediaControl.queryInterface(vw.getIID(), vw); videoWindow = vw; final IBasicVideo2Impl bv = new IBasicVideo2Impl(); mediaControl.queryInterface(bv.getIID(), bv); basicVideo = bv; final IBasicAudioImpl ba = new IBasicAudioImpl(); mediaControl.queryInterface(ba.getIID(), ba); basicAudio = ba; final IMediaEventExImpl me = new IMediaEventExImpl(); mediaControl.queryInterface(me.getIID(), me); mediaEvent = me; } catch (ComException comex) { // restore old structure System.out.println("Could not create default filter graph: " + comex.getMessage()); comex.printStackTrace(); } catch (Exception ex) { System.out.println("Any error: " + ex.getMessage()); ex.printStackTrace(); } } /** * DOCUMENT ME! * * @return DOCUMENT ME! */ public MediaDescriptor getMediaDescriptor() { return mediaDescriptor; } /** * */ public String getFrameworkDescription() { return "Native Windows Media Framework DS01"; } /** * Should be removed from interface? * * @param event DOCUMENT ME! */ public synchronized void controllerUpdate(ControllerEvent event) { } /** * Gets the display Component for this Player. * * @return DOCUMENT ME! */ public java.awt.Component getVisualComponent() { return visualComponent; } /** * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceHeight() */ public int getSourceHeight() { if (basicVideo != null) { return (int) basicVideo.getSourceHeight().getValue(); } return 0; } /** * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceWidth() */ public int getSourceWidth() { if (basicVideo != null) { return (int) basicVideo.getSourceWidth().getValue(); } return 0; } /** * Gets the aspectRatio between width and height of the video image * * @return DOCUMENT ME! */ public float getAspectRatio() { return aspectRatio; } /** * */ public synchronized void playInterval(long startTime, long stopTime) { // Setting stoptime BEFORE setting media time is important when rendering .wav // This sucks and there is no real explanation for it setStopTime(stopTime); setMediaTime(startTime); start(); } /** * Sets the time where the player and all its slaves should automaticaly * stop playing A correction is made for stop time on a frame boundary. In * the pause mode the correct (new) frame is shown when media time is set * to the frame boundary but stopping at the frame boundary does not * render the correct frame. * * @param stopTime DOCUMENT ME! */ public void setStopTime(long stopTime) { this.stopTime = stopTime; // see if the stop time must be increased to ensure correct frame rendering at a frame boundary long nFrames = (stopTime + offset) / getMilliSecondsPerSample(); long extra = 0; if ((nFrames * getMilliSecondsPerSample()) == (stopTime + offset)) { // on a frame boundary extra = 1; this.stopTime += 1; } mediaPosition.setStopTime(new DoubleFloat( ((float) stopTime + offset + extra) / 1000)); setControllersStopTime(stopTime); } /** * Starts the Player as soon as possible. is not synchronized in JMF */ public synchronized void start() { if (playing) { return; } // play at start of media if at end of media if ((getMediaDuration() - getMediaTime()) < 40) { setMediaTime(0); } playing = true; mediaControl.run(); // make sure all managed controllers are started startControllers(); // temporary polling for player state, will be obsolete when active callback is available Thread tw = new Thread(new PlayerStateWatcher()); // tw.setPriority(Thread.MIN_PRIORITY); tw.start(); } /** * Stop the media player */ public synchronized void stop() { if (!playing) { return; } mediaControl.pause(); stopControllers(); setControllersMediaTime(getMediaTime()); playing = false; } /* DISABLED BLOCK WITH EXPERIMENTAL ACTIVE CALLBACK CODE private class CallbackWindowProc extends WindowProc { //public CallbackWindowProc(Wnd window) { // super(window); //} public void callback() { System.out.println("filter graph message: " + (int)_msg.getValue()); switch ((int)_msg.getValue()) { case 10: break; default: break; } } } private static class ListenerWindow extends Wnd { public ListenerWindow(Component component) { super(component); } public static void eventLoop(long event) { System.out.println("event: " + event); } } */ /** * Tell if this player is playing * * @return DOCUMENT ME! */ public boolean isPlaying() { return playing; } /** * DOCUMENT ME! * * @return the step size for one frame */ public long getMilliSecondsPerSample() { return (long) millisPerSample; } /** * DOCUMENT ME! * * @param milliSeconds the step size for one frame */ public void setMilliSecondsPerSample(long milliSeconds) { // disabled because this player knows itself better //millisPerSample = milliSeconds; if (!frameRateAutoDetected) { millisPerSample = milliSeconds; } } /** * Gets the volume as a number between 0 and 1 * * @return DOCUMENT ME! */ public float getVolume() { // should do something more logarithmic? try { Int32 volume = basicAudio.getVolume(); return ((float) volume.getValue() + 10000) / 10000; } catch (Exception e) { return 1.0f; // do nothing here, The empty try catch might solve problems that occurred // on some clients when saving the volume during exit in ELAN 2.3 } } /** * Gets the volume as a number between 0 and 1 * * @param level DOCUMENT ME! */ public void setVolume(float level) { try { // should do something more logarithmic? basicAudio.setVolume(new Int32((int) ((level * 10000) - 10000))); } catch (Exception e) { // video without audio gives a problem when not catched // e.printStackTrace(); } } /** * 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; duration = (long) (1000 * mediaPosition.getDuration().getValue()) - offset; stopTime = duration; } /** * 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) { // the player must be in state 1(pause) when immediate rendering after set media time is required. if (mediaControl.getState(new Int32(0)).getValue() != STATE_PAUSE) { mediaControl.pause(); }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -