Status
Not open for further replies.

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.
 

demoninside

In the zone
my friend as we know .wav is an standred format(means not a coded format)
so we run it that easyly
but when it comes about mp3 we need a decoder plugin as it'a an encoded format.
so it wouldn't be easy but try get decoder inwork (don't knowhw to do it now)
then u'll be able to play mp3
 
OP
Doddy

Doddy

Broken In
#/bin/sh

just at first glance it looks a bit excessive - is theie an easier way? Excuse my ignorance
 
Status
Not open for further replies.
Top Bottom