How to make Video splash

本文介绍了一个简单的视频启动屏实现方案,支持多种视频格式,如GIF、AVI、MPG等,并提供了完整的Java代码示例。

http://wiki.forum.nokia.com/index.php/How_to_make_Video_splash

 

In those a few lines you will find a code of how to create easy startup splash screen that can play video files of any format (GIF,AVI,mpg,3gpp,real etc..)

video splash class

package GALAXY.videosplash;
 
import java.io.*;
 
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
 
public class Splash extends Canvas implements PlayerListener, Runnable {
    private Display display;
    //the next screen
    private Displayable next;
    //the video mime type
    private String MIMEtype;
    private Player player;
    private String file;
 
    public Splash(Display display, Displayable next, String file,
                  String MIMEtype) {
 
        this.display = display;
        this.next = next;
        this.file = file;
        this.MIMEtype = MIMEtype;
        Thread th = new Thread(this);
        th.start();
 
    }
 
    //if any button is pressed, finalizes splash screen
    protected void keyPressed(int keyCode) {
        stopPlayer();
        nextScreen();
    }
 
    protected void paint(Graphics g) {
        int x = g.getClipX();
        int y = g.getClipY();
 
        int w = g.getClipWidth();
        int h = g.getClipHeight();
 
        g.setColor(0x0000000);
        g.fillRect(x, y, w, h);
 
 
    }
 
    //for touch screen devices.
    protected void pointerPressed(int x, int y) {
        stopPlayer();
        nextScreen();
    }
 
    protected void showNotify() {
 
    }
 
    private void nextScreen() {
 
        this.display.setCurrent(next);
    }
 
    public void run() {
        try {
            resetplayer();
        } catch (MediaException ex) {
            nextScreen();
        }
        this.play(file);
 
    }
 
    public void playerUpdate(Player player, String playerstate, Object object) {
        if (playerstate == PlayerListener.END_OF_MEDIA) {
            try {
                resetplayer();
            } catch (MediaException me) {
 
            }
            player = null;
            nextScreen();
        }
 
    }
 
    private void resetplayer() throws MediaException {
        if (player != null) {
            //checks if the video is being rendered.
            if (player.getState() == Player.STARTED) {
                player.stop();
            }
            //the player has all resources to execute
            if (player.getState() == Player.PREFETCHED) {
                //free resources
                player.deallocate();
            }
            //the player obtained the necessary information to acquire the resources (REALIZED) or the player 
            //has just been created.
            if (player.getState() == Player.REALIZED ||
                player.getState() == Player.UNREALIZED) {
                player.close(); //closes the player
            }
        }
        player = null;
    }
 
    private void play(String url) {
        try {
            //gets video from /res folder
            InputStream is = getClass().getResourceAsStream(url);
            VideoControl vc;
            resetplayer();
            // create a player instance
 
            player = Manager.createPlayer(is, this.MIMEtype);
 
            // realize the player
            player.realize();
            //gets all necessary resources
            player.prefetch();
            //adds a player listener. annonces player events: stoped, paused, etc
            player.addPlayerListener(this);
 
            //video control for video rendering
            vc = (VideoControl) player.getControl("VideoControl");
            //if null, the device probably has no support for video rendering 
            if (vc != null) {
 
               vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
               vc.setDisplayLocation(((this.getWidth() - vc.getDisplayWidth()) /
                                   2),
                                    (this.getHeight() - vc.getDisplayHeight()) /
                                   2);
 
 
                vc.setVisible(true);
 
                this.setFullScreenMode(true);
            }
            player.start();
            this.display.setCurrent(this);
        } catch (Throwable t) {
 
            player = null;
            nextScreen();
        }
    }
 
    private void stopPlayer() {
        try {
            resetplayer();
        } catch (MediaException me) {
 
        }
        player = null;
 
    }
}

second ,this is the MIDlet example. Note that all I have to do was just to create a new instance of videosplash class

MIDLET

{
package GALAXY.videosplash;
 
import javax.microedition.midlet.*;
import javax.microedition.lcdui.*;
 
public class SplashMIDlet extends MIDlet {
    static SplashMIDlet instance;
 
    public SplashMIDlet() {
        instance = this;
    }
 
    public void startApp() {
        Display dispaly = Display.getDisplay(this);
 
 
        Splash sp = new Splash(dispaly, new Form("Test"),"/PhotoStory.3gp", "video/3gpp");
 
 
    }
 
    public void pauseApp() {
    }
 
    public void destroyApp(boolean unconditional) {
    }
 
    public static void quitApp() {
        instance.destroyApp(true);
        instance.notifyDestroyed();
        instance = null;
    }
 
}

 

【源码免费下载链接】:https://renmaiwang.cn/s/crcx8 AmaterasUML是一款专为Eclipse集成开发环境设计的自动UML工具,它极大地简化了软件开发者在编码过程中创建和维护UML模型的过程。UML(统一建模语言)是一种标准化的图形表示法,用于描述软件系统的设计、结构和行为,是软件工程中的重要工具。通过使用AmaterasUML,开发者可以快速地从源代码自动生成UML类图、序列图和其他相关图表,从而更好地理解和管理项目结构。AmaterasUML支持的主要功能包括:1. **源码到UML的转换**:这个工具能够分析Java源代码,并自动将其转换为符合UML规范的类图。开发者无需手动绘制,只需专注于编写代码,AmaterasUML就能帮助你可视化代码结构。2. **实时更新**:当源代码发生变化时,AmaterasUML会自动检测并更新对应的UML图,保持图表与代码的一致性,减少了因手动调整而产生的错误。3. **多种UML图**:除了基本的类图,AmaterasUML还支持生成用例图、序列图、状态图和活动图等多种UML图表,覆盖了软件开发的多个方面,有助于全面理解系统设计。4. **交互式编辑**:用户不仅可以从代码生成UML,还可以反过来从UML图中生成或修改代码,实现双向工程,提高开发效率。5. **团队协作**:由于AmaterasUML与Eclipse的紧密集成,它可以无缝地融入到版本控制系统(如Git)中,方便团队成员共享和审查UML模型,促进协同开发。6. **定制化设置**:根据项目需求,用户可以自定义生成的UML图的显示样式和细节级别,使得图表更加符合个人或团队的风格。7. **易于集成**:作为Eclipse插件,AmaterasUML安装简单,只需在Eclipse Marketplace中搜索并安装即可,无需额外配置。8
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值