Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/GhettoGirl/chatty
Browse files Browse the repository at this point in the history
[Changed to be compatible with Java7]
  • Loading branch information
tduva committed Apr 21, 2016
2 parents 562c58d + 0b9ea15 commit 8f69749
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 1 deletion.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@ build/
dist/
nbproject/
working_directory/
out/
chatty.iml
.idea/
META-INF/
12 changes: 11 additions & 1 deletion src/chatty/util/Sound.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ public static void play(String fileName, float volume, String id, int delay) {
AudioInputStream ais = AudioSystem.getAudioInputStream(file);

DataLine.Info info = new DataLine.Info(Clip.class, ais.getFormat());
Clip clip = (Clip)AudioSystem.getLine(info);
final Clip clip = (Clip)AudioSystem.getLine(info);
clip.open(ais);

// Volume, use what is available
Expand All @@ -60,6 +60,16 @@ public static void play(String fileName, float volume, String id, int delay) {
volumeInfo = "no volume control";
}

clip.addLineListener(new LineListener() {

@Override
public void update(LineEvent event) {
if (event.getType() == LineEvent.Type.STOP) {
clip.close();
}
}
});

clip.start();
LOGGER.info("Playing sound "+id+"/"+fileName+" ("+volumeInfo+")");
} catch (NullPointerException | LineUnavailableException | IOException | UnsupportedAudioFileException ex) {
Expand Down

0 comments on commit 8f69749

Please sign in to comment.