Module: Toybox.Audio.Output

Overview

The Output module provides APIs for playing audio on the device.

Since:

API Level 6.0.3

Requires Permission:

  • AudioOutput

Classes Under Namespace

Classes: DynamicAudioSource, DynamicAudioSourceBuilder, StreamingAudioSource

Constant Summary

Error

Since:

API Level 6.0.3

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.

PlaybackState

Since:

API Level 6.0.3

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

Typedef Details

AudioSource as Audio.AudioResource or Output.StreamingAudioSource or Output.DynamicAudioSource

Since:

API Level 6.0.3

Instance Method Details

decrementVolume(step as Lang.Number) as Void

Decrement the volume.

This is equivalent to setVolume(getVolume() - step)

Note:

This will not set the volume to a value less than 0.

Parameters:

  • step — (Lang.Number) —

    The percentage points to subtract from the volume.

Since:

API Level 6.0.3

getError() as Output.Error or Null

Get the error that occurred during playback.

Note:

The error state is cleared when a new source is played.

Returns:

  • Output.Error —

    The error that occurred during the last playback, or null if there is no error.

Since:

API Level 6.0.3

getPosition() as Lang.Number

Get the current playback position in milliseconds.

Returns:

Since:

API Level 6.0.3

getState() as Output.PlaybackState

Get the current playback state.

Returns:

Since:

API Level 6.0.3

incrementVolume(step as Lang.Number) as Void

Increment the volume.

This is equivalent to setVolume(getVolume() + step)

Note:

This will not set the volume to a value greater than 100.

Parameters:

  • step — (Lang.Number) —

    The percentage points to add to the volume.

Since:

API Level 6.0.3

pause() as Void

Stop playing audio without resetting the position.

Since:

API Level 6.0.3

play(audio as Output.AudioSource, startPosition as Lang.Number or Null) as Void

Start playing an audio source.

Parameters:

Since:

API Level 6.0.3

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

Note:

The callback is only called when a source is playing. It is not called while playback is stopped or paused.

Parameters:

  • period — (Lang.Number) —

    The period at which the handler is called in milliseconds.

  • callback — (Lang.Method) —

    The callback. If this is null, clear any previously registered callback.

Since:

API Level 6.0.3

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

Parameters:

  • callback — (Lang.Method) —

    The callback. If this is null, clear any previously registered callback.

Since:

API Level 6.0.3

resume() as Void

Start playing the last played audio source without resetting the position.

Since:

API Level 6.0.3

seekPosition(position as Lang.Number) as Void

Set the playback position.

Parameters:

  • position — (Lang.Number) —

    The playback position in milliseconds.

Since:

API Level 6.0.3

setVolume(volume as Lang.Number) as Void

Set the playback volume.

Parameters:

  • volume — (Lang.Number) —

    The volume percentage from 0 to 100.

Since:

API Level 6.0.3

Throws:

start() as Void

Start playing the last played audio source.

This resets the position to 0 before playing.

Since:

API Level 6.0.3

stop() as Void

Stop playing audio.

This resets the position to 0.

Since:

API Level 6.0.3


Generated Oct 19, 2026, 4:16:38 PM