[英]Audio does not play in JMF framework in java
当我运行此代码时,没有任何反应。 但是没有错误。 我现在用的是跨平台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();
}
}
请帮助我发现错误!!!!
您提供了mp3
文件,但仅jmf
不能播放mp3。
为此,您必须使用mp3plugin.jar文件,下载jar,然后将其添加到classpath中,然后重试,并使用您的代码可以播放.wav文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.