无法实现媒体播放器

时间:2010-12-31 21:21:37

标签: jmf

我正在使用此代码使用jmf运行avi文件 但错误就像“无法实现媒体播放器”

以及如何使用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 e){
            System.out.println(e);
    }catch (NoPlayerException e) {
        System.out.println(e);
    }
    System.out.println("Playing Started");
    p.start();
}
}

3 个答案:

答案 0 :(得分:0)

我的猜测是它与你的JMF安装有关。你在运行Windows吗?如果是这样,我已经重新编写了代码。试一试。它会告诉您视频播放所需的dll是否在正确的位置。


/*
 * 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();
    }
}


答案 1 :(得分:0)

假设您正确安装了JMF并且您可以使用JMStudio查看和捕获视频,那么您可以继续使用。

请检查您的CaptureDeviceManager代码段。搜索的基础是什么,以及您想要播放哪个AVI文件?

试试此代码段...

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);
}

答案 2 :(得分:0)

下载jmf-2_1_1e-alljava JAR文件后,根据您的操作系统提取文件,就像执行任何zip文件夹一样。在您使用的编辑器中打开项目,右键单击并选择构建路径,选择库,选择Add JAR / Files,导航到保存jmf文件的位置,双击该文件,选择lib。在那里你会看到看起来像一堆罐子,点击其中一个打开它,它会出现在你面前的大面板中,你必须为每个罐子做这个,你听到了吗,你和我他们每个人,当你完成后点击OK,然后" Bam",你应该好好去,玩得开心!..