⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 nativemediaplayerwindowsqt.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* * File:     NativeMediaPlayerWindowsQT.java * Project:  MPI Linguistic Application * Date:     02 May 2007 * * Copyright (C) 2001-2007  Max Planck Institute for Psycholinguistics * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA */package mpi.eudico.client.annotator.player;import com.jniwrapper.*;import com.jniwrapper.win32.automation.Automation;import com.jniwrapper.win32.automation.IDispatch;import com.jniwrapper.win32.automation.OleContainer;import com.jniwrapper.win32.automation.types.BStr;import com.jniwrapper.win32.automation.types.Variant;import com.jniwrapper.win32.com.CoInit;import com.jniwrapper.win32.com.ComFunctions;import com.jniwrapper.win32.com.types.*;import com.jniwrapper.win32.ole.OleFunctions;import com.jniwrapper.win32.ole.impl.IOleObjectImpl;import com.jniwrapper.win32.ole.types.OleVerbs;import com.jniwrapper.win32.ui.WindowTools;import com.jniwrapper.win32.ui.Wnd;import mpi.eudico.client.annotator.ElanLayoutManager;import mpi.eudico.client.annotator.ElanLocale;import mpi.eudico.client.annotator.gui.FormattedMessageDlg;import mpi.eudico.client.mediacontrol.ControllerEvent;import mpi.eudico.client.mediacontrol.ControllerListener;import mpi.eudico.client.mediacontrol.ControllerManager;import mpi.eudico.server.corpora.clomimpl.abstr.MediaDescriptor;import mpi.util.TimeFormatter;//import mpi.eudico.client.annotator.nativemedia.qtactivexplugin.*;//import mpi.eudico.client.annotator.nativemedia.qtactivexplugin.impl.*;import java.awt.Panel;import java.awt.event.ActionEvent;import java.awt.event.ActionListener;import java.awt.event.ComponentEvent;import java.awt.event.ComponentListener;import java.awt.event.HierarchyEvent;import java.awt.event.HierarchyListener;import java.awt.event.MouseAdapter;import java.util.StringTokenizer;import javax.swing.JFrame;import javax.swing.JMenuItem;import javax.swing.JPanel;import javax.swing.JPopupMenu;import javax.swing.SwingUtilities;/** * The JMF implementation of an elan media player */public class NativeMediaPlayerWindowsQT extends ControllerManager    implements ElanMediaPlayer, ControllerListener, ActionListener {    /** Holds value of property DOCUMENT ME! */    private final static String QTActiveXPlugin_INTERFACE_ID = "{02BF25D5-8C17-4B23-BC80-D3488ABDDC6B}";    private MediaDescriptor mediaDescriptor;    private boolean playing;    private long offset;    private long duration;    private float aspectRatio;    private long millisPerSample;    private JPopupMenu popup;    private JMenuItem durationItem;    /** Holds value of property DOCUMENT ME! */    protected JMenuItem detachItem;    private JMenuItem infoItem;    private ElanLayoutManager layoutManager;    private boolean detached;    /** Holds value of property DOCUMENT ME! */    private final OleContainer oleContainer;    private Automation automation;    private VisualComponent visualComponent;    private long now;    private float rate;    private float timeScale;    private long stopTime;    /**     * Create a JMFMediaPlayer for a media URL     *     * visual component     * speelsnelheid controleren, time scale lijkt vreemd     * na lang stil staan is een nieuwe initialisatie nodig?     * player rate is niet in te stellen     * aspect ratio     * milli seconds per frame     *     * @param mediaDescriptor DOCUMENT ME!     *     * @throws NoPlayerException DOCUMENT ME!     */    public NativeMediaPlayerWindowsQT(MediaDescriptor mediaDescriptor)        throws NoPlayerException {        try {            this.mediaDescriptor = mediaDescriptor;            if (DefaultLibraryLoader.getInstance().findLibrary("jniwrap") == null) {                // relative path to the cvs MPI directory which is the user.dir for developers                DefaultLibraryLoader.getInstance().addPath("lib/java/jniwrapper");                DefaultLibraryLoader.getInstance().loadLibrary("jniwrap");            }            String URLString = mediaDescriptor.mediaURL;            //URLString = "rtsp://nt06.mpi.nl:80/De_Eng.mp4";            //   	URLString = "rtsp://nt06.mpi.nl:80/SyncTest_hinted.mov";            //		URLString = "file:///N:/echo2a_6.mp4";            //		URLString = "file:///N:/SyncTest.mpg";            System.out.println("url: " + URLString);            OleFunctions.oleInitialize();            oleContainer = new OleContainer();            oleContainer.createObject(CLSID.create(QTActiveXPlugin_INTERFACE_ID));            //	    	oleContainer.doVerb(OleVerbs.PRIMARY);            //	   	    oleContainer.doVerb(OleVerbs.SHOW);            //	    	oleContainer.doVerb(OleVerbs.INPLACEACTIVATE);            //	    	oleComponent.doVerb(OleVerbs.OPEN);            //	    	oleContainer.doVerb(OleVerbs.UIACTIVATE);            //	    	oleComponent.doVerb(OleVerbs.SHOW);	              //	    	visualComponent = new VisualComponent();            //	    	visualComponent.add(oleContainer);            JFrame sample = new JFrame("Streaming Video");            ;            sample.getContentPane().add(oleContainer);            sample.setSize(640, 480);            sample.setVisible(true);            oleContainer.doVerb(OleVerbs.SHOW);            automation = new Automation(oleContainer.getOleObject());            automation.invoke("SetURL", new Object[] { new BStr(URLString) });            //automation.invoke("SetRectangle", new Object[] {new BStr("0, 0, 300, 200")});            automation.invoke("SetControllerVisible",                new Object[] { new Int32(0) });            automation.invoke("SetTime", new Object[] { new Int32(0) });            //automation.invoke("Rewind");            //automation.invoke("SetPlayEveryFrame", new Object[] {new Int32(-1)});            //something is wrong here?            timeScale = ((float) ((Variant) automation.invoke("GetTimeScale")).getLVal()                                  .getValue()) / 1000;            System.out.println("time scale " +                ((Variant) automation.invoke("GetTimeScale")).getLVal()                 .getValue());            System.out.println("time scale " + timeScale);            System.out.println("movie size " +                ((Variant) automation.invoke("GetMovieSize")).getLVal()                 .getValue());            aspectRatio = 1;            duration = (long) (((Variant) automation.invoke("GetDuration")).getLVal()                                .getValue() / timeScale);            millisPerSample = 40;            rate = 1.0f;            start();            stop();            automation.invoke("SetTime", new Object[] { new Int32(0) });            //automation.invoke("Rewind");            JPopupMenu.setDefaultLightWeightPopupEnabled(false);            popup = new JPopupMenu();            infoItem = new JMenuItem(ElanLocale.getString("Player.Info"));            infoItem.addActionListener(this);            durationItem = new JMenuItem(ElanLocale.getString("Player.duration") +                    ":  " + TimeFormatter.toString(getMediaDuration()));            durationItem.setEnabled(false);            popup.addSeparator();            popup.add(infoItem);            popup.add(durationItem);        } catch (Exception e) {            e.printStackTrace();            throw new NoPlayerException(                "Problem while creating Quicktime based native player");        }    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public MediaDescriptor getMediaDescriptor() {        return mediaDescriptor;    }    /**     * DOCUMENT ME!     */    public void finalize() {        OleFunctions.oleUninitialize();    }    /**     *     */    public String getFrameworkDescription() {        return "Native Windows Media Framework QT Plugin";    }    /**     * Should be removed from interface?     */    public synchronized void controllerUpdate(ControllerEvent event) {    }    /**     *     */    public synchronized void playInterval(long startTime, long stopTime) {        /*                automation.invoke("SetTime", new Object[] {new Int32(0)});                System.out.println("mt1 " + getMediaTime());                automation.invoke("Step", new Object[] {new Int32(1)});                System.out.println("mt1 " + getMediaTime());                automation.invoke("SetTime", new Object[] {new Int32(0)});                System.out.println("mt1 " + getMediaTime());                automation.invoke("Step", new Object[] {new Int32(10)});                System.out.println("mt1 " + getMediaTime());                */        System.out.println("play interval " + startTime + " - " + stopTime);        setMediaTime(startTime);        System.out.println("SetEndTime " +            (int) ((stopTime * timeScale) + offset));        setStopTime(stopTime);        //automation.invoke("SetEndTime", new Object[] {new Int32((int) (stopTime * timeScale + offset))});        start();    }    /**     *     */    public void setStopTime(long stopTime) {        this.stopTime = stopTime;        automation.invoke("SetEndTime",            new Object[] { new Int32((int) ((stopTime * timeScale) + offset)) });    }    /**     * Gets the display Component for this Player.     *     * @return DOCUMENT ME!     */    public java.awt.Component getVisualComponent() {        return visualComponent;    }    /**     * Extracts the QT interpreted source height from what the activeX plugin     * returns when "GetRectangle" is invoked: a peculiar string representation     * of a rectangle. The format is "x,y,w,h", but the video height seems to     * be (h-y).     *     * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceHeight()     */    public int getSourceHeight() {        try {            Variant wi = (Variant) automation.invoke("GetRectangle");            if (wi != null) {                BStr bs = (BStr) wi.getValue();                System.out.println("Bstr: " + bs.getValue());                // the BStr has the format "x,y,w,h"                // the actual video height seems to be: h - y ??                 StringTokenizer tokenizer = new StringTokenizer(bs.getValue(),                        ",");                tokenizer.nextToken();                int y = Integer.valueOf(tokenizer.nextToken()).intValue();                tokenizer.nextToken();                int th = Integer.valueOf(tokenizer.nextToken()).intValue();                System.out.println("Height: " + (th - y));                return th - y;            }        } catch (Exception ex) { //any exceptin, NumberFormatException, COMException            System.out.println("Could not get height: " + ex.getMessage());        }        return 240;    }    /**     * Extracts the QT interpreted source width from what the activeX plugin     * returns when "GetRectangle" is invoked: a peculiar string representation     * of a rectangle. The format is "x,y,w,h", but the video width seems to     * be (w-x).     *     * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceWidth()     */    public int getSourceWidth() {        try {            Variant wi = (Variant) automation.invoke("GetRectangle");            if (wi != null) {                BStr bs = (BStr) wi.getValue();                //System.out.println("Bstr: " + bs.getValue());                // the BStr has the format "x,y,w,h"                // the actual video width seems to be: w - x ??                 StringTokenizer tokenizer = new StringTokenizer(bs.getValue(),                        ",");                int x = Integer.valueOf(tokenizer.nextToken()).intValue();                tokenizer.nextToken();                int tw = Integer.valueOf(tokenizer.nextToken()).intValue();                //System.out.println("Width: " + (tw - x));                return tw - x;            }        } catch (Exception ex) { //any exceptin, NumberFormatException, COMException            System.out.println("Could not get width: " + ex.getMessage());        }        return 320;    }    /**     * Gets the aspectRatio between width and height of the video image     *     * @return DOCUMENT ME!     */    public float getAspectRatio() {        return aspectRatio;    }    /**     * Starts the Player as soon as possible. is not synchronized in JMF     */    public synchronized void start() {        // play at start of media if at end of media        System.out.println("start duration: " + getMediaDuration());        System.out.println("start current:  " + getMediaTime());        if ((getMediaDuration() - getMediaTime()) < 40) { // slow startup so maybe > 40            setMediaTime(0);        }        automation.invoke("Play");        //automation.invoke("SetRate", new Object[] {new DoubleFloat(rate)});        // make sure all managed controllers are started        startControllers();        //        double rate = ((Variant) automation.invoke("GetRate")).getFltVal().getValue();        while (getRate() == 0) {            try {                Thread.sleep(100);                //	    		rate = ((Variant) automation.invoke("GetRate")).getFltVal().getValue();                //	    		System.out.println("sleep start, rate: " + getRate());            } catch (Exception e) {            }        }        playing = true;        new Thread(new PlayerStateWatcher()).start();    }

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -