Doddy
Broken In
Hi
i have the current code:
import sun.audio.*; //import the sun.audio package
import java.io.*;
import javax.swing.*;
class Sound {
private AudioStream as;
public void play(String item){
try{
InputStream in = new FileInputStream("Resources" + File.separator + "Music" + File.separator + item + ".wav");
// Create an AudioStream object from the input stream.
//AudioStream
as = new AudioStream(in);
AudioPlayer.player.stop(as);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException f)
{
JOptionPane.showMessageDialog(null,"No such file was found in the Music Folder.",
"No File", JOptionPane.INFORMATION_MESSAGE);
}
catch(IOException io)
{
io.printStackTrace();
}
}
public void stop()
{
try
{
AudioPlayer.player.stop(as);
}
catch(Exception e)
{
}
}
}
I have hardcoded ".wav" as this is the only format that the sound class will play. I was wondering does anyone know the code to play .mp3 files? or even how i could simply adjust this code to play mp3 files. After all mp3's are way smaller in size - even if the quality it a small bit degraded.
i have the current code:
import sun.audio.*; //import the sun.audio package
import java.io.*;
import javax.swing.*;
class Sound {
private AudioStream as;
public void play(String item){
try{
InputStream in = new FileInputStream("Resources" + File.separator + "Music" + File.separator + item + ".wav");
// Create an AudioStream object from the input stream.
//AudioStream
as = new AudioStream(in);
AudioPlayer.player.stop(as);
AudioPlayer.player.start(as);
}
catch(FileNotFoundException f)
{
JOptionPane.showMessageDialog(null,"No such file was found in the Music Folder.",
"No File", JOptionPane.INFORMATION_MESSAGE);
}
catch(IOException io)
{
io.printStackTrace();
}
}
public void stop()
{
try
{
AudioPlayer.player.stop(as);
}
catch(Exception e)
{
}
}
}
I have hardcoded ".wav" as this is the only format that the sound class will play. I was wondering does anyone know the code to play .mp3 files? or even how i could simply adjust this code to play mp3 files. After all mp3's are way smaller in size - even if the quality it a small bit degraded.