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

📄 videocanvas.java

📁 看看如何用j2me 制作自己的媒体播放器。 附带直接运行文件
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
            System.err.println(e);            close();        }    }    public void start() {        if (player == null)            return;        try {            duration = player.getDuration();            player.start();            if (duration != Player.TIME_UNKNOWN) {                sliderThread = new Thread(this);                sliderThread.start();            }        } catch (Exception e) {            System.err.println(e);             close();        }    }    public void close() {        synchronized (this) {            pause();            if (player != null) {                player.close();                player = null;            }        }        VideoTest.getInstance().nullPlayer();    }    public void pause() {        if ( player != null) {            try {                player.stop();            } catch (MediaException me) {        		System.err.println(me);            }        }    }    public void playerUpdate(Player plyr, String evt, Object evtData) {        //try {            if ( evt == END_OF_MEDIA ) {                try {                    player.setMediaTime(0);                    player.start();                } catch (MediaException me) {                    System.err.println(me);                }            }        //} catch (Exception e) {        //    System.out.println("DEBUG: GOT EXCEPTION in VideoCanvas.playerUpdate("+evt.toString()+")!");        //    e.printStackTrace();        //}    }        private void doSnapshot() {        new SnapshotThread().start();    }            class SnapshotThread extends Thread {        final Canvas tThis = (Canvas)VideoCanvas.this;                public void run() {            try {                byte [] snap = vidc.getSnapshot("encoding=png");                if (snap != null) {                Image im = Image.createImage(snap, 0, snap.length);                Alert al = new Alert("Snapshot",                             "Here's the snap",                             im,                             AlertType.INFO);                al.setTimeout(2000);                parentDisplay.setCurrent(al, tThis);                }            } catch (MediaException me) {                System.err.println(me);            //} catch (Exception e) {            //    System.out.println("DEBUG: GOT EXCEPTION in VideoCanvas.SnapshotThread.run()!");            //    e.printStackTrace();            }        }    }    public synchronized void stopVideoCanvas() {        // stop & deallocate        player.deallocate();    }    /* Handle the different keys pressed on the phone GUI emulator */    public void keyPressed(int keyCode) {        int cr, cv;        switch (keyCode) {        case Canvas.KEY_NUM4:            cr = rc.getRate();            cr -= 10000;            cr = rc.setRate(cr);            break;        case Canvas.KEY_NUM6:            cr = rc.getRate();            cr += 10000;            cr = rc.setRate(cr);            break;        case Canvas.KEY_STAR:            if (vc != null) {                cv = vc.getLevel();                cv -= 10;                cv = vc.setLevel(cv);            }            break;        case Canvas.KEY_NUM0:            if (vc != null) {                vc.setMute(!vc.isMuted());            }            break;        case Canvas.KEY_POUND:            if (vc != null) {                cv = vc.getLevel();                cv += 10;                cv = vc.setLevel(cv);            }            break;        case Canvas.KEY_NUM7:            if (fpc != null) {                fpc.skip(-1);            }            break;        case Canvas.KEY_NUM5:            try {                player.stop();                if (!isCapturePlayer) {                    player.setMediaTime(0);                }                player.deallocate();            } catch (MediaException me) {        		System.err.println(me);            }            break;        case Canvas.KEY_NUM9:            if (fpc != null) {                fpc.skip(1);            }            break;        case Canvas.KEY_NUM2:            try {                if (player.getState() == Player.STARTED)                    player.stop();                else                    player.start();            } catch (Exception e) {                System.err.println(e);            }            break;        case Canvas.KEY_NUM8:            try {                // Full screen                if (vidc != null)                    vidc.setDisplayFullScreen(fsmode = !fsmode);                repaint();            } catch (MediaException me) {                System.err.println(me);            }            break;        case Canvas.KEY_NUM1:        case Canvas.KEY_NUM3:            if (!isCapturePlayer) {                long mTime = player.getMediaTime();                long duration = player.getDuration();                if (duration == Player.TIME_UNKNOWN || mTime == Player.TIME_UNKNOWN)                    return;                try {                    if (keyCode == Canvas.KEY_NUM3) {                        // Jump forward 10%                        mTime += duration / 10;                        if (mTime > duration)                            mTime = duration;                        player.setMediaTime(mTime);                    } else if (keyCode == Canvas.KEY_NUM1) {                        mTime -= duration / 10;                        if (mTime < 0)                            mTime = 0;                        player.setMediaTime(mTime);                    } else                        return;                } catch (MediaException me) {                    System.err.println(me);                }            }            break;        /* Code to move the video around using cursor keys */        default:            int game = getGameAction(keyCode);            int x = vidc.getDisplayX();            int y = vidc.getDisplayY();            if (game == UP)                vidc.setDisplayLocation(x, y - 10);            else if (game == DOWN)                vidc.setDisplayLocation(x, y + 10);            else if (game == LEFT)                vidc.setDisplayLocation(x - 10, y);            else if (game == RIGHT)                vidc.setDisplayLocation(x + 10, y);            else if (game == FIRE)                vidc.setVisible(vis = !vis);            repaint();            break;        }    }    /**     * Deallocate the player and the display thread.     * Some VM's may stop players and threads     * on their own, but for consistent user     * experience, it's a good idea to explicitely     * stop and start resources such as player     * and threads.     */    public synchronized void pauseApp() {        suspended = true;        if (player != null && player.getState() >= Player.STARTED) {            // player was playing, so stop it and release resources.            if (!isCapturePlayer) {                restartMediaTime = player.getMediaTime();            }            player.deallocate();            // make sure to restart upon resume            restartOnResume = true;        } else {            restartOnResume = false;        }    }	    /**     * If the player was playing when the MIDlet was paused,     * then the player will be restarted here.     */    public synchronized void startApp() {        suspended = false;        if (player != null && restartOnResume) {            try {                player.prefetch();                if (!isCapturePlayer) {                    try {                        player.setMediaTime(restartMediaTime);                    } catch (MediaException me) {                        System.err.println(me);                    }                }                player.start();            } catch (MediaException me) {                System.err.println(me);            }        }        restartOnResume = false;    }}

⌨️ 快捷键说明

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