Skip to content
This repository was archived by the owner on Dec 24, 2025. It is now read-only.

Commit 5611fa1

Browse files
authored
v1: Remove _async suffix from all methods, remove fire-n-forget counterparts, code improvements (#10)
* configs * remove fire-and-forget methods | remove _async in methods name * updates * update test file * fix examples
1 parent aa29c5e commit 5611fa1

17 files changed

Lines changed: 194 additions & 236 deletions

File tree

.ci/patch_pubspec_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# /// script
2+
# dependencies = ["pyyaml"]
3+
# ///
4+
15
import os
26
import pathlib
37
import sys
@@ -17,7 +21,7 @@
1721
"flet",
1822
]
1923

20-
with open(pubspec_path, "r") as f:
24+
with open(pubspec_path) as f:
2125
data = yaml.safe_load(f)
2226

2327
# patch version

.ci/patch_toml_version.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
# /// script
2+
# dependencies = ["tomlkit"]
3+
# ///
4+
15
import os
26
import pathlib
37
import sys
@@ -14,7 +18,7 @@
1418
print(f"Patching TOML file {toml_path} to {ver}")
1519

1620
# read
17-
with open(toml_path, "r") as f:
21+
with open(toml_path) as f:
1822
t = tomlkit.parse(f.read())
1923

2024
# patch version

.docstr.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
paths: src/flet_audio
2+
badge: ./docs/assets/badges/docs-coverage.svg
3+
skip_file_doc: True
4+
skip_private: False
5+
ignore_patterns: # Dict with key/value pairs of file-pattern/node-pattern
6+
.*: __post_init__ # Ignore __post_init__ in all files
7+
fail_under: 50

.github/workflows/docs.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ on:
44
push:
55
branches:
66
- main
7-
- dev
87
paths:
98
- 'LICENSE'
109
- 'CHANGELOG.md'

CHANGELOG.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,14 +23,14 @@ and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.
2323
- `on_duration_changed``on_duration_change`
2424
- `on_position_changed``on_position_change`
2525
- Method `Audio.play()` now accepts an optional `position` parameter for specifying start position.
26-
- The following sync methods were removed:
27-
- `get_duration()` → use `get_duration_async()` instead
28-
- `get_current_position()` → use `get_current_position_async()` instead
26+
- The following sync methods were made [`async`](https://docs.python.org/3/library/asyncio.html):
27+
- `get_duration()`
28+
- `get_current_position()`
2929

3030
## [0.1.0] - 2025-01-15
3131

3232
Initial release.
3333

3434

3535
[0.2.0]: https://github.com/flet-dev/flet-audio/compare/0.1.0...0.2.0
36-
[0.1.0]: https://github.com/flet-dev/flet-audio/releases/tag/0.1.0
36+
[0.1.0]: https://github.com/flet-dev/flet-audio/releases/tag/0.1.0

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,9 @@ This package supports the following platforms:
2525
| Android ||
2626
| Web ||
2727

28-
## Installation
28+
## Usage
29+
30+
### Installation
2931

3032
To install the `flet-audio` package and add it to your project dependencies:
3133

@@ -45,6 +47,6 @@ To install the `flet-audio` package and add it to your project dependencies:
4547
poetry add flet-audio
4648
```
4749

48-
## Examples
50+
### Examples
4951

50-
For examples, see [this](./examples)
52+
For examples, see [these](./examples).

appveyor.yml

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,23 +3,20 @@ image: ubuntu
33
version: '0.1.{build}'
44

55
environment:
6+
PYTHON_VERSION: 3.12
67
UV_PUBLISH_TOKEN:
78
secure: 174ncAbF5IjSIkmioPt62jeSnzmTlRNchUkE4QdjDWH8xK1olYtySXLJpo2q95HcP7lWJky1hv4APESiRRHnBWoY0XRFafzM/mbCDMzG1tZXiXZmpP1qzHAtRP2QSCIg18xh1TMktraUdTi7sbJnjjRhqzgbW1k0kLBxKw79MPFBhYQ/TiGcmaYWZbWVZNY3HCUCb6Dt7bG1OE2Ul9rD1gvs55xwO9Oq9FOVA1VnMYw=
89

9-
stack:
10-
- python 3.12
11-
1210
install:
1311
- source .ci/update_build_version.sh
14-
- python --version
15-
- python -m ensurepip --upgrade
16-
- pip3 install --upgrade tomlkit pyyaml
1712
- curl -LsSf https://astral.sh/uv/install.sh | sh
18-
- export PATH=$HOME/.local/bin:$PATH
13+
- export PATH="$HOME/.local/bin:$PATH"
14+
- uv python install $PYTHON_VERSION
15+
- uv python pin $PYTHON_VERSION
1916

2017
build_script:
21-
- python .ci/patch_toml_version.py pyproject.toml $PYPI_VER
22-
- python .ci/patch_pubspec_version.py src/flutter/flet_*/pubspec.yaml $PKG_VER
18+
- uv run .ci/patch_toml_version.py pyproject.toml $PYPI_VER
19+
- uv run .ci/patch_pubspec_version.py src/flutter/flet_*/pubspec.yaml $PKG_VER
2320
- (cd src/flutter/* && dart pub get && dart analyze && cd -)
2421
- uv build
2522

@@ -32,4 +29,4 @@ deploy_script:
3229
artifacts:
3330
- path: dist/*.whl
3431

35-
test: off
32+
test: off

docs/audio.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,7 @@
1-
::: flet_audio.Audio
1+
## Examples
2+
3+
```python title="example_1.py"
4+
--8<-- "examples/audio_example/src/example_1.py"
5+
```
6+
7+
::: flet_audio.Audio

docs/index.md

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,18 +46,16 @@ To install the `flet-audio` package and add it to your project dependencies:
4646

4747
??? note "Windows Subsystem for Linux (WSL)"
4848
On WSL, you need to install [`GStreamer`](https://github.com/GStreamer/gstreamer) library.
49-
50-
If you receive `error while loading shared libraries: libgstapp-1.0.so.0`,
49+
50+
If you receive `error while loading shared libraries: libgstapp-1.0.so.0`,
5151
it means `GStreamer` is not installed in your WSL environment.
52-
52+
5353
To install it, run the following command:
54-
54+
5555
```bash
5656
apt install -y libgstreamer1.0-0 gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-bad gstreamer1.0-plugins-ugly gstreamer1.0-libav gstreamer1.0-tools
5757
```
5858

59-
## Example
59+
### Examples
6060

61-
```python title="main.py"
62-
--8<-- "examples/audio_example/src/main.py"
63-
```
61+
See [these](audio.md#examples).
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import flet as ft
2+
3+
import flet_audio as fta
4+
5+
6+
def main(page: ft.Page):
7+
url = "https://github.com/mdn/webaudio-examples/blob/main/audio-analyser/viper.mp3?raw=true"
8+
9+
async def play(e: ft.Event[ft.ElevatedButton]):
10+
await audio.play()
11+
12+
async def pause(e: ft.Event[ft.ElevatedButton]):
13+
await audio.pause()
14+
15+
async def resume(e: ft.Event[ft.ElevatedButton]):
16+
await audio.resume()
17+
18+
async def release(e: ft.Event[ft.ElevatedButton]):
19+
await audio.release()
20+
21+
def set_volume(value: float):
22+
audio.volume += value
23+
24+
def set_balance(value: float):
25+
audio.balance += value
26+
27+
async def seek_2s(e: ft.Event[ft.ElevatedButton]):
28+
await audio.seek(ft.Duration(seconds=2))
29+
30+
async def get_duration(e: ft.Event[ft.ElevatedButton]):
31+
duration = await audio.get_duration()
32+
print("Duration:", duration)
33+
34+
async def on_get_current_position(e: ft.Event[ft.ElevatedButton]):
35+
position = await audio.get_current_position()
36+
print("Current position:", position)
37+
38+
audio = fta.Audio(
39+
src=url,
40+
autoplay=False,
41+
volume=1,
42+
balance=0,
43+
on_loaded=lambda _: print("Loaded"),
44+
on_duration_change=lambda e: print("Duration changed:", e.duration),
45+
on_position_change=lambda e: print("Position changed:", e.position),
46+
on_state_change=lambda e: print("State changed:", e.state),
47+
on_seek_complete=lambda _: print("Seek complete"),
48+
)
49+
page.services.append(audio)
50+
51+
page.add(
52+
ft.ElevatedButton("Play", on_click=play),
53+
ft.ElevatedButton("Pause", on_click=pause),
54+
ft.ElevatedButton("Resume", on_click=resume),
55+
ft.ElevatedButton("Release", on_click=release),
56+
ft.ElevatedButton("Seek 2s", on_click=seek_2s),
57+
ft.Row(
58+
controls=[
59+
ft.ElevatedButton("Volume down", on_click=lambda _: set_volume(-0.1)),
60+
ft.ElevatedButton("Volume up", on_click=lambda _: set_volume(0.1)),
61+
]
62+
),
63+
ft.Row(
64+
controls=[
65+
ft.ElevatedButton("Balance left", on_click=lambda _: set_balance(-0.1)),
66+
ft.ElevatedButton("Balance right", on_click=lambda _: set_balance(0.1)),
67+
]
68+
),
69+
ft.ElevatedButton("Get duration", on_click=get_duration),
70+
ft.ElevatedButton("Get current position", on_click=on_get_current_position),
71+
)
72+
73+
74+
ft.run(main)

0 commit comments

Comments
 (0)