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: 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: ft.Number = 0.0
#
Sets 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.
data: Any = skip_field()
#
Arbitrary data of any type that can be attached to a control.
key: str | int | float | bool | ValueKey | ScrollKey | None = None
#
on_duration_change: ft.OptionalEventHandler[AudioDurationChangeEvent[Audio]] = None
#
Fires as soon as audio duration is available (it might take a while to download or buffer it).
Event handler argument is of type AudioDurationChangeEvent
.
on_loaded: ft.OptionalControlEventHandler[Audio] = None
#
Fires when an audio is loaded/buffered.
on_position_change: ft.OptionalEventHandler[AudioPositionChangeEvent[Audio]] = 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.
Event handler argument is of type AudioPositionChangeEvent
.
on_seek_complete: ft.OptionalControlEventHandler[Audio] = None
#
Fires on seek completions. An event is going to be sent as soon as the audio seek is finished.
on_state_change: ft.OptionalEventHandler[AudioStateChangeEvent[Audio]] = None
#
Fires when audio player state changes.
Event handler argument is of type AudioStateChangeEvent
.
page: Page | PageView | None
#
The page (of type Page
or PageView
) to which this control belongs to.
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: ft.Number = 1.0
#
Sets 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.
release_mode: ReleaseMode = ReleaseMode.RELEASE
#
Sets the release mode.
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.
src_base64: str | None = None
#
volume: ft.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() -> ft.Duration | None
#
Get the current position of the audio playback.
RETURNS | DESCRIPTION |
---|---|
Duration | None
|
The current position of the audio playback. |
get_duration_async() -> ft.Duration | None
#
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).
RETURNS | DESCRIPTION |
---|---|
Duration | None
|
The duration of audio playback. |
pause()
#
Pauses the audio that is currently playing.
If you call [resume()
][.resume] or [resume_async()
][.resume_async] later,
the audio will resume from the point that it has been paused.
pause_async()
#
Pauses the audio that is currently playing.
If you call [resume()
][.resume] or [resume_async()
][.resume_async] later,
the audio will resume from the point that it has been paused.
play(position: ft.DurationValue = ft.Duration())
#
Starts playing audio from the specified position
.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to start playback from.
TYPE:
|
play_async(position: ft.DurationValue = ft.Duration())
#
Starts playing audio from the specified position
.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to start playback from.
TYPE:
|
release()
#
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()
][.resume] or [resume_async()
][.resume_async].
release_async()
#
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()
][.resume] or [resume_async()
][.resume_async].
resume()
#
Resumes the audio that has been paused or stopped.
resume_async()
#
Resumes the audio that has been paused or stopped.
seek(position: ft.DurationValue)
#
Moves the cursor to the desired position.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to seek/move to.
TYPE:
|
seek_async(position: ft.DurationValue)
#
Moves the cursor to the desired position.
PARAMETER | DESCRIPTION |
---|---|
position
|
The position to seek/move to.
TYPE:
|