Audio
Audio
#
Bases: Service
A control to simultaneously play multiple audio sources.
RAISES | DESCRIPTION |
---|---|
AssertionError
|
If both |
Note
This control is non-visual and should be added to
Page.services
list before it can be used.
autoplay
#
autoplay: bool = False
Starts playing audio as soon as audio control is added to a page.
Note
Autoplay works in desktop, mobile apps and Safari browser, but doesn't work in Chrome/Edge.
balance
#
balance: Number = 0.0
Defines the stereo balance.
-1
- The left channel is at full volume; the right channel is silent.1
- The right channel is at full volume; the left channel is silent.0
- Both channels are at the same volume.
on_duration_change
#
on_duration_change: (
EventHandler[AudioDurationChangeEvent] | None
) = None
Fires as soon as audio duration is available (it might take a while to download or buffer it).
on_loaded
#
on_loaded: ControlEventHandler[Audio] | None = None
Fires when an audio is loaded/buffered.
on_position_change
#
on_position_change: (
EventHandler[AudioPositionChangeEvent] | None
) = None
Fires when audio position is changed. Will continuously update the position of the playback every 1 second if the status is playing.
Can be used for a progress bar.
on_seek_complete
#
on_seek_complete: ControlEventHandler[Audio] | None = None
Fires on seek completions. An event is going to be sent as soon as the audio seek is finished.
on_state_change
#
on_state_change: (
EventHandler[AudioStateChangeEvent] | None
) = None
Fires when audio player state changes.
page
#
The page (of type Page
or PageView
) to which this control belongs to.
parent
#
parent: BaseControl | None
The direct ancestor(parent) of this control.
It defaults to None
and will only have a value when this control is mounted (added to the page tree).
The Page
control (which is the root of the tree) is an exception - it always has parent=None
.
playback_rate
#
playback_rate: Number = 1.0
Defines the playback rate.
Should ideally be set when creating the constructor.
Note
- iOS and macOS have limits between
0.5x
and2x
. - Android SDK version should be 23 or higher.
src
#
src: str | None = None
The audio source. Can be a URL or a local asset file.
Note
- At least one of
src
orsrc_base64
must be provided, withsrc_base64
having priority if both are provided. - Here is a list of supported audio formats.
volume
#
volume: Number = 1.0
Sets the volume (amplitude).
It's value ranges between 0.0
(mute) and 1.0
(maximum volume).
Intermediate values are linearly interpolated.
get_current_position_async
#
get_duration_async
#
Get audio duration of the audio playback.
It will be available as soon as the audio duration is available (it might take a while to download or buffer it if file is not local).
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
Duration | None
|
The duration of audio playback. |
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
pause
#
pause(timeout: float | None = 10)
Pauses the audio that is currently playing.
If you call resume()
or
resume_async()
later,
the audio will resume from the point that it has been paused.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
pause_async
#
pause_async(timeout: float | None = 10)
Pauses the audio that is currently playing.
If you call resume()
or
resume_async()
later,
the audio will resume from the point that it has been paused.
play
#
play(
position: DurationValue = Duration(),
timeout: float | None = 10,
)
Starts playing audio from the specified position
.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to start playback from.
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
play_async
#
play_async(
position: DurationValue = Duration(),
timeout: float | None = 10,
)
Starts playing audio from the specified position
.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to start playback from.
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
release
#
release(timeout: float | None = 10)
Releases the resources associated with this media player.
These are going to be fetched or buffered again as soon as
you change the source or call resume()
or
resume_async()
.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
release_async
#
release_async(timeout: float | None = 10)
Releases the resources associated with this media player.
These are going to be fetched or buffered again as soon as
you change the source or call resume()
or
resume_async()
.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
resume
#
resume(timeout: float | None = 10)
Resumes the audio that has been paused or stopped.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
resume_async
#
resume_async(timeout: float | None = 10)
Resumes the audio that has been paused or stopped.
PARAMETER | DESCRIPTION |
---|---|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
seek
#
seek(position: DurationValue, timeout: float | None = 10)
Moves the cursor to the desired position.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to seek/move to.
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |
seek_async
#
seek_async(
position: DurationValue, timeout: float | None = 10
)
Moves the cursor to the desired position.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to seek/move to.
TYPE:
|
timeout
|
The maximum amount of time (in seconds) to wait for a response.
TYPE:
|
RAISES | DESCRIPTION |
---|---|
TimeoutError
|
If the request times out. |