* BAEL-4292:Play sound in java * BAEL-4292:Play sound in java * BAEL-4292: Play sound in java * BAEL-4292:Play sound in java * BAEL-4292:Play sound in java * BAEL-4292:Play sound in java * fix for spaces Co-authored-by: Sachin kumar <sachin.n.kumar@oracle.com>
31 lines
968 B
Java
31 lines
968 B
Java
package com.baeldung;
|
|
|
|
import java.io.BufferedInputStream;
|
|
|
|
import javazoom.jl.player.Player;
|
|
|
|
public class SoundPlayerUsingJavaZoom {
|
|
|
|
public static void main(String[] args) {
|
|
|
|
// javazoom Player doesn't work with wav audio format.
|
|
// String audioFilePath = "AudioFileWithWavFormat.wav";
|
|
|
|
// It works with below audio formats.
|
|
// String audioFilePath = "AudioFileWithMpegFormat.mpeg";
|
|
String audioFilePath = "AudioFileWithMp3Format.mp3";
|
|
SoundPlayerUsingJavaZoom player = new SoundPlayerUsingJavaZoom();
|
|
|
|
try {
|
|
BufferedInputStream buffer = new BufferedInputStream(player.getClass()
|
|
.getClassLoader()
|
|
.getResourceAsStream(audioFilePath));
|
|
Player mp3Player = new Player(buffer);
|
|
mp3Player.play();
|
|
|
|
} catch (Exception ex) {
|
|
System.out.println("Error occured during playback process:" + ex.getMessage());
|
|
}
|
|
}
|
|
}
|