Mobile video with JME and MMAPI, Part 2

Send and receive video files in your Java mobile applications

In the first half of this article, you learned how to use JME and the Mobile Media API to build a Java application capable of taking advantage of the video cameras built in to many popular mobile devices today. Now author Srijeeb Roy shows you how to extend the application to upload video files to a remote server and download them back to the device. The result is a Java application that allows video-enabled devices to communicate with the wider world.

This article is the second half of an introduction to using JSR-135 and the Mobile Media API (MMAPI) to support video recording on a Java-enabled mobile device. In the first part of this article, you learned the basics of the MMAPI. You also learned about the MMAPI-specific system properties, and saw how to record a video on a mobile device. You also saw how to use the PlayerListener interface to trap the events generated by a Player at different stages in the application's life cycle.

In this article, we will upload a video recorded on a mobile device to a server, and will fetch that video back from the server to play it on the mobile device. Before you start, you should have already read "Mobile video with JME and MMAPI, Part 1" and have handy the code you developed in the course of that article. You can also download this article's sample code for use in the following examples.

Uploading the recorded video to a server

In this section, we'll see how to upload our recorded video to a server. To do this, on the MIDlet side we will use the Generic Connection Framework (GCF) to establish a HTTP connection; on the server side, we will host a servlet through which we will upload our recorded video to the server. We'll use the same servlet later in this article to fetch the stored video and play it on the mobile device.

Changes required on the MIDlet side

We will need an address for the server to which we will connect. Thus, on the Options screen, we will add a TextField where we will accept the server address as input. Also, to make the HTTP connection using GCF, we will use a Java class called HttpCommandExecuter (this file is supplied in the source code that accompanies this article). Together with the files already discussed, you also need to copy the classes that are used to transfer the data from the mobile device to the server (our Data Transfer Objects, or DTOs):

  • Copy and from the supplied source to the <Your-WTK-Installation-Dir>/apps/MobileVideoApp/src/com/srijeeb/jme directory. (Remember, throughout this tutorial, <Your-WTK-Installation-Directory> represents the directory where you installed the Sun Java Wireless Toolkit; see Resources for a link.) Your current should be replaced by the same file supplied in the source.

  • Copy work-offline.png from the supplied source to <Your-WTK-Installation-Dir>/apps/MobileVideoApp/res/images.

  • Copy,,, and from the supplied source to the <Your-WTK-Installation-Dir>/apps/MobileVideoApp/src/com/srijeeb/dto directory. You will not need and for uploading the recorded video to the server, but has references to these objects, so you'll need them for compilation.

  • Copy from the supplied source and replace your current

In the commandAction() method of the PropertyForm, you will find some extra steps that set the server address for the HttpCommandExecuter class and our MIDlet class, as shown in Listing 1.

Listing 1. Extra steps in commandAction() to set the server address

 HttpCommandExecuter.setServiceURL("http://" + 
   serverAddress.getString().trim() + "/MMAWeb/MMAServlet");

When you run the revised application in the Wireless Toolkit, you will see an initial screen like the one displayed in Figure 1. You will find another option, named Work Offline. If the application were deployed on a real device without a wireless Internet connection, you would select this option; however, remember that you won't be able to test the server functionality we'll explore here on such device.

Wireless Toolkit emulator displaying revised PropertyForm
Figure 1. Wireless Toolkit emulator displaying revised PropertyForm
1 2 3 4 5 6 Page 1
Page 1 of 6