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.

Are there any code examples left?
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source