Module: Toybox.Audio.Output
Overview
The Output module provides APIs for playing audio on the device.
Classes Under Namespace
Classes: DynamicAudioSource, DynamicAudioSourceBuilder, StreamingAudioSource
Constant Summary
-
Error
-
PlaybackState
| Name | Value | Since | Description |
|---|---|---|---|
| OUTPUT_ERROR_UNKNOWN | 0 | API Level 6.0.3 |
An unknown error occurred during audio playback. |
| OUTPUT_ERROR_DECODING | 1 | API Level 6.0.3 |
There was an error decoding the audio source. |
| Name | Value | Since | Description |
|---|---|---|---|
| PLAYBACK_STOPPED | 0 | API Level 6.0.3 |
Playback is stopped. |
| PLAYBACK_PLAYING | 1 | API Level 6.0.3 |
Playback is in progress. |
| PLAYBACK_PAUSED | 2 | API Level 6.0.3 |
Playback is paused. |
| PLAYBACK_ERROR | 3 | API Level 6.0.3 |
An error occurred during playback. |
Typedef Summary collapse
Instance Method Summary collapse
-
decrementVolume(step as Lang.Number) as Void
Decrement the volume.
-
getError() as Output.Error or Null
Get the error that occurred during playback.
-
getPosition() as Lang.Number
Get the current playback position in milliseconds.
-
getState() as Output.PlaybackState
Get the current playback state.
-
incrementVolume(step as Lang.Number) as Void
Increment the volume.
-
pause() as Void
Stop playing audio without resetting the position.
-
play(audio as Output.AudioSource, startPosition as Lang.Number or Null) as Void
Start playing an audio source.
-
registerPeriodicUpdateHandler(period as Lang.Number, callback as Null or Lang.Method(position as Lang.Number) as Void) as Void
Register a method to be called periodically during playback.
-
registerStateChangeHandler(callback as Null or Lang.Method(newState as Output.PlaybackState) as Void) as Void
Register a method to be called when the playback state changes.
-
resume() as Void
Start playing the last played audio source without resetting the position.
-
seekPosition(position as Lang.Number) as Void
Set the playback position.
-
setVolume(volume as Lang.Number) as Void
Set the playback volume.
-
start() as Void
Start playing the last played audio source.
-
stop() as Void
Stop playing audio.
Typedef Details
AudioSource as Audio.AudioResource or Output.StreamingAudioSource or Output.DynamicAudioSource
Instance Method Details
decrementVolume(step as Lang.Number) as Void
Decrement the volume.
This is equivalent to setVolume(getVolume() - step)
This will not set the volume to a value less than 0.
getError() as Output.Error or Null
Get the error that occurred during playback.
The error state is cleared when a new source is played.
getPosition() as Lang.Number
Get the current playback position in milliseconds.
getState() as Output.PlaybackState
Get the current playback state.
incrementVolume(step as Lang.Number) as Void
Increment the volume.
This is equivalent to setVolume(getVolume() + step)
This will not set the volume to a value greater than 100.
pause() as Void
Stop playing audio without resetting the position.
play(audio as Output.AudioSource, startPosition as Lang.Number or Null) as Void
Start playing an audio source.
registerPeriodicUpdateHandler(period as Lang.Number, callback as Null or Lang.Method(position as Lang.Number) as Void) as Void
Register a method to be called periodically during playback
The callback is only called when a source is playing. It is not called while playback is stopped or paused.
registerStateChangeHandler(callback as Null or Lang.Method(newState as Output.PlaybackState) as Void) as Void
Register a method to be called when the playback state changes
resume() as Void
Start playing the last played audio source without resetting the position.
seekPosition(position as Lang.Number) as Void
Set the playback position.
setVolume(volume as Lang.Number) as Void
Set the playback volume.
start() as Void
Start playing the last played audio source.
This resets the position to 0 before playing.
stop() as Void
Stop playing audio.
This resets the position to 0.