0

I want to play an audio file when certain conditions are met but I can't figure it out. I am inexperienced in java and programming in general and copied several blocks of code and none of them work.

Trying to play this:
File type: .mp3
Location: C:\Users\Public\Music\Sample Music

I wasted close to two hours on this. Plz help with code that just plays audio from a file. Thank you.

Update: I keep getting this error
Multiple markers at this line - Access restriction: The type AudioStream is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre1.8.0_25\lib\rt.jar - Access restriction: The type AudioStream is not accessible due to restriction on required library C:\Program Files (x86)\Java\jre1.8.0_25\lib\rt.jar - Access restriction: The constructor AudioStream(InputStream) is not accessible due to restriction on required library C:\Program Files (x86)\Java

user3144079
  • 159
  • 3
  • 12

2 Answers2

1

Check Xuggle or jLayer.

Google them and you will come up with nice results.

Good >> http://kxhitiz.blogspot.com.tr/2010/09/playing-mp3-in-java-programming.html

Java Jlayer Mp3 Player - how to repeat and stop song

Community
  • 1
  • 1
Soley
  • 1,716
  • 1
  • 19
  • 33
0
  public class JavaAudioPlaySoundExample
 {
  public static void main(String[] args) 
  throws Exception
  {
// open the sound file as a Java input stream
String gongFile = "/Users/al/DevDaily/Projects/MeditationApp/resources/gong.au";
InputStream in = new FileInputStream(gongFile);

// create an audiostream from the inputstream
AudioStream audioStream = new AudioStream(in);

// play the audio clip with the audioplayer class
AudioPlayer.player.start(audioStream);
 }
}
parajs dfsb
  • 145
  • 2
  • 4
  • 13