flutter_soloud supports audio streaming and real-time playback for compressed audio formats including Ogg, Vorbis, Opus, and FLAC via libraries from Xiph.org.
Starting in version 5.1+, flutter_soloud uses Dart Native Assets build hooks to provide flexible options for handling Xiph libraries across all platforms:
- Default Mode (Remote Prebuilt Libraries): No configuration is required. Tested, precompiled static and shared Xiph libraries are hosted in the companion repository flutter_soloud_prebuilds. On the first build, Dart's Native Assets build hook automatically downloads and caches the matching archive for your target platform and architecture into
.dart_tool/flutter_soloud/xiph/prebuild/. This keeps the pub package lightweight while ensuring apps run out of the box with zero setup. - System Libraries Mode (
<platform>_use_system_libs: true): Links against system-installed packages (apt, pacman, dnf, Homebrew, vcpkg). Ideal for Linux distribution packages (.deb,.rpm, Arch AUR) and custom desktop environments. - Build from Source Mode (
<platform>_force_build_libs: true): Clones the pinned Xiph Git repositories (ogg,vorbis,opus,flac) and builds them locally using CMake into.dart_tool/flutter_soloud/xiph/install/<os>/<arch>(orinstall/ios/<simulator|device>/<arch>on iOS). - Without Xiph Mode (
no_xiph_libs: true): Skips Xiph libraries entirely across all platforms to reduce application binary size.
No configuration is needed in your pubspec.yaml!
To keep the flutter_soloud package footprint small on pub.dev, precompiled binaries and C headers are hosted and maintained in the dedicated companion repository:
๐ alnitak/flutter_soloud_prebuilds
The flutter_soloud_prebuilds repository provides automated, reproducible CMake build scripts and multi-platform GitHub Actions workflows. Each release provides pre-compiled, optimized, and stripped libraries for all Flutter-supported targets:
- Android: Prebuilt shared
.solibraries for all 4 ABIs (arm64-v8a,armeabi-v7a,x86,x86_64). - iOS: Universal static
.aarchives covering physical devices (arm64) and simulators (arm64,x86_64). - macOS: Universal static
.aarchives supporting both Apple Silicon (arm64) and Intel (x86_64). - Windows: Precompiled 64-bit (
x64) and 64-bit ARM (arm64).zippackages with DLLs and import libraries. - Linux: Precompiled 64-bit (
x86_64) and 64-bit ARM (aarch64).soshared libraries. - Include Headers: Canonical Xiph C headers (
ogg/,vorbis/,opus/,FLAC/) including generated configuration headers.
When you run flutter run or flutter build:
- The Dart Native Assets build hook (
hook/build.dart) checks whether prebuilts already exist in the local project cache at.dart_tool/flutter_soloud/xiph/prebuild/<platform>/. - If not found, it automatically downloads the matching archive from the latest GitHub Release and extracts it into the cache.
- It records the release tag in
flutter_soloud_prebuild_version.txtinside the cache. - Subsequent builds reuse the cached libraries instantly without downloading again.
By default, the build hook queries the latest GitHub release. If your team or CI/CD environment requires pinning a specific release tag, specify prebuild_tag in your app's pubspec.yaml:
hooks:
user_defines:
flutter_soloud:
prebuild_tag: 'v1.0.1' # Optional: pin to a specific release tagOn desktop platforms, you can instruct flutter_soloud to link against libraries installed in the operating system.
If you package an application with system libraries, the end user running your application must have those libraries installed on their machine. If missing, the app will fail to load the native library on startup (with an actionable error message indicating how to install them).
Install the Xiph development packages using your platform's package manager:
sudo apt update
sudo apt install libogg-dev libvorbis-dev libopus-dev libflac-dev pkg-configsudo pacman -S libogg libvorbis opus flac pkgconfsudo dnf install libogg-devel libvorbis-devel opus-devel flac-devel pkgconf-pkg-configbrew install libogg libvorbis opus flac pkg-config# For x64
vcpkg install libogg:x64-windows libvorbis:x64-windows opus:x64-windows flac:x64-windows
# For ARM64
vcpkg install libogg:arm64-windows libvorbis:arm64-windows opus:arm64-windows flac:arm64-windowsSet the VCPKG_ROOT environment variable if not already set (e.g., C:\vcpkg).
If you are on Windows and prefer to download prebuilt binaries manually:
-
Download the Binaries:
-
Where to Place the Files: When
windows_use_system_libs: trueis configured, the build hook searches:%VCPKG_ROOT%\installed\<arch>-windows\libC:\vcpkg\installed\<arch>-windows\libC:\Program Files\Xiph\libandC:\Program Files\Xiph\includeC:\Xiph\libandC:\Xiph\include
Add the platform-specific flag under hooks.user_defines.flutter_soloud in your app's pubspec.yaml:
hooks:
user_defines:
flutter_soloud:
linux_use_system_libs: true
# and/or macos_use_system_libs: true
# and/or windows_use_system_libs: trueIf you want to compile the Xiph libraries from the official pinned Git repositories using CMake on your own machine:
hooks:
user_defines:
flutter_soloud:
linux_force_build_libs: true
# and/or macos_force_build_libs: true
# and/or windows_force_build_libs: true
# and/or android_force_build_libs: true
# and/or ios_force_build_libs: trueBuild time impact: Setting <platform>_force_build_libs: true significantly increases build times. The build hook will git clone all four Xiph repositories (ogg, vorbis, opus, flac) and compile them from source via CMake.
Keep in mind that:
- Android compiles across 4 architectures (
arm64-v8a,armeabi-v7a,x86,x86_64). - Apple (iOS / macOS) compiles for both device and simulator architectures.
- Compilation artifacts are cached in
flutter_soloud's.dart_tool/directory, meaning they persist even after runningflutter cleanin your application (a re-clone and re-compile only occurs if the plugin's.dart_tool/is removed or on fresh CI/CD environments without cache).
For everyday development, leaving this option at its default (false) to use the remote precompiled libraries is strongly recommended.
- Git installed on your system PATH (
git --version). - CMake installed on your system PATH (
cmake --version). - A C/C++ compiler (GCC/Clang on Linux, Xcode on macOS/iOS, MSVC on Windows, Android NDK for Android).
Artifacts are compiled into .dart_tool/flutter_soloud/xiph/install/<os>/<arch> (or install/ios/<simulator|device>/<arch> on iOS) and cached for future builds.
If your app only plays uncompressed PCM / WAV audio or built-in synthesizer waveforms and you want to reduce your app's binary size by 600 KB to 3 MB:
Add no_xiph_libs: true to your pubspec.yaml:
hooks:
user_defines:
flutter_soloud:
no_xiph_libs: trueWhen built without Xiph:
- The compiler defines
NO_XIPH_LIBS. - No Xiph libraries are linked or bundled.
- Compressed audio streaming with Opus/Vorbis/FLAC formats is disabled (
SoLoudXiphLibsNotAvailableExceptionis thrown if attempted). - All standard WAV, MP3, and synthesis features remain 100% operational.
See Without Xiph libs for full details.
All build customization options are configured in your application's pubspec.yaml under hooks.user_defines.flutter_soloud:
| User Define | Type | Default | Supported Platforms | Description |
|---|---|---|---|---|
no_xiph_libs | bool | false | All | Excludes Xiph codecs entirely, reducing final binary size by 0.6โ3 MB. Disables Ogg, Vorbis, Opus, and FLAC streaming. |
prebuild_tag | string | 'latest' | All | Specific GitHub release tag to download from flutter_soloud_prebuilds (e.g. 'v1.0.1'). Default queries latest. |
linux_use_system_libs | bool | false | Linux | Links against system-installed libraries via pkg-config (apt, pacman, dnf). |
use_system_xiph_libs | bool | false | Linux | Legacy alias for linux_use_system_libs. |
linux_force_build_libs | bool | false | Linux | Clones and builds Xiph libraries from Git source tree using CMake and GCC/Clang. |
macos_use_system_libs | bool | false | macOS | Links against system or Homebrew-installed Xiph libraries. |
macos_force_build_libs | bool | false | macOS | Clones and builds universal Apple Silicon & Intel static libraries from source via CMake. |
windows_use_system_libs | bool | false | Windows | Links against system or vcpkg-installed libraries. |
windows_force_build_libs | bool | false | Windows | Clones and builds Xiph libraries from Git source tree using CMake and MSVC. |
android_force_build_libs | bool | false | Android | Clones and builds shared libraries across all 4 Android ABIs using Android NDK and CMake. |
ios_force_build_libs | bool | false | iOS | Clones and builds static libraries for device (arm64) and simulator (arm64, x86_64) via CMake. |