Package org.openhab.core.audio
Class AudioSinkSync
java.lang.Object
org.openhab.core.audio.AudioSinkSync
- All Implemented Interfaces:
AudioSink
Definition of an audio output like headphones, a speaker or for writing to
a file / clip.
Helper class for synchronous sink : when the process() method returns,
the source is considered played, and could be disposed.
Any delayed tasks can then be performed, such as volume restoration.
- Author:
- Gwendal Roulleau - Initial contribution
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
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
processSynchronously
(@Nullable AudioStream audioStream) Processes the passedAudioStream
and returns only when the playback is ended.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
-
Constructor Details
-
AudioSinkSync
public AudioSinkSync()
-
-
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
-
processSynchronously
protected abstract void processSynchronously(@Nullable AudioStream audioStream) throws UnsupportedAudioFormatException, UnsupportedAudioStreamException Processes the passedAudioStream
and returns only when the playback is ended. 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
-