public void playSound(AudioInputStream stream, float volume) {
    init();
    // Walk the pending requests.
    for (var i = headIndex; i != tailIndex; i = (i + 1) % MAX_PENDING) {
      var playMessage = getPendingAudio()[i];
      if (playMessage.getStream() == stream) {
        // Use the larger of the two volumes.
        playMessage.setVolume(Math.max(volume, playMessage.getVolume()));

        // Don't need to enqueue.
        return;
      }
    }
    getPendingAudio()[tailIndex] = new PlayMessage(stream, volume);
    tailIndex = (tailIndex + 1) % MAX_PENDING;
  }
@Test
  void testPlaySound() throws UnsupportedAudioFileException, IOException, InterruptedException {
    audio.playSound(audio.getAudioStream("./etc/Bass-Drum-1.wav"), -10.0f);
    // test that service is started
    assertTrue(audio.isServiceRunning());
    // adding a small pause to be sure that the sound is ended
    Thread.sleep(5000);

    audio.stopService();
    // test that service is finished
    assertFalse(audio.isServiceRunning());
  }