Playing a sound at regular intervals
David DeHaven
david.dehaven at oracle.com
Tue Aug 23 14:15:40 UTC 2016
> We're trying to play a notification sound at a regular interval (every 500ms) in a loop.
>
> It should sound like "bing.bing.bing." and not like "bing......bing..bing...bing" if you know what I mean ;)
>
> From the JavaDoc we were guessing that an efficient way to do this would be to set cycle count to indefinite on the audio clip / on the media player and call play() once.
>
> Observations:
> - Cycle count doesn't work for mp3 files. No problem, just use WAV.
> - The playback does not happen at regular intervals. -> not usable in this scenario
>
> Our solution so far has been to have a scheduled executor which calls audioclip.play() every 500 ms. This creates a new thread every time (see stack trace below) and we don't like this approach.
For the moment this is a better solution, until we can get a few internal things fixed in AudioClip.
In the current implementation there will always be at least one new thread created.
There are bugs filed on this already, specifically:
https://bugs.openjdk.java.net/browse/JDK-8090414
https://bugs.openjdk.java.net/browse/JDK-8087423
And possibly related:
https://bugs.openjdk.java.net/browse/JDK-8088375
-DrD-
More information about the openjfx-dev
mailing list