How to Make a Video Player for Java Phones
With the maturity of mobile technology and the Java Me programming profile, many limitations of the past have been eliminated. There are two parts to multimedia processing in the application programming interface: protocol handing (reading data from a file or streaming server), and content handling (parsing the media data and displaying it on an output device such as a Java-enabled phone). The multimedia API provides two object types for conducting operations: the Data Source--this class contains the handing of the protocol and allows the player object to manipulate the data--and the player, an output device than can differentiate between file and media types.
Instructions
-
-
1
Include the classes from the Java ME API required for creating the video player. In this example, the following classes are used:
import javax.microedition.lcdui.*;
import javax.microedition.media.*;
import javax.microedition.media.control.*;
import javax.microedition.midlet.*; -
2
Create an instance of the Player and VideoControl classes.
Player myPlayer;
VideoControl myVideoController; -
-
3
Create a video player with the manager class through the static create-player call. In this example, the Uniform Resource Locator for the MPG movie is hard-coded into the sample, but can also be passed to the player dynamically based on user choice. The create-player call is called in a try loop to handle potential exceptions.
try {
myPlayer = Manager.createPlayer("http://www.rjsmunford.com/testmovie.mpg"); -
4
Obtain control of the video controller through the realize() method call and use of the video-control class static get-control method call.
myPlayer.realize();
myVideoController = (VideoControl)myPlayer.getControl("VideoControl"); -
5
Start the video player and end the try loop.
myPlayer.start();
} // end the try loop -
6
Catch Input and Media exceptions that can result from the video player instantiation.
catch(IOException myIOException) {
}
catch(MediaException myMediaE) {
}
-
1
Tips & Warnings
This example only plays video files on java phones. Research the API to add handling for video capture, mp3 playing and other options. Download the phone emulator for the targeted Java phone you are coding the video player for to test code prior to deployment
Do not forget to handle exceptions for unpredictable results when playing video on java phones.
Resources
- Photo Credit Screen shot taken by the author.