22 package com.realtime.crossfire.jxclient.sound;
25 import java.io.IOException;
26 import javax.sound.sampled.AudioInputStream;
27 import javax.sound.sampled.AudioSystem;
28 import javax.sound.sampled.Clip;
29 import javax.sound.sampled.DataLine;
30 import javax.sound.sampled.Line;
31 import javax.sound.sampled.LineUnavailableException;
32 import javax.sound.sampled.UnsupportedAudioFileException;
33 import org.jetbrains.annotations.NotNull;
34 import org.jetbrains.annotations.Nullable;
73 public DataLine
allocateClip(@Nullable
final String name, @NotNull
final String action) {
81 public void freeClip(@NotNull
final Line clip) {
82 if (debugSound != null) {
95 private DataLine
newClip(@Nullable
final String name, @NotNull
final String action) {
97 try (
final AudioInputStream audioInputStream = AudioSystem.getAudioInputStream(audioFileLoader.
getInputStream(name, action))) {
100 clip = AudioSystem.getClip();
101 clip.open(audioInputStream);
102 }
catch (
final IllegalArgumentException ex) {
103 final UnsupportedAudioFileException ex2 =
new UnsupportedAudioFileException(ex.getMessage());
107 if (debugSound != null) {
108 debugSound.
debugProtocolWrite(
"newClip: "+System.identityHashCode(clip)+
" "+name+
"/"+action);
112 }
catch (
final UnsupportedAudioFileException ex) {
113 if (debugSound != null) {
117 }
catch (
final LineUnavailableException ex) {
118 if (debugSound != null) {
122 }
catch (
final IOException ex) {
123 if (debugSound != null) {
Allocates new sound clips.
DataLine newClip(@Nullable final String name, @NotNull final String action)
Allocates a new clip.
DataLine allocateClip(@Nullable final String name, @NotNull final String action)
Allocates a new clip.
final DebugWriter debugSound
The writer for logging sound related information or.
void debugProtocolWrite(@NotNull final CharSequence str)
Writes a message to the debug protocol.
Writer debug information to a log file.
InputStream getInputStream(@Nullable final String name, @NotNull final String action)
Returns an input stream for an audio file.
final AudioFileLoader audioFileLoader
The AudioFileLoader for loading audio files.
ClipCache(@NotNull final AudioFileLoader audioFileLoader, @Nullable final DebugWriter debugSound)
Creates a new instance.
void freeClip(@NotNull final Line clip)
Deallocates a clip.