Introduction
The Java™ Media Framework is a framework for handling streaming media (video/audio) using the Java™ programming language. This framework allows us to acquire, process and deliver multimedia content from a variety of sources. A part this framework provides access to image capture using Webcams (internal or external).
Installation
The installation downloads are available here
http://www.oracle.com/technetwork/java/javase/tech/index-jsp-140239.html
Windows
The downloads section contains a windows installer (power pack installer) that simplifies the installation process. Default setting will install the library to
“C:\Program Files\JMF2.1.1e” on 32 Bit OS or
“C:\Program Files (x86)\JMF2.1.1e\” on 64 Bit OS
Ubuntu Linux
The download offered (power pack installer) for Linux has a problem which could result in failed installation and a zero sized file replacing the original download file. To overcome this, see this forum post http://ubuntuforums.org/archive/index.php/t-1137722.html. The steps for a successful install are as follows
- Download the .bin file from here
- Rename the .bin to a .zip and extract the contents
$ mv jmf-2_1_1e-linux-i586.bin jmf-2_1_1e-linux-i586.zip $ unzip jmf-2_1_1e-linux-i586.zip
- Rename the .zip file back to .bin
$ mv jmf-2_1_1e-linux-i586.zip jmf-2_1_1e-linux-i586.bin
- add execute permissions
$ chmod +x jmf-2_1_1e-linux-i586.bin
- run the installer
$ ./jmf-2_1_1e-linux-i586.bin
The installation should complete successfully.
Configuring the IDE
Netbeans
- Open Menu->Tools->Libraries
- Click “New Library”
- Enter “JMF” as new library name and click “OK”
- Click “Add JAR/Folder”
- Browse to lib subdirectory in the installation folder:“C:\Program Files\JMF2.1.1e\lib” on 32 Bit OS or
“C:\Program Files (x86)\JMF2.1.1e\lib” on 64 Bit OSand select all the jar files to add to the library. - Incase you have downloaded the documentation (.zip)select the “Javadoc” tab, Click “Add Zip/Folder”, select the zip file to enable popup help during auto completion.
- Click “OK” to save the settings and dismiss the dialog.
Eclipse
- Open Menu->Window->Preferences
- Select Java->Build Path->User Libraries
- Select “New” and enter “JMF” as the name of the library and click “OK”
- Select “Add Jars”
- Browse to lib subdirectory in the installation folder:“C:\Program Files\JMF2.1.1e\lib” on 32 Bit OS or
“C:\Program Files (x86)\JMF2.1.1e\lib” on 64 Bit OS
- Select All jar files and click “Open” to add the jars to user library.
Writing your first application
Netbeans
- Create a new project.
- Open “Projects” View.
- Right Click “Libraries” folder.
- Select “Add Library”.
- Select “JMF” library created in previous step.
- Click “OK” to add the library reference.
- Use the below code to scan for cameras (internal/external)
package testapp; import java.util.Vector; import javax.media.CaptureDeviceManager; public class CaptureDeviceEnumerator { public static void main(String[] args) { System.out.println("Scanning for devices ..."); Vector deviceList = CaptureDeviceManager.getDeviceList(null); System.out.format("%1$s devices detected.\n", deviceList.size()); for (Object device : deviceList) { System.out.println(device); } } }
Eclipse
- Create a new java project
- In the java settings page, select the libraries tab and click the “Add Library”
- Select the “User Library” option
- Select the JMF library and select finish
- Add a new class and use the above code to test the library
Conclusion
This post should be able to guide you to download, install, configure and test the JMF library. My next post will be on doing something more useful such as capturing an image and doing some processing.