java mp3 player while code is running code example

Example: java mp3 player while code is running

THIS IS JUST ONE OF MANY OPTIONS
For this to work, you have to download and add
the .jar file linked in the source.

import javazoom.jl.player.*;
import java.io.FileInputStream;

public class PlaySomeMusic{
		
	public static void main(String[] args) {

        try{

             FileInputStream fis = new FileInputStream("Music.mp3");
             Player playMP3 = new Player(fis);

             playMP3.play();

        }  catch(Exception e){
             System.out.println(e);
           }
    }
}


If your new to programming, you might be wondering how you can play the song
while your code is running, because right now, whenever you issue the 
playMP3.play();
command, the programm waits for the mp3 file to be finished and then
continues running your code. 
To solve this, just read up on Java Threads on the internet, 
because it allows you to run multiple things at the same time.

Tags:

Misc Example