无法实现媒体播放器

发布于 2024-10-09 21:17:36 字数 941 浏览 0 评论 0原文

我正在使用此代码使用 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();
}
}

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

原谅过去的我 2024-10-16 21:17:36

我的猜测是它与您的 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();
    }
}


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


身边 2024-10-16 21:17:36

假设您正确安装了 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);
}

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);
}
南城追梦 2024-10-16 21:17:36

下载 jmf-2_1_1e-alljava JAR 文件后,像提取任何 zip 文件夹一样提取文件,具体取决于您的操作系统。

  • 在您使用的编辑器中打开您的项目,
  • 右键单击并选择构建路径
  • 选择库,
  • 选择添加 JAR/文件,
  • 导航到保存 jmf 文件的位置,
  • 双击该文件,
  • 选择 lib 。

在那里你会看到看起来像一堆罐子的东西。单击其中之一将其打开。它将出现在您眼前的大面板中。

你必须对每个罐子都这样做;你听到我了吗:他们每个人。

完成后,单击“确定”,然后单击“Bam”,您应该可以开始了。

玩得开心!

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!

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文