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

📄 qtmediaplayer.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
        }        long startOff = startTime + offset;        long stopOff = stopTime + offset;        try {            // load small intervals in memory             // time scale??            if ((stopTime - startTime) < 5000) {                int loadBeginTime = ((startOff - 5000) > 0)                    ? (int) (startOff - 5000) : 0;                int loadDuration = (int) (stopOff - loadBeginTime + 1000);                //System.out.println("Loading " + loadDuration + " milliseconds in ram");                movie.loadIntoRam(loadBeginTime, loadDuration,                    StdQTConstants.unkeepInRam);                //		movie.loadIntoRam(loadBeginTime, loadDuration, 0);//StdQTConstants.unkeepInRam);            }            setMediaTime(startTime);            Thread.sleep(100);            /*                movie.prePreroll((int)startOff, movie.getPreferredRate());                if (!streaming) {                    movie.preroll((int)startOff, movie.getPreferredRate());                }                */            /*            controller.setSelectionBegin(new TimeRecord (1000, startTime));            controller.setSelectionDuration(new TimeRecord (1000, stopTime - startTime));            controller.setLooping(true);            controller.setPlaySelection(true);            startControllers();            controller.play(1f);            */            // correct stoptime for frame boundary?            if (stopMode == STOP_WITH_STOP_TIME) {                setStopTime(stopOff);            } else {                movie.setPreviewTime((int) startOff,                    (int) (stopTime - startTime));                movie.setPreviewMode(true);            }            exactStopTime = stopTime;            start();        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Empty implementation for ElanMediaPlayer Interface     * Only usefull for player that correctly supports setting stop time     */    public void setStopTime(long stopTime) {        try {            timeBase.setStopTime(new TimeRecord(movie.getTimeScale(), stopTime));        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Gets the display Component for this Player.     *     * @return DOCUMENT ME!     */    public java.awt.Component getVisualComponent() {        return visualComponent;        /*        if (isWavPlayer) {            return null;        } else {            //return canvas.asJComponent();        //       return canvas.asComponent();            return visualComponent;        }        */    }    /**     * DOCUMENT ME!     *     * @return DOCUMENT ME!     */    public java.awt.Component createNewVisualComponent() {        if (isWavPlayer) {            return null;        } else {            try {                canvas = QTFactory.makeQTComponent(movie);                visualComponent = canvas.asComponent();                visualComponent.addMouseListener(new MouseHandler());            } catch (QTException qte) {                System.out.println("Could not create a new visual component. ");                qte.printStackTrace();            }            return visualComponent;        }    }    /**     * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceHeight()     */    public int getSourceHeight() {        if (movie != null) {            try {                return movie.getNaturalBoundsRect().getHeight();            } catch (QTException qte) {                return 0;            }        }        return 0;    }    /**     * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#getSourceWidth()     */    public int getSourceWidth() {        if (movie != null) {            try {                return movie.getNaturalBoundsRect().getWidth();            } catch (QTException qte) {                return 0;            }        }        return 0;    }    /**     * Gets the ratio between width and height of the video image     *     * @return DOCUMENT ME!     */    public float getAspectRatio() {        if (movie == null) {            return 0;        }        //float aspectRatio = (float) (canvas.asJComponent().getPreferredSize()        //                                   .getWidth() / canvas.asJComponent().getPreferredSize().getHeight());        //float aspectRatio = (float) (canvas.asComponent().getPreferredSize().getWidth() /        //									canvas.asComponent().getPreferredSize().getHeight());        return aspectRatio;    }    /**     * Starts the Player as soon as possible. is not synchronized in JMF     */    public synchronized void start() {        if (movie == null) {            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);        }        try {            // make sure all managed controllers are started            startControllers();            movie.start();        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Stop the media player     */    public synchronized void stop() {        if (movie == null) {            return;        }        try {            movie.stop();            // make sure all managed controllers are stopped            stopControllers();            setControllersMediaTime(getMediaTime());        } catch (QTException qt) {            qt.printStackTrace();        }    }    /**     * Tell if this player is playing     *     * @return DOCUMENT ME!     */    public boolean isPlaying() {        if (movie == null) {            return false;        }        float rate = 0;        try {            rate = movie.getRate();        } catch (Exception qt) {            qt.printStackTrace();        }        return (rate != 0);    }    /**     * 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 (movie == null) {            return;        }        // do not set media time on a started player        if (isPlaying()) {            stop();        }        try {            movie.setTime(new TimeRecord(movie.getTimeScale(), time + offset));            // set the media time for the connected controllers            setControllersMediaTime(time);        } catch (Exception qt) {            qt.printStackTrace();        }    }    /**     * 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 (movie == null) {            return 0;        }        long time = 0;        try {            time = movie.getTime();        } catch (Exception qt) {            qt.printStackTrace();        }        //System.out.println("get mt : " + (time - offset));        return time - offset;    }    /**     * DOCUMENT ME!     *     * @return the step size for one frame     */    public long getMilliSecondsPerSample() {        if (!rateDetectionAttempted) {            detectFrameRate();        }        return milliSecondsPerSample;    }    /**     * DOCUMENT ME!     *     * @param milliSeconds the step size for one frame     */    public void setMilliSecondsPerSample(long milliSeconds) {        if (!frameRateAutoDetected) {            milliSecondsPerSample = milliSeconds;        }        //milliSecondsPerSample = milliSeconds;    }    /**     * Sets the temporal scale factor.     *     * @param rate DOCUMENT ME!     */    public synchronized void setRate(float rate) {        if (movie == null) {            return;        }        // do not set rate on a started player        if (isPlaying()) {            stop();        }        try {            movie.setPreferredRate(rate);            setControllersRate(rate);        } catch (Exception e) {            e.printStackTrace();        }    }    /**     * Gets the current temporal scale factor.     *     * @return DOCUMENT ME!     */    public float getRate() {        if (movie == null) {            return 0;        }        float rate = 0;        try {            rate = movie.getPreferredRate();        } catch (Exception e) {            e.printStackTrace();        }        return rate;    }    /**     * @see mpi.eudico.client.annotator.player.ElanMediaPlayer#isFrameRateAutoDetected()     */    public boolean isFrameRateAutoDetected() {        if (!rateDetectionAttempted) {            detectFrameRate();        }        return frameRateAutoDetected;    }    /**     * Get the duration of the media represented by this object in milli     * seconds.     *     * @return DOCUMENT ME!     */    public long getMediaDuration() {        if (movie == null) {            return 0;        }        long duration = 0;        try {            duration = movie.getDuration();        } catch (Exception qt) {            qt.printStackTrace();        }        //System.out.println("dur " + duration);        return duration - offset;    }    /**     * Sets the volume as a number between 0 and 1     *     * @param volume DOCUMENT ME!     */    public void setVolume(float volume) {        if (movie == null) {            return;        }        try {            movie.setVolume(volume);        } catch (Exception qt) {            qt.printStackTrace();        }    }    /**     * Gets the volume as a number between 0 and 1     *     * @return DOCUMENT ME!     */    public float getVolume() {        if (movie == null) {            return 0;        }        float volume = 0;        try {            volume = movie.getVolume();        } catch (Exception qt) {            qt.printStackTrace();        }        return volume;    }    /**     * Sets the way an interval is being played by QT.     * @param mode the new stop mode, one of <code>STOP_WITH_PREVIEW</code>     * or <code>STOP_WITH_STOP_TIME</code>     */    public void setStopMode(int mode) {        if ((mode == STOP_WITH_PREVIEW) || (mode == STOP_WITH_STOP_TIME)) {            stopMode = mode;        }    }    /**     * Attempts to create a scratch movie file for save editing.     * This is to avoid modifications to an mpeg file when using 2d     * annotations (i.e. adding tracks).     *     * @return the temp scratch movie, or null     */    private Movie createScratchMovie() {        if (movie == null) {            return null;        }        try {            Media media = null;            if (movie.getTrackCount() >= 1) {                Track origTrack = movie.getTrack(1);                media = origTrack.getMedia();                if (media instanceof MPEGMedia) {                    isWavPlayer = false;                    // create a new editable movie object to prevent modification of                     // mpg files when using svg/graphic annotations	                    File tempFile = new File(Constants.ELAN_DATA_DIR,                            (scratchName + scratchCount++));                    // if deletion did fail on last exit...                    if (tempFile.exists()) {                        // if it is more than 24 hours old                        long modified = tempFile.lastModified();                        long age = System.currentTimeMillis() - modified;

⌨️ 快捷键说明

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