Package org.openhab.core.audio
Class AudioSinkAsync
java.lang.Object
org.openhab.core.audio.AudioSinkAsync
- All Implemented Interfaces:
AudioSink
Definition of an audio output like headphones, a speaker or for writing to
a file / clip.
Helper class for asynchronous sink : when the process() method returns, the
AudioStream
may or may not be played. It is the responsibility of the implementing AudioSink class to
complete the CompletableFuture when playing is done. Any delayed tasks will then be performed, such as volume
restoration.- Author:
- Gwendal Roulleau - Initial contribution
-
Field Summary
Modifier and TypeFieldDescriptionprotected final Map
<AudioStream, CompletableFuture<@Nullable Void>> -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
playbackFinished
(AudioStream audioStream) Will complete the future previously returned, allowing the core to run delayed task.void
process
(@Nullable AudioStream audioStream) Processes the passedAudioStream
If the passedAudioStream
is not supported by this instance, anUnsupportedAudioStreamException
is thrown.CompletableFuture
<@Nullable Void> processAndComplete
(@Nullable AudioStream audioStream) Processes the passedAudioStream
, and returns a CompletableFuture that should complete when the sound is fully played.protected abstract void
processAsynchronously
(@Nullable AudioStream audioStream) Processes the passedAudioStream
asynchronously.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface org.openhab.core.audio.AudioSink
getId, getLabel, getSupportedFormats, getSupportedStreams, getVolume, setVolume
-
Field Details
-
runnableByAudioStream
-
-
Constructor Details
-
AudioSinkAsync
public AudioSinkAsync()
-
-
Method Details
-
processAndComplete
Description copied from interface:AudioSink
Processes the passedAudioStream
, and returns a CompletableFuture that should complete when the sound is fully played. It is the sink responsibility to complete this future. If the passedAudioStream
is not supported by this instance, anUnsupportedAudioStreamException
is thrown. If the passedAudioStream
has anAudioFormat
not supported by this instance, anUnsupportedAudioFormatException
is thrown. In case the audioStream is null, this should be interpreted as a request to end any currently playing stream. When the stream is not needed anymore, if the stream implements theDisposable
interface, the sink should hereafter get rid of it by calling the dispose method.- Specified by:
processAndComplete
in interfaceAudioSink
- Parameters:
audioStream
- the audio stream to play or null to keep quiet- Returns:
- A future completed when the sound is fully played. The method can instead complete with UnsupportedAudioFormatException if the audioStream format is not supported, or UnsupportedAudioStreamException If audioStream is not supported
-
process
public void process(@Nullable AudioStream audioStream) throws UnsupportedAudioFormatException, UnsupportedAudioStreamException Description copied from interface:AudioSink
Processes the passedAudioStream
If the passedAudioStream
is not supported by this instance, anUnsupportedAudioStreamException
is thrown. If the passedAudioStream
has anAudioFormat
not supported by this instance, anUnsupportedAudioFormatException
is thrown. In case the audioStream is null, this should be interpreted as a request to end any currently playing stream. When the stream is not needed anymore, if the stream implements theDisposable
interface, the sink should hereafter get rid of it by calling the dispose method.- Specified by:
process
in interfaceAudioSink
- Parameters:
audioStream
- the audio stream to play or null to keep quiet- Throws:
UnsupportedAudioFormatException
- If audioStream format is not supportedUnsupportedAudioStreamException
- If audioStream is not supported
-
processAsynchronously
protected abstract void processAsynchronously(@Nullable AudioStream audioStream) throws UnsupportedAudioFormatException, UnsupportedAudioStreamException Processes the passedAudioStream
asynchronously. This method is expected to return before the stream is fully played. This is the sink responsibility to call theplaybackFinished(AudioStream)
when it is. If the passedAudioStream
is not supported by this instance, anUnsupportedAudioStreamException
is thrown. If the passedAudioStream
has anAudioFormat
not supported by this instance, anUnsupportedAudioFormatException
is thrown. In case the audioStream is null, this should be interpreted as a request to end any currently playing stream.- Parameters:
audioStream
- the audio stream to play or null to keep quiet- Throws:
UnsupportedAudioFormatException
- If audioStream format is not supportedUnsupportedAudioStreamException
- If audioStream is not supported
-
playbackFinished
Will complete the future previously returned, allowing the core to run delayed task.- Parameters:
audioStream
- The AudioStream is the key to find the delayed CompletableFuture in the storage.
-