Play a mp3 File
import jaco.mp3.player.MP3Player; import java.io.File; public class Example1 { public static void main(String[] args) { new MP3Player(new File("test.mp3")).play(); } }
... or URL
import jaco.mp3.player.MP3Player; import java.net.URL; public class Example2 { public static void main(String[] args) throws Exception { new MP3Player(new URL("http://server.com/mp3s/test.mp3")).play(); } }
Constructors accepts also multiple files
import jaco.mp3.player.MP3Player; import java.io.File; public class Example3 { public static void main(String[] args) throws Exception { File file1 = new File("test1.mp3"); File file2 = new File("test2.mp3"); File file3 = new File("test3.mp3"); new MP3Player(file1, file2, file3).play(); } }
... or URLs
import jaco.mp3.player.MP3Player; import java.net.URL; public class Example4 { public static void main(String[] args) throws Exception { URL url1 = new URL("http://server.com/mp3s/test1.mp3"); URL url2 = new URL("http://server.com/mp3s/test2.mp3"); URL url3 = new URL("http://server.com/mp3s/test3.mp3"); new MP3Player(url1, url2, url3).play(); } }
Add mp3s to play list
import jaco.mp3.player.MP3Player; import java.io.File; import java.net.URL; public class Example5 { public static void main(String[] args) throws Exception { MP3Player player = new MP3Player(); player.addToPlayList(new File("test1.mp3")); player.addToPlayList(new File("test2.mp3")); player.addToPlayList(new URL("http://server.com/mp3s/test3.mp3")); player.play(); } }
Repeat / Shuffle
import jaco.mp3.player.MP3Player; import java.io.File; public class Example6 { public static void main(String[] args) throws Exception { MP3Player player = new MP3Player(); player.addToPlayList(new File("test1.mp3")); player.addToPlayList(new File("test2.mp3")); player.addToPlayList(new File("test3.mp3")); player.setRepeat(true); player.setShuffle(true); player.play(); } }
Added as component on a GUI
import jaco.mp3.player.MP3Player; import jaco.mp3.player.plaf.MP3PlayerUICompact; import java.io.File; import java.net.URL; import javax.swing.BorderFactory; import javax.swing.JFrame; public class Example7 { public static void main(String[] args) throws Exception { // MP3Player.setDefaultUI(MP3PlayerUICompact.class); // MP3Player player = new MP3Player(); player.setRepeat(true); player.addToPlayList(new File("test.mp3")); player.addToPlayList(new File("test2.mp3")); player.addToPlayList(new File("test3.mp3")); player.addToPlayList(new URL("http://server.com/mp3s/test4.mp3")); // player.setBorder(BorderFactory.createEmptyBorder(50, 100, 50, 100)); JFrame frame = new JFrame("MP3 Player"); frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); frame.getContentPane().add(player); frame.pack(); frame.setLocationRelativeTo(null); frame.setVisible(true); } }
Added as applet on a web page
<script type="text/javascript" src="http://www.java.com/js/deployJava.js"> </script> <script type="text/javascript"> var attributes = { code : "jaco.mp3.player.MP3PlayerApplet.class", archive : "jars/jaco-mp3-player.jar", width : "86", height : "16" }; var parameters = { separate_jvm : "true", codebase_lookup : "true", background : "0xFFFFFF", compact : "false", playlist : "mp3s/01.mp3, mp3s/02.mp3, mp3s/03.mp3" }; var version = "1.6"; deployJava.runApplet(attributes, parameters, version); </script>