BAEL-4292:Play sound in java (#12004)

* 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>
This commit is contained in:
sachin
2022-05-28 08:48:22 +05:30
committed by GitHub
parent 95e8ee82ec
commit 6919cc8f62
9 changed files with 244 additions and 0 deletions

View File

@@ -0,0 +1,30 @@
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());
}
}
}