DIGIT-ARC read-only archive · snapshot: July 23, 2026

mp3

6 posts · originally from https://geek.digit.in/community/threads/mp3.4509/

Doddy
Doddy Original post #1
Jan 9, 2005 at 6:31 PM
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.
D
Jan 9, 2005 at 11:06 PM
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
#/bin/sh
Jan 10, 2005 at 12:05 AM
*www.javaworld.com/javaworld/jw-11-2000/jw-1103-mp3.html
Doddy
Doddy #4
Jan 10, 2005 at 12:45 PM
#/bin/sh

just at first glance it looks a bit excessive - is theie an easier way? Excuse my ignorance
#/bin/sh
Jan 10, 2005 at 2:42 PM
by default java does not support mp3, to support it you need to add a service provider.
#/bin/sh
Jan 10, 2005 at 2:44 PM
Maybe the project PlayList Editor at *lightdev.dyndns.org can inspire you