Skip to content

Commit

Permalink
Adding method that could play a sound file. No external libraries used.
Browse files Browse the repository at this point in the history
Issue - iluwatar#108
  • Loading branch information
deepikasidana committed May 4, 2022
1 parent cc96a00 commit 2ef0c29
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -583,6 +583,33 @@ public static int calculateLuhnChecksum(long num) {
}
```

### Play sound

```java
public static void playSound(String soundFile) throws IOException, UnsupportedAudioFileException, LineUnavailableException {
File f = new File("./" + soundFile);
AudioInputStream audioIn = null;
Clip clip = null;
try {
audioIn = AudioSystem.getAudioInputStream(f.toURI().toURL());
clip = AudioSystem.getClip();
clip.open(audioIn);
clip.start();
FloatControl volume = (FloatControl)clip.getControl(FloatControl.Type.MASTER_GAIN);
volume.setValue(1.0f); // Reduce volume by 10 decibels.
clip.drain();
}
finally {
try {
clip.close();
}
catch (Exception exp) {
exp.printStackTrace();
}
}
}
```

## Networking

### HTTP GET
Expand Down

0 comments on commit 2ef0c29

Please sign in to comment.