intelliproject logo

Location: Mobile Development - J2ME    License: The Intelliproject Open License (IPOL)

Capturing Video on J2ME devices

Posted by Silviu Caragea

Describe how can you take pictures on a J2ME device

Skill: Intermediate

Posted: 12/10/2008

Views: 2129

Rating: 3.75 /5

Popularity: 2.26

Sign Up to vote for this article

Introduction

The Mobile Media API extends the functionality of the J2ME platform by providing audio, video, and other time-based multimedia support to resource-constrained devices. As a simple and lightweight optional package, it gives Java developers access to native multimedia services available on a given device.

j2me_capture.jpg

Source Code for Capturing Video on J2ME devices

The Manager class is the static factory class in the MMAPI. The createPlayer() method is the factory method used to create Player instances.

The following function creates a Player instance. Because J2ME compatibility between different manufacturers can differ we trying to create the player through several parameters.
If the mobile phone is equipped with several cameras, you can specify which camera you want to use through the int camera parameter.

The video coming from the camera can be displayed on the screen either as an Item in a Form or as part of a Canvas. A VideoControl makes this possible. To get a VideoControl, just ask the Player for it:

vc = (VideoControl) player.getControl("VideoControl");

If you wish to show the video coming from the camera in a Canvas, initialize the VideoControl, then set the size and location of the video in the Canvas, and then make the video visible.

Once the video camera is shown on the device, capturing an image is easy. All you need to do is call VideoControl's getSnapshot() and pass an image type, or null for the default type, PNG.
Also you can find the image types that are supported by your mobile phone .The video.snapshot.encodings system property contain a whitespace-delimited list with these values.

The getSnapshot() method returns an array of bytes, which is the image data in the format you requested. What you do at this point is up to you: you might save the bytes in a record store, send them to a server, or create an Image from them.

imgBytes = vc.getSnapshot("encoding=jpeg"/*+videoOptions*/);

Through the videoOption you can specify the width and height of the captured image. For example videoOption =”&width=640&height=480”.

Note:Not all mobile devices support these parameters (width & height).

 

License

This article, along with any associated source code and files, is licensed under The Intelliproject Open License (IPOL)

About the author

Silviu Caragea

Silviu Caragea is the Founder, Administrator and Chief Editor who wrote and runs The IntelliProject.

He's been programming since 2000 and now he's student at The Faculty of Economic Cybernetics, Statistics and Informatics from Bucharest. In the same time he's working as software developer at Cratima Software, a Romanian software and web design company that activates both on the local and foreign market, providing its customers with software development services, internet and intranet solutions, web design, graphic design and IT consultancy.

His programming experience includes:
- C,C++, Visual C++(Win32 API, MFC, ADO, STL, DAO, ODBC, ATL, COM, DirectShow, DirectDraw, WTL)
- Open Source libraries :CURL & Boost
- HTML, CSS
- Java (SE,ME)
- JavaScript, Ajax, Google Web Toolkit (GWT)
- Php, MySQL
-Oracle, PL SQL
- C# .NET
-Objective C, IPhone SDK, Cocoa

Location: Romania
Ocupation: Software Engineer
Home page: http://www.intelliproject.net

Sign up to post message on the article message board!