hi...
I have ".txt" files and ".mp3" files in java/bin.
When i open txt file the audio file must be played.
I have attached my code below..but i get error on compling..so can anyone pls help me in fixing the bugs..
thanks...
import java.io.BufferedInputStream;
import java.io.*;
import java.io.FileInputStream;
import javazoom.jl.player.Player;
public class MP3 {
private String filename;
private Player player;
// constructor that takes the name of an MP3 file
public MP3(String filename) {
this.filename = filename;
}
public void close() { if (player != null) player.close(); }
// play the MP3 file to the sound card
public void play() {
try {
FileInputStream fis = new FileInputStream(filename);
BufferedInputStream bis = new BufferedInputStream(fis);
player = new Player(bis);
}
catch (Exception e) {
System.out.println("Problem playing file " + filename);
System.out.println(e);
}
// run in new thread to play in background
new Thread() {
public void run() {
try { player.play(); }
catch (Exception e) { System.out.println(e); }
}
}.start();
}
// test client
public static void main(String[] args) {
String targetExtension=".mp3";
if(args.length >= 1 )
{//1
String ext =args[0].substring(args[0].indexOf("."));
System.out.println(ext);
if(ext.equalsIgnoreCase(".txt"))
{//2
File f = new File(args[0]);
//if the file exists
// then change the filename
if(f.exists())
{//3
args[0]=args[0].replace(ext,targetExtension);
System.out.println(" "+args[0]);
File filename = new File(args[0]);
f.renameTo(filename);
MP3 mp3 = new MP3(filename);
mp3.play(); mp3.close();
}}}}