PRETESTING
We will perform preliminary tests in order to create a more easily understood. For this it is necessary to consider the recommendations of the first part of this issue. Let's create a Java application that displays different capture devices for video and audio formats installed on your computer. In my case I will use NetBeans 6.9, however it is not necessary to have it installed, you can even use any other development environment for our example, taking into consideration that we must add to our classpath (classpath ) the jmf.jar file to make use of classes of the package. So if you're using NetBeans to create the example we can add the file to our classpath as follows: taking the project created right click on the Library folder that is displayed on the left of the folder tree and select the option " Add JAR / Folder " as shown in the figure below:
In the dialog that appears navigate to the file jmf. jar, as default location should be " / Program Files/JMF2.1.1e/lib/jmf.jar . Seleccionanos the file and click on the Open button. Then we'll be in a position to make use of Media Framework classes. As mentioned above, the following example loads the video capture devices installed and audio formats in the system. Remember to know what kind of format is necessary to manage your device check in the file "JMF Registry.
import java.io.BufferedReader;
import java.io.IOException;
import java. io.InputStreamReader;
import java.util.Vector;
javax.media.CaptureDeviceInfo import, import
javax.media.CaptureDeviceManager;
/ / FORMATS
javax.media.format.AudioFormat import; Import
javax.media.format.JPEGFormat;
javax.media.format.RGBFormat import, import
javax.media.format.VideoFormat;
{public class
private Devices Devices () {
bl = new BufferedReader ( new InputStreamReader (System.in));
FORMATO_AUDIO = new AudioFormat (AudioFormat.LINEAR)
JPEGFormat FORMATO_JPEG = new ();
FORMATO_VIDEO = new videoformat (VideoFormat.CINEPAK)
RGBFormat FORMATO_RGB = new ();}
private static int menu ()
{int opt \u200b\u200b= 0, index;
System.out.println ("\\ t-*- MENU OPTIONS -*- \\ n ");
for (index = 0; index < opciones.length; indice ++ )
System.out.println ((index + 1) +" .- "+ options [index]);
System.out.print (" Which option you choose? ");
try
{opc = Integer.parseInt (bl.readLine ());
} catch (NumberFormatException exc) {
opt = menu ();
} catch (IOException exc) {
opt = menu ();}
System.out.println ();
return opt;
} public static void main ( String args []) {
ban boolean = false;
int opt;
new Device ();
devices = new Vector ();
do
{
opt = menu ();
dispositivos.setSize (0) ;
switch (opt)
{case 1:
devices = CaptureDeviceManager.getDeviceList (FORMATO_AUDIO)
break;
case 2:
devices = CaptureDeviceManager.getDeviceList (FORMATO_JPEG)
break;
case 3:
dispositivos = CaptureDeviceManager.getDeviceList( FORMATO_VIDEO );
break;
case 4:
dispositivos = CaptureDeviceManager.getDeviceList( FORMATO_RGB );
break;
}
if( opc != opciones.length )
if( dispositivos.size() > 0 )
for( CaptureDeviceInfo d : dispositivos )
System.out.println( "UBICACIÓN:\t" + d.getLocator() + "\nNOMBRE:\t"
+ d.getName() + "\n" );
else
System.out.println ("\\ nThe format is specified devices"
+ "installed on the computer!");}
while (opt! = Opciones.length)
} private static String options [] = {"FORMATO_AUDIO", "FORMATO_JPEG"
"FORMATO_VIDEO", "FORMATO_RGB", "EXIT"} private static BufferedReader
bl;
< CaptureDeviceInfo > private static Vector devices;
AudioFormat FORMATO_AUDIO private static;
JPEGFormat private static FORMATO_JPEG ;
videoformat FORMATO_VIDEO private static;
FORMATO_RGB RGBFormat private static;}
0 comments:
Post a Comment