Skip to main content

Audio

A control to simultaneously play multiple audio files. Works on macOS, Linux, Windows, iOS, Android and web. Based on audioplayers Flutter widget.

Audio control is non-visual and should be added to page.overlay list.

Packaging

To build your Flet app that uses Audio control add flet-audio to dependencies key of the [project] section of your pyproject.toml file, for example:

[project]
...
dependencies = [
"flet==0.27.6",
"flet-audio==0.1.0",
]

Examples​

Live example

Autoplay audio​

note

Autoplay works in desktop, mobile apps and Safari browser, but doesn't work in Chrome/Edge.

python/controls/utility/audio/audio-autoplay.py
loading...

Audio with playback controls​

python/controls/utility/audio/audio-player.py
loading...

Properties​

autoplay​

Starts playing audio as soon as audio control is added to a page.

Value is of type bool and defaults to False.

note

Autoplay works in desktop, mobile apps and Safari browser, but doesn't work in Chrome/Edge.

balance​

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.

Value is of type OptionalNumber.

note

Setting balance is supported on Windows and Linux only.

playback_rate​

Sets the playback rate. iOS and macOS have limits between 0.5 and 2x Android SDK version should be 23 or higher.

Value is of type OptionalNumber.

release_mode​

Sets the release mode.

Value is of type ReleaseMode and defaults to ReleaseMode.RELEASE.

src​

The audio source. Can be a URL or a local asset file.

note

Here is a list of supported audio formats.

src_base64​

Sets the contents of audio file encoded in base-64 format.

Value is of type str.

volume​

Sets the volume (amplitude).

0 is mute and 1 is the max volume. The values between 0 and 1 are linearly interpolated.

Value is of type OptionalNumber.

Methods​

get_current_position()​

Returns the current position in milliseconds.

get_duration()​

Returns the duration of audio in milliseconds.

pause()​

Stops playing audio.

play()​

Starts playing audio for the beginning.

release()​

Stops playing and releases the resources associated with this audio control. The resources are going to be fetched or buffered again as soon as you call resume() or change the source.

resume()​

Resumes playing audio from the current position.

seek()​

Moves the cursor to the desired position.

Method arguments:

  • position_milliseconds - desired position in milliseconds.

Events​

on_duration_changed​

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​

Fires when an audio is loaded/buffered.

on_position_changed​

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​

Fires on seek completions. An event is going to be sent as soon as the audio seek is finished.

on_state_changed​

Fires when audio player state changes.

Event handler argument is of type AudioStateChangeEvent.