Skip to content
This repository has been archived by the owner on Aug 20, 2022. It is now read-only.

Commit

Permalink
Fix for sound buffer.
Browse files Browse the repository at this point in the history
  • Loading branch information
mpaterakis committed Jan 5, 2020
1 parent e239f43 commit 18539f2
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/Sound/SoundPlayer.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package Sound;

import java.io.BufferedInputStream;
import java.io.IOException;
import javax.sound.sampled.AudioInputStream;
import javax.sound.sampled.AudioSystem;
Expand All @@ -19,15 +20,14 @@ public class SoundPlayer {
* @param soundType The type of sound to be played
*/
public static synchronized void playSound(final SoundTypes soundType) {
String soundFile = getFileName(soundType);
new Thread(new Runnable() {
// The wrapper thread is unnecessary, unless it blocks on the
// Clip finishing; see comments.
@Override
public void run() {
try {
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(getClass().getResourceAsStream("/Files/Sounds/" + soundFile));
AudioInputStream inputStream = AudioSystem.getAudioInputStream(new BufferedInputStream(getClass().getResourceAsStream("/Files/Sounds/" + getFileName(soundType))));
clip.open(inputStream);
clip.start();
} catch (IOException | LineUnavailableException | UnsupportedAudioFileException e) {
Expand Down

0 comments on commit 18539f2

Please sign in to comment.