Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / desktop / MFC

How to make Video splash

0.00/5 (No votes)
16 Sep 2009CPOL 16.5K  
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 classpack

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


<br />package GALAXY.videosplash;<br /><br />import java.io.*;<br /><br />import javax.microedition.lcdui.*;<br />import javax.microedition.media.*;<br />import javax.microedition.media.control.*;<br /><br />public class Splash extends Canvas implements PlayerListener, Runnable {<br />   private Display display;<br />   private Displayable next;<br />   private String MIMEtype;<br />   private Player player;<br />   private String file;<br /><br />   public Splash(Display display, Displayable next, String file,<br />                 String MIMEtype) {<br /><br />       this.display = display;<br />       this.next = next;<br />       this.file = file;<br />       this.MIMEtype = MIMEtype;<br />       Thread th = new Thread(this);<br />       th.start();<br /><br />   }<br /><br />   protected void keyPressed(int keyCode) {<br />       stopPlayer();<br />       nextScreen();<br />   }<br /><br />   protected void paint(Graphics g) {<br />       int x = g.getClipX();<br />       int y = g.getClipY();<br /><br />       int w = g.getClipWidth();<br />       int h = g.getClipHeight();<br /><br />       g.setColor(0x0000000);<br />       g.fillRect(x, y, w, h);<br /><br /><br />   }<br /><br />   protected void pointerPressed(int x, int y) {<br />       stopPlayer();<br />       nextScreen();<br />   }<br /><br />   protected void showNotify() {<br /><br />   }<br /><br />   private void nextScreen() {<br /><br />       this.display.setCurrent(next);<br />   }<br /><br />   public void run() {<br />       try {<br />           resetplayer();<br />       } catch (MediaException ex) {<br />           nextScreen();<br />       }<br />       this.play(file);<br /><br />   }<br /><br />   public void playerUpdate(Player player, String playerstate, Object object) {<br />       if (playerstate == PlayerListener.END_OF_MEDIA) {<br />           try {<br />               resetplayer();<br />           } catch (MediaException me) {<br /><br />           }<br />           player = null;<br />           nextScreen();<br />       }<br /><br />   }<br /><br />   private void resetplayer() throws MediaException {<br />       if (player != null) {<br />           if (player.getState() == Player.STARTED) {<br />               player.stop();<br />           }<br />           if (player.getState() == Player.PREFETCHED) {<br />               player.deallocate();<br />           }<br />           if (player.getState() == Player.REALIZED ||<br />               player.getState() == Player.UNREALIZED) {<br />               player.close();<br />           }<br />       }<br />       player = null;<br />   }<br /><br />   private void play(String url) {<br />       try {<br />           InputStream is = getClass().getResourceAsStream(url);<br />           VideoControl vc;<br />           resetplayer();<br />           // create a player instance<br /><br />           player = Manager.createPlayer(is, this.MIMEtype);<br /><br />           player.prefetch();<br />           player.addPlayerListener(this);<br />           // realize the player<br />           player.realize();<br /><br />           vc = (VideoControl) player.getControl("VideoControl");<br />           if (vc != null) {<br /><br />               vc.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);<br />              vc.setDisplayLocation(((this.getWidth() - vc.getDisplayWidth()) /<br />                                  2),<br />                                   (this.getHeight() - vc.getDisplayHeight()) /<br />                                  2);<br /><br /><br />               vc.setVisible(true);<br /><br />               this.setFullScreenMode(true);<br />           }<br />           player.prefetch();<br />           player.start();<br />           this.display.setCurrent(this);<br />       } catch (Throwable t) {<br /><br />           player = null;<br />           nextScreen();<br />       }<br />   }<br /><br />   private void stopPlayer() {<br />       try {<br />           resetplayer();<br />       } catch (MediaException me) {<br /><br />       }<br />       player = null;<br /><br />   }<br />}<br />

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


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


License

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