0

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.

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!!!!

Knight of Ni
  • 1,780
  • 3
  • 20
  • 47
Tamojit Chatterjee
  • 161
  • 1
  • 1
  • 10
  • Does your code work with the MP3 files seen on [this page](http://pscode.org/media/#sound)? BTW - it is not necessary to add the entire JMF to the run-time class-path in order to play an MP3. Part of JMF (one Jar) is a Service Provider Interface for decoding MP3. Add that alone to the run-time class-path, and Java Sound should then be able to play an MP3. – Andrew Thompson Nov 29 '13 at 01:08
  • i have only added the jmf.jar file to the classpath. – Tamojit Chatterjee Nov 29 '13 at 14:38
  • Well I'd guess that is the problem. Dump the JMF Jar, add the SPI & do this with Java Sound. See the [info. page](http://stackoverflow.com/tags/javasound/info) for details. – Andrew Thompson Nov 29 '13 at 14:41

1 Answers1

-1

You have given a mp3 file but jmf alone can't play 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.

Community
  • 1
  • 1
Prabir
  • 66
  • 8