I was trying out the method of creating a background music for a java program, but it displayed an IO excedption error when i clicked the play button.
package javaentertainment;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.FileInputStream;
import java.io.IOException;
import javax.swing.*;
import sun.audio.AudioData;
import sun.audio.AudioPlayer;
import sun.audio.AudioStream;
public class Music
{
public static void main(String args[])
{
JFrame frame=new JFrame();
frame.setSize(100,100);
JButton button=new JButton("P L A Y");
frame.add(button);
button.addActionListener(new AL());
frame.show();
}
public static class AL implements ActionListener
{
public void actionPerformed(ActionEvent e) {
music();
}
}
public static void music()
{
AudioPlayer MGP=AudioPlayer.player;
AudioStream BGM;
AudioData MD;
ContinousAudioDataStream loop=null;
try
{
BGM = new AudioStream(new FileInputStream("Vision.wmv"));
MD=BGM.getData();
loop=new ContinousAudioDataStream(MD);
}
catch (IOException ex)
{
System.out.println(ex);
}
MGP.start(loop); // word loop was underlined by netbeans
}
}
When I run the program and click on play it displays the following error, java.io.IOException: could not create audio stream from input stream