简体   繁体   English

音频无法在Java的JMF框架中播放

[英]Audio does not play in JMF framework in java

when i am running this code nothing get's played. 当我运行此代码时,没有任何反应。 But there is no error. 但是没有错误。 I am using the cross platform JMF 2.1.1 and have imported JMF.jar file in my netbeans project. 我现在用的是跨平台JMF 2.1.1和我的NetBeans项目有进口JMF.jar文件。

import javax.swing.*;
import java.awt.*;
import javax.media.*;
import java.awt.event.*;
import java.net.*;

public class HelloJMF {

    JFrame frame = new JFrame(" Hello JMF Player");
    static Player helloJMFPlayer = null;

    public HelloJMF() {

        try { // method using URL 
            URL url = new URL("file", null, "C:\\Users\\Tamojit9\\Documents\\NetBeansProjects\\MediaPlayer\\src\\sample\\gunaah.mp3");
            helloJMFPlayer = Manager.createRealizedPlayer(url);
        } catch (Exception e) {
            System.out.println(" Unable to create the audioPlayer :" + e);
        }

        Component control = helloJMFPlayer.getControlPanelComponent();

        frame.getContentPane().add(control, BorderLayout.CENTER);
        frame.addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent we) {
                HelloJMF.stop();
                System.exit(0);
            }
        });
        frame.pack();
        frame.setSize(new Dimension(200, 50));
        frame.setVisible(true);
        helloJMFPlayer.start();

    }

    public static void stop() {
        helloJMFPlayer.stop();
        helloJMFPlayer.close();
    }

    public static void main(String args[]) {
        HelloJMF helloJMF = new HelloJMF();
    }
}

Please help me in finding the error!!!! 请帮助我发现错误!!!!

You have given a mp3 file but jmf alone can't play mp3. 您提供了mp3文件,但仅jmf不能播放mp3。
For that you have to use mp3plugin.jar file, download the jar and then add to classpath then try again and with your code you can play .wav files. 为此,您必须使用mp3plugin.jar文件,下载jar,然后将其添加到classpath中,然后重试,并使用您的代码可以播放.wav文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM