JMF Playing an audio error
Hi,
I am getting below error while player.start() code
Actually there are three file involved in it and they are
1) ExampleJMF.java
2) exampleFrame.java
3) examplePanle
ExampleJMF.java
Code:
//package org.jmf.example;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;
import javax.swing.plaf.metal.MetalLookAndFeel;
public class ExampleJMF
{
public static void main(String[] args)
{
JFrame.setDefaultLookAndFeelDecorated(true);
JDialog.setDefaultLookAndFeelDecorated(true);
try
{
UIManager.setLookAndFeel(new MetalLookAndFeel());
}
catch(UnsupportedLookAndFeelException e)
{
e.printStackTrace();
}
exampleFrame exampleFrame = new exampleFrame();
}
}
exampleFrame.java
Code:
//package org.jmf.example;
import java.awt.Toolkit;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JFrame;
public class exampleFrame extends JFrame
{
private static final long serialVersionUID = 1L;
public exampleFrame()
{
super("JMF - Example...");
setSize(400, 300);
setLocation((Toolkit.getDefaultToolkit().getScreenSize().width - getWidth())/2, (Toolkit.getDefaultToolkit().getScreenSize().height - getHeight())/2);
addWindowListener(new WindowAdapter()
{
public void windowClosing(WindowEvent evt)
{
System.exit(0);
}
});
setContentPane(new examplePanel());
setVisible(true);
}
}
examplePanel.java
Code:
//package org.jmf.example;
import java.awt.Component;
import java.awt.Graphics;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import javax.media.ControllerEvent;
import javax.media.ControllerListener;
import javax.media.Manager;
import javax.media.NoPlayerException;
import javax.media.Player;
import javax.media.RealizeCompleteEvent;
import javax.swing.JPanel;
public class examplePanel extends JPanel implements ActionListener, ControllerListener
{
private static final long serialVersionUID = 1L;
private Component visualComponent;
private Player player;
public examplePanel()
{
try
{
player = Manager.createPlayer(new URL("file:///E:/movies/Engeyum-Eppodhum/Govinda.mp3"));
//player = Manager.createPlayer(new URL("/Govinda.mp3"));
player.addControllerListener(this);
player.start();
}
catch(NoPlayerException e)
{
e.printStackTrace();
}
catch(MalformedURLException e)
{
e.printStackTrace();
}
catch(IOException e)
{
e.printStackTrace();
}
}
public void paintComponent(Graphics g)
{
super.paintComponent(g);
}
public void actionPerformed(ActionEvent e)
{
}
public void controllerUpdate(ControllerEvent c)
{
if(player == null) {
return;
}
if(c instanceof RealizeCompleteEvent)
{
if((visualComponent = player.getVisualComponent()) != null) {
add(visualComponent);
}
}
}
}
Code:
java.lang.ArrayIndexOutOfBoundsException: 15
at codecLib.mpa.k.a(Unknown Source)
at codecLib.mpa.k.do(Unknown Source)
at codecLib.mpa.Decoder.decode(Unknown Source)
at com.sun.media.codec.audio.mpa.JavaDecoder.process(JavaDecoder.java:327)
at com.sun.media.BasicFilterModule.process(BasicFilterModule.java:322)
at com.sun.media.BasicModule.connectorPushed(BasicModule.java:69)
at com.sun.media.BasicOutputConnector.writeReport(BasicOutputConnector.java:120)
at com.sun.media.SourceThread.process(BasicSourceModule.java:729)
at com.sun.media.util.LoopThread.run(LoopThread.java:135)
BUILD SUCCESSFUL (total time: 10 seconds)
Re: JMF Playing an audio error
Well, it's more or less impossible for me (perhaps anyone) to help you out since you don't provide us with the relevant code. The error is obviously an ArrayIndexOutOfBounds which is self explanatory I assume, and it's on line 15. Since you said the problem is in player.start(); on your line 34, I guess the line numbers aren't the same as in your IDE.
If you get this error and want help, don't you think it's a good idea to provide the code for the class Player where the actual error is?
Re: JMF Playing an audio error
Hi Zyril,
Now I have added the three files that are all invloved and there files are called in the below order
1) ExampleJMF.java
2) exampleFrame.java
3) examplePanle
Thanks for your reply