Removed sonar issue and converted Audio to eager singleton for simplicity
This commit is contained in:
@ -23,6 +23,9 @@
|
|||||||
|
|
||||||
package com.iluwatar.event.queue;
|
package com.iluwatar.event.queue;
|
||||||
|
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
@ -38,6 +41,8 @@ import javax.sound.sampled.UnsupportedAudioFileException;
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Audio {
|
public class Audio {
|
||||||
|
private static final Logger LOGGER = LoggerFactory.getLogger(Audio.class);
|
||||||
|
private static final Audio INSTANCE = new Audio();
|
||||||
|
|
||||||
private static final int MAX_PENDING = 16;
|
private static final int MAX_PENDING = 16;
|
||||||
|
|
||||||
@ -55,7 +60,7 @@ public class Audio {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static Audio getInstance() {
|
public static Audio getInstance() {
|
||||||
return SingletonHolder.getAudioInstance();
|
return INSTANCE;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -141,14 +146,11 @@ public class Audio {
|
|||||||
clip.open(audioStream);
|
clip.open(audioStream);
|
||||||
clip.start();
|
clip.start();
|
||||||
} catch (LineUnavailableException e) {
|
} catch (LineUnavailableException e) {
|
||||||
System.err.println("Error occoured while loading the audio: The line is unavailable");
|
LOGGER.trace("Error occoured while loading the audio: The line is unavailable", e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
System.err.println("Input/Output error while loading the audio");
|
LOGGER.trace("Input/Output error while loading the audio", e);
|
||||||
e.printStackTrace();
|
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (IllegalArgumentException e) {
|
||||||
System.err.println("The system doesn't support the sound: " + e.getMessage());
|
LOGGER.trace("The system doesn't support the sound: " + e.getMessage(), e);
|
||||||
e.printStackTrace();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,11 +174,4 @@ public class Audio {
|
|||||||
return pendingAudio;
|
return pendingAudio;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static class SingletonHolder {
|
|
||||||
private static final Audio INSTANCE = new Audio();
|
|
||||||
|
|
||||||
static Audio getAudioInstance() {
|
|
||||||
return INSTANCE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user