Skip to content

Commit c5ed317

Browse files
committed
Update to audioplayers v4
1 parent 7d3d426 commit c5ed317

File tree

5 files changed

+378
-163
lines changed

5 files changed

+378
-163
lines changed

README.md

Lines changed: 46 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ _The difference between packages and plugins is that packages don't include any
1919
## 🖥️ Supported Platforms
2020
Although flutter-pi is only tested on a Rasberry Pi 4 2GB, it should work fine on other linux platforms, with the following conditions:
2121

22-
- support for hardware 3D acceleration. more precisely support for kernel-modesetting (KMS) and the direct rendering infrastructure (DRI)
22+
- support for hardware 3D acceleration. more precisely support for kernel-modesetting (KMS) and the direct rendering infrastructure (DRI)
2323
- CPU architecture is one of ARMv7, ARMv8, x86 or x86 64bit.
2424

2525
This means flutter-pi won't work on a Pi Zero (only the first one) or Pi 1.
@@ -33,16 +33,16 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
3333

3434
## 📑 Contents
3535

36-
1. **[Building flutter-pi on the Raspberry Pi](#-building-flutter-pi-on-the-raspberry-pi)**
37-
1.1 [Dependencies](#dependencies)
38-
1.2 [Compiling](#compiling)
39-
2. **[Running your App on the Raspberry Pi](#-running-your-app-on-the-raspberry-pi)**
40-
2.1 [Configuring your Raspberry Pi](#configuring-your-raspberry-pi)
41-
2.2 [Building the App](#building-the-app-new-method-linux-only)
42-
2.3 [Running your App with flutter-pi](#running-your-app-with-flutter-pi)
43-
2.4 [gstreamer video player](#gstreamer-video-player)
44-
3. **[Performance](#-performance)**
45-
3.1 [Graphics Performance](#graphics-performance)
36+
1. **[Building flutter-pi on the Raspberry Pi](#-building-flutter-pi-on-the-raspberry-pi)**
37+
1.1 [Dependencies](#dependencies)
38+
1.2 [Compiling](#compiling)
39+
2. **[Running your App on the Raspberry Pi](#-running-your-app-on-the-raspberry-pi)**
40+
2.1 [Configuring your Raspberry Pi](#configuring-your-raspberry-pi)
41+
2.2 [Building the App](#building-the-app-new-method-linux-only)
42+
2.3 [Running your App with flutter-pi](#running-your-app-with-flutter-pi)
43+
2.4 [gstreamer video player](#gstreamer-video-player)
44+
3. **[Performance](#-performance)**
45+
3.1 [Graphics Performance](#graphics-performance)
4646
3.2 [Touchscreen latency](#touchscreen-latency)
4747
4. **[Useful Dart Packages](#-useful-dart-packages)**
4848
5. **[Discord](#-discord)**
@@ -62,7 +62,7 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
6262

6363
<details>
6464
<summary>More Info</summary>
65-
65+
6666
flutter-pi needs flutters `icudtl.dat` and `libflutter_engine.so.{debug,profile,release}` at runtime, depending on the runtime mode used.
6767
You actually have two options here:
6868

@@ -71,7 +71,7 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
7171

7272
</details>
7373

74-
74+
7575
</details>
7676

7777
3. Install cmake, graphics, system libraries and fonts:
@@ -85,15 +85,15 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
8585
```
8686
<details>
8787
<summary>More Info</summary>
88-
88+
8989
- flutter-pi needs the mesa OpenGL ES and EGL implementation and libdrm & libgbm. It may work with non-mesa implementations too, but that's untested.
9090
- The flutter engine depends on the _Arial_ font. Since that doesn't come included with Raspbian, you need to install it.
9191
- `libsystemd` is not systemd, it's just an utility library. It provides the event loop and dbus support for flutter-pi.
9292
- `libinput-dev`, `libudev-dev` and `libxkbcommon-dev` are needed for (touch, mouse, raw keyboard and text) input support.
9393
- `libudev-dev` is required, but actual udev is not. Flutter-pi will just open all `event` devices inside `/dev/input` (unless overwritten using `-i`) if udev is not present.
9494
- `gpiod` and `libgpiod-dev` where required in the past, but aren't anymore since the `flutter_gpiod` plugin will directly access the kernel interface.
9595
</details>
96-
96+
9797
4. Update the system fonts.
9898
```bash
9999
sudo fc-cache
@@ -122,12 +122,12 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
122122
```bash
123123
sudo raspi-config
124124
```
125-
125+
126126
2. Switch to console mode:
127127
`System Options -> Boot / Auto Login` and select `Console` or `Console (Autologin)`.
128128

129-
3. *You can skip this if you're on Raspberry Pi 4 with Raspbian Bullseye*
130-
Enable the V3D graphics driver:
129+
3. *You can skip this if you're on Raspberry Pi 4 with Raspbian Bullseye*
130+
Enable the V3D graphics driver:
131131
`Advanced Options -> GL Driver -> GL (Fake KMS)`
132132
133133
4. Configure the GPU memory
@@ -144,7 +144,7 @@ If you encounter issues running flutter-pi on any of the supported platforms lis
144144

145145
<details>
146146
<summary>More information</summary>
147-
147+
148148
- flutter-pi requires that no other process, like a X11- or wayland-server, is using the video output. So to disable the desktop environment, we boot into console instead.
149149
- The old broadcom-proprietary GL driver was bugged and not working with flutter, so we have to use the Fake KMS driver.
150150
- Actually, you can also configure 16MB of GPU memory if you want to. 64MB are needed when you want to use the [`omxplayer_video_player`](https://pub.dev/packages/omxplayer_video_player) plugin.
@@ -159,7 +159,7 @@ _One-time setup:_
159159
2. Install the [flutterpi_tool](https://pub.dev/packages/flutterpi_tool):
160160
Run `flutter pub global activate flutterpi_tool` (One time only)
161161
3. If running `flutterpi_tool` directly doesn't work, follow https://dart.dev/tools/pub/cmd/pub-global#running-a-script-from-your-path
162-
to add the dart global bin directory to your path.
162+
to add the dart global bin directory to your path.
163163
Alternatively, you can launch the tool via:
164164
`flutter pub global run flutterpi_tool ...`
165165

@@ -168,7 +168,7 @@ _Building the app bundle:_
168168
2. Run `flutterpi_tool build` to build the app.
169169
- This will build the app for ARM 32-bit debug mode.
170170
- `flutterpi_tool build --help` gives more usage information.
171-
- For example, to build for 64-bit ARM, release mode, with a Raspberry Pi 4 tuned engine, use:
171+
- For example, to build for 64-bit ARM, release mode, with a Raspberry Pi 4 tuned engine, use:
172172
`flutterpi_tool build --arch=arm64 --cpu=pi4 --release`
173173
3. Deploy the bundle to the Raspberry Pi using `rsync` or `scp`:
174174
- Using `rsync` (available on linux and macOS or on Windows when using [WSL](https://docs.microsoft.com/de-de/windows/wsl/install-win10))
@@ -197,15 +197,15 @@ rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/
197197
<details>
198198
199199
<summary>Instructions</summary>
200-
200+
201201
1. Make sure you've installed the flutter SDK. **You must** use a flutter SDK that's compatible to the installed engine binaries.
202-
- for the flutter SDK, use flutter stable and keep it up to date.
203-
- always use the latest available [engine binaries](https://github.com/ardera/flutter-engine-binaries-for-arm)
204-
202+
- for the flutter SDK, use flutter stable and keep it up to date.
203+
- always use the latest available [engine binaries](https://github.com/ardera/flutter-engine-binaries-for-arm)
204+
205205
If you encounter error messages like `Invalid kernel binary format version`, `Invalid SDK hash` or `Invalid engine hash`:
206206
1. Make sure your flutter SDK is on `stable` and up to date and your engine binaries are up to date.
207207
2. If you made sure that's the case and the error still happens, create a new issue.
208-
208+
209209
2. Open terminal or commandline and `cd` into your app directory.
210210

211211
3. `flutter build bundle`
@@ -219,7 +219,7 @@ rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/
219219
```bash
220220
scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_apps_flutter_assets
221221
```
222-
222+
223223
#### Example
224224
1. We'll build the asset bundle for `flutter_gallery` and deploy it using `rsync` in this example.
225225
```bash
@@ -233,7 +233,7 @@ rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/
233233
234234
<details>
235235
<summary>More information</summary>
236-
236+
237237
- flutter_gallery is developed against flutter master. `d77920b4ced4a105ad35659fbe3958800d418fb9` is currently the latest flutter gallery
238238
commit working with flutter stable.
239239
</details>
@@ -373,7 +373,7 @@ OPTIONS:
373373
--pixelformat <format> Selects the pixel format to use for the framebuffers.
374374
If this is not specified, a good pixel format will
375375
be selected automatically.
376-
Available pixel formats: RGB565, ARGB4444, XRGB4444, ARGB1555, XRGB1555, ARGB8888, XRGB8888, BGRA8888, BGRX8888, RGBA8888, RGBX8888,
376+
Available pixel formats: RGB565, ARGB4444, XRGB4444, ARGB1555, XRGB1555, ARGB8888, XRGB8888, BGRA8888, BGRX8888, RGBA8888, RGBX8888,
377377
--videomode widthxheight
378378
--videomode widthxheight@hz Uses an output videomode that satisfies the argument.
379379
If no hz value is given, the highest possible refreshrate
@@ -407,12 +407,27 @@ of the flutter app you're trying to run.
407407
`[flutter engine options...]` will be passed as commandline arguments to the flutter engine. You can find a list of commandline options for the flutter engine [Here](https://github.com/flutter/engine/blob/master/shell/common/switches.h).
408408
409409
### gstreamer video player
410-
Gstreamer video player is a newer video player based on gstreamer. The older video player (omxplayer_video_player) was based on deprecated omxplayer and it was kind of a hack. So I recommend using the gstreamer one instead.
410+
Gstreamer video player is a newer video player based on gstreamer. The older video player (omxplayer_video_player) was based on deprecated omxplayer and it was kind of a hack. So I recommend using the gstreamer one instead.
411411
412412
To use the gstreamer video player, just rebuild flutter-pi (delete your build folder and reconfigure) and make sure the necessary gstreamer packages are installed. (See [dependencies](#dependencies))
413413
414414
And then, just use the stuff in the official [video_player](https://pub.dev/packages/video_player) package. (`VideoPlayer`, `VideoPlayerController`, etc, there's nothing specific you need to do on the dart-side)
415415
416+
### audioplayers
417+
418+
As of current moment flutter-pi implements plugin for `audioplayers: ^4.0.0`.
419+
420+
There are several things you need to keep in mind:
421+
422+
- As flutter-pi is intended for use on constrained systems like raspberry pi, you should avoid creating multiple temporary instances and instead prefer to use one global instance of `AudioPlayer`. There is limit you can easily hit if you're going to spam multiple instances of `AudioPlayer`
423+
- Plugin was tested to work with ALSA and `pulseaudio` might prevent the plugin from playing audio correctly:
424+
- Hence please make sure you delete `pulseaudio` package from your system.
425+
- Make sure you have `gstreamer1.0-alsa` package installed in addition to packages needed for gstreamer video player.
426+
- Make sure you can list audio devices using command: `aplay -L`
427+
- If there is error, please investigate why and fix it before using audio
428+
- One of the common reasons is outdated ALSA config in which case you should delete existing config and replace it with up to date one
429+
- Finally, if you want to verify your audio setup is good, you can use `gst-launch` command to invoke `playbin` on audio file directly.
430+
416431
## 📊 Performance
417432
### Graphics Performance
418433
Graphics performance is actually pretty good. With most of the apps inside the `flutter SDK -> examples -> catalog` directory I get smooth 50-60fps on the Pi 4 2GB and Pi 3 A+.
@@ -432,6 +447,7 @@ This is why I created my own (userspace) touchscreen driver, for improved latenc
432447
| linux_spidev ([package](https://pub.dev/packages/linux_spidev/)) ([repo](https://github.com/ardera/flutter_packages/tree/main/packages/linux_spidev)) | 🖨 peripherals | Hannes Winkler | SPI bus support for dart/flutter, uses kernel interfaces directly for more performance. |
433448
| dart_periphery ([package](https://pub.dev/packages/dart_periphery)) ([repo](https://github.com/pezi/dart_periphery)) | 🖨 peripherals | [Peter Sauer](https://github.com/pezi/) | All-in-one package GPIO, I2C, SPI, Serial, PWM, Led, MMIO support using c-periphery. |
434449
| flutterpi_gstreamer_video_player ([package](https://pub.dev/packages/flutterpi_gstreamer_video_player)) ([repo](https://github.com/ardera/flutter_packages/tree/main/packages/flutterpi_gstreamer_video_player)) | ⏯️ multimedia | Hannes Winkler | Official video player implementation for flutter-pi. See [GStreamer video player](#gstreamer-video-player) section above. |
450+
| audioplayers ([package](https://pub.dev/packages/audioplayers)) ([repo](https://github.com/bluefireteam/audioplayers/tree/main/packages/audioplayers)) | ⏯️ multimedia | Blue Fire | flutter-pi implements audio plugin v4. |
435451
436452
## 💬 Discord
437453
There a `#custom-embedders` channel on the [flutter discord](https://github.com/flutter/flutter/wiki/Chat) which you can use if you have any questions regarding flutter-pi or generally, anything related to embedding the engine for which you don't want to open issue about or write an email.

include/plugins/audioplayers.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ void audio_player_set_volume(struct audio_player *self, double volume);
3030

3131
void audio_player_set_playback_rate(struct audio_player *self, double rate);
3232

33+
void audio_player_set_balance(struct audio_player *self, double balance);
34+
3335
void audio_player_set_position(struct audio_player *self, int64_t position);
3436

3537
void audio_player_set_source_url(struct audio_player *self, char *url);

src/plugins/audioplayers/README.md

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
## audioplayers plugin
2+
3+
### Requirements
4+
5+
- `audioplayers` version `^4.0.0`
6+
- Working gstreamer installation, including corresponding audio plugin (e.g. `gstreamer1.0-alsa`)
7+
8+
### Troubleshooting
9+
10+
- Check that you can list ALSA devices via command `aplay -L`;
11+
- Check that you can launch `playbin` on any audio file via `gst-launch`;
12+
- Make sure `pulseaudio` is deleted
13+
14+
### pulseaudio
15+
16+
Please note that plugin was not tested with `pulseaudio` and it is up to you to make gstreamer work via it.
17+
As `pulseaudio` takes full control over audio devices, `ALSA` will no longer function correctly with `pulseaudio` installed

0 commit comments

Comments
 (0)