Saturday, May 31, 2025

[JAVA] PLAY MUSIC

import javax.sound.sampled.*;import java.io.File;public class AudioPlayer { public static void main(String[] args) { try { File audioFile = new File("path/to/your/audio.wav"); // Replace with your file path AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audioFile); Clip clip = AudioSystem.getClip(); clip.open(audioInputStream); clip.start(); // Keep the program running so the audio can play Thread.sleep(clip.getMicrosecondLength() / 1000); } catch (Exception e) { e.printStackTrace(); } }}

No comments: