Could not realize media player
I am using this code to run avi file using jmf but the error come like "Could not realize media player"
and how to open all video format using jmf
import javax.media.*;
import javax.media.format.*;
import java.io.*;
import java.util.*;
public class Test{
public static void main(String a[]) throws Exception{
CaptureDeviceInfo di = null;
Player p = null;
Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
if (deviceList.size() > 0){
di = (CaptureDeviceInfo)deviceList.firstElement();
System.out.println((di.getLocator()).toExternalForm());
}else{
System.out.println("Exiting");
System.exit(-1);
}
try{
p = Manager.createPlayer(di.getLocator());
}catch (IOException 开发者_如何学Goe){
System.out.println(e);
}catch (NoPlayerException e) {
System.out.println(e);
}
System.out.println("Playing Started");
p.start();
}
}
My guess is that it has something to do with your JMF install. Are you running Windows? If so, I have reworked your code. Give it a shot. It will tell you if the dlls needed for video playback are in their correct locations.
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package javaapplication13;
/**
*
* @author dvargo
*/
import javax.media.*;
import javax.media.format.*;
import java.io.*;
import java.util.*;
public class Test {
final static String windowsDllFolder = "C:\\WINDOWS\\system32\\";
final static String[] windowsDllList = new String[]{
"jmacm.dll",
"jmam.dll",
"jmcvid.dll",
"jmdaud.dll",
"jmdaudc.dll",
"jmddraw.dll",
"jmfjawt.dll",
"jmg723.dll",
"jmgdi.dll",
"jmgsm.dll",
"jmh261.dll",
"jmh263enc.dll",
"jmjpeg.dll",
"jmmci.dll",
"jmmpa.dll",
"jmmpegv.dll",
"jmutil.dll",
"jmvcm.dll",
"jmvfw.dll",
"jmvh263.dll",
"jsound.dll"};
/**
* Verifies that all the dll's that JMF needs are in their correct spot
* @return True if all dlls are in their correct spot, false otherwise
*/
public static boolean detectDlls()
{
boolean retVal = true;
String currFile;
for(String currDll : windowsDllList)
{
currFile = windowsDllFolder + currDll;
if(! new File(currFile).exists())
{
retVal = false;
}
}
return retVal;
}
public static void main(String a[]) throws Exception {
boolean JMFsetUp = detectDlls();
if(JMFsetUp == false)
{
System.err.println("Missing DLLS");
}
else
{
System.out.println("JMF Should be working");
}
CaptureDeviceInfo di = null;
Player p = null;
Vector deviceList = CaptureDeviceManager.getDeviceList(new AudioFormat("linear", 44100, 16, 2));
if (deviceList.size() > 0) {
di = (CaptureDeviceInfo) deviceList.firstElement();
System.out.println((di.getLocator()).toExternalForm());
} else {
System.out.println("Exiting");
System.exit(-1);
}
try {
p = Manager.createPlayer(di.getLocator());
} catch (IOException e) {
System.out.println(e);
} catch (NoPlayerException e) {
System.out.println(e);
}
System.out.println("Playing Started");
p.start();
}
}
Assuming you installed JMF correctly and you are able to use JMStudio to view and capture videos then you are okay to go.
Please check your CaptureDeviceManager code snippet. What is the basis for search and which AVI file do you want to play?
Try this code snippet...
public static void main(String[] args) throws Exception {
File f = new File("C:\\test.avi"); //Substitute the name of the file
Player p = Manager.createRealizedPlayer(f.toURI().toURL());
Component c = p.getVisualComponent();
Frame frame = new Frame("JMF AVI Player");
frame.setState(Frame.MAXIMIZED_BOTH);
frame.add(c);
frame.pack();
p.start();
frame.setVisible(true);
}
After you download the jmf-2_1_1e-alljava
JAR file, extract the files like you would do any zip folder depending on you operating system.
- Open your project in the editor that you use,
- right-click and select build path,
- select libraries,
- Select Add JAR/Files,
- navigate to where you saved you jmf file,
- double click the file,
- select lib.
There you will see what looks like a bunch of jars. Click on one of them to open it. It will appear in the large panel before your eyes.
You have to do this for each and every jar; did you hear me: each and everyone of them.
When you're done click OK, and "Bam", you should be good to go.
Have fun!
精彩评论