Core Java| JSP| Servlets| XML| EJB| JEE5| Web Services| J2ME| Glossary| Questions?

 

 

 

 

 

 

 

 

 

 

 

 

 

Search Tutorials

Latest Questions
Comments
 
J2ME Video Control Example 
 

This Application explain the use of Video Control. The work of video control is used to controls the display of video.

 

J2ME Video Control Example

                         

This Application explain the use of Video Control. The work of video control is used to controls the display of video. In this example we want to show you, how to capture the video clip. The below source code shows you  to create the player and capture the video.

 

 

 

 

 

Player player = Manager.createPlayer("capture://video");

 There are the following methods are used in the Video Control:

  • getDisplayHeight()
  • getDisplayWidth()
  • getDisplayX()
  • getDisplayY()
  • getSnapshot(java.lang.String imageType)
  • getSourceHeight()
  • getSourceWidth()
  • initDisplayMode(int mode, java.lang.Object arg)
  • setDisplayFullScreen(boolean fullScreenMode)
  • setDisplayLocation(int x, int y)
  • setDisplaySize(int width, int height)
  • setVisible(boolean visible)

To see details about video follow this link: http://www.roseindia.net/j2me/video-midlet.shtml 

The application is as follows:

 

 

VideoControlExample.java

 
import java.io.IOException;
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.MIDlet;
import javax.microedition.media.control.VideoControl;

public class VideoControlExample extends MIDlet implements CommandListener{
  private Display display;
    private Form form;
    private Command exit, back, capture, camera;
    private Player player;
    private VideoControl videoControl;
    private Video video;
    
    public VideoControlExample() {
    display = Display.getDisplay(this);
    form = new Form("Capture Video");
        exit = new Command("Exit", Command.EXIT, 0);
        camera = new Command("Camera", Command.SCREEN, 1);
        back = new Command("Back", Command.BACK, 2);
        capture = new Command("Capture", Command.SCREEN, 3);        
        form.addCommand(camera);
        form.setCommandListener(this);
    }
    
    public void startApp() {        
        display.setCurrent(form);
    }
    
    public void pauseApp() {}
    
    public void destroyApp(boolean unconditional){
    notifyDestroyed();
  }
    
    public void commandAction(Command c, Displayable s){
    String label = c.getLabel();
        if (label.equals("Exit")){
            destroyApp(true);
        else if (label.equals("Camera")) {
            showCamera();
        else if (label.equals("Back"))
            display.setCurrent(form);
        else if (label.equals("Capture")) {
            video = new Video(this);
            video.start();
        }
    }
    
    public void showCamera(){
        try{
            player = Manager.createPlayer("capture://video");
            player.realize();            
            videoControl = (VideoControl)player.getControl("VideoControl");
            Canvas canvas = new VideoCanvas(this, videoControl);
            canvas.addCommand(back);
            canvas.addCommand(capture);
            canvas.setCommandListener(this);
            display.setCurrent(canvas);
            player.start();
        catch (IOException ioe) {} catch (MediaException me) {}
    }
    
    class Video extends Thread {
        VideoControlExample midlet;
        public Video(VideoControlExample midlet) {
            this.midlet = midlet;
        }
        
        public void run() {
            captureVideo();            
        }
        
        public void captureVideo() {
            try {
                byte[] photo = videoControl.getSnapshot(null);
                Image image = Image.createImage(photo, 0, photo.length);
                form.append(image);
                display.setCurrent(form);                
                player.close();
                player = null;
                videoControl = null;
            catch (MediaException me) { }
        }
    };
}

class VideoCanvas extends Canvas {
    private VideoControlExample midlet;
    
    public VideoCanvas(VideoControlExample midlet, VideoControl videoControl) {
        int width = getWidth();
        int height = getHeight();
        this.midlet = midlet;
        
        videoControl.initDisplayMode(VideoControl.USE_DIRECT_VIDEO, this);
        try {
            videoControl.setDisplayLocation(22);
            videoControl.setDisplaySize(width - 4, height - 4);
        catch (MediaException me) {}
        videoControl.setVisible(true);
    }
    
    public void paint(Graphics g) {
        int width = getWidth();
        int height = getHeight();
        
        g.setColor(25500);
        g.drawRect(00, width - 1, height - 1);
        g.drawRect(11, width - 3, height - 3);
    
}

Download Source Code

                         

» View all related tutorials
Related Tags: c file list table time hash mobile object map screen hashtable maps display key value this id keys oo wav

Leave your comment:

Name:

Email:

URL:

Title:

Comments:


Enter Code:

Audio Version
Reload Image
 

Note: Emails will not be visible or used in any way, and are not required. Please keep comments relevant. Any content deemed inappropriate or offensive may be edited and/or deleted.

No HTML code is allowed. Line breaks will be converted automatically. URLs will be auto-linked. Please use BBCode to format your text.

Add This Tutorial To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Training Courses
Tell A Friend
Your Friend Name
Software Solutions
Least Viewed
Most Rated
Recently Viewed
Search Tutorials

 

 
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net  | Site Map

India News

Indian Software Development Company | iPhone Development Company in India | Flex Development Company in India | Java Training Delhi | Java Training at Noida |

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2008. All rights reserved.