Click here to Skip to main content
11,482,402 members (72,473 online)
Click here to Skip to main content

Tagged as

How to make Video splash

, 16 Sep 2009 CPOL 10.7K 12
Rate this:
Please Sign up or sign in to vote.
This blog has been contributed to Forum Nokia Wiki at 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 classpackage G

This blog has been contributed to Forum Nokia Wiki at 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;
   private Displayable next;
   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();

   }

   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);


   }

   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) {
           if (player.getState() == Player.STARTED) {
               player.stop();
           }
           if (player.getState() == Player.PREFETCHED) {
               player.deallocate();
           }
           if (player.getState() == Player.REALIZED ||
               player.getState() == Player.UNREALIZED) {
               player.close();
           }
       }
       player = null;
   }

   private void play(String url) {
       try {
           InputStream is = getClass().getResourceAsStream(url);
           VideoControl vc;
           resetplayer();
           // create a player instance

           player = Manager.createPlayer(is, this.MIMEtype);

           player.prefetch();
           player.addPlayerListener(this);
           // realize the player
           player.realize();

           vc = (VideoControl) player.getControl("VideoControl");
           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.prefetch();
           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 example of launch it form midelt,note that all I have to do i just create & initiate new instance of videosplash class



video splash class


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;
   }

}


License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

Mohamed M. Shaheen
Other Axiom Telecom
United Arab Emirates United Arab Emirates
Integration Specialist at Axiom Mobile Solutions a division of Axiom Telecom

Comments and Discussions

 
QuestionHelp needed regarding playing 2 videos at a time Pin
booota22-Feb-10 19:35
memberbooota22-Feb-10 19:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web03 | 2.8.150520.1 | Last Updated 16 Sep 2009
Article Copyright 2009 by Mohamed M. Shaheen
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid