Académique Documents
Professionnel Documents
Culture Documents
MalformedURLExc; public class SimpleAudioPlayer { private Player audioPlayer = null; public SimpleAudioPlayer(URL url) throws IOException, NoPlayerException, CannotRealizeException { audioPlayer = Manager.createRealizedPlayer(url); } public SimpleAudioPlayer(File file) throws IOException, NoPlayerException, CannotRealizeException { this(file.toURL()); } public void play() { audioPlayer.start(); } public void stop() { audioPlayer.stop(); audioPlayer.close(); } public static void main(String[] args) { try{ File audioFile = new File("/t.mp3"); SimpleAudioPlayer player = new SimpleAudioPlayer(audioFile); System.out.println(); System.out.println("-> Playing file '" + audioFile.getAbsolutePath() + "'"); System.out.println(" Press the Enter key to exit"); player.play(); // wait for the user to press Enter to proceed. System.in.read(); System.out.println("-> Exiting"); player.stop(); }catch(Exception ex){ ex.printStackTrace(); } System.exit(0); } }