Installation

Learn how to set up flutter_soloud in your project

Platform Setup

Web Platform

To use this plugin on the web platform, add the following scripts to your web/index.html:

html
<script src="assets/packages/flutter_soloud/web/libflutter_soloud_plugin.js" defer></script>
<script src="assets/packages/flutter_soloud/web/init_module.dart.js" defer></script>

The web build uses a WebAssembly module that requires SharedArrayBuffer, which means it must be run with --wasm or served with cross-origin isolation headers. See the Web Platform Guide for details.

Linux Setup

Linux distributions require the ALSA library for audio support. If missing, install it using your package manager:

bash
# Debian/Ubuntu
sudo apt-get install libasound2-dev

# Arch Linux
sudo pacman -S alsa-lib

# OpenSUSE
sudo zypper install alsa-devel

If you are linking the Xiph libraries (the default), you can also choose to use the TRY_SYSTEM_LIBS_FIRST=1 environment variable to link the ones available in the system:

bash
# Default - use bundled libraries
flutter run

# Prefer system libraries, fallback to bundled
TRY_SYSTEM_LIBS_FIRST=1 flutter run

Raspberry Pi Setup

Since the precompiled Xiph libraries are provided only for x86_64, you need to install them manually on the system:

bash
sudo apt install libflac-dev libogg-dev libopus-dev libvorbis-dev

and then set the TRY_SYSTEM_LIBS_FIRST=1 environment variable to link them instead of the bundled ones:

bash
TRY_SYSTEM_LIBS_FIRST=1 flutter run

If the Xiph libraries are not needed (for streaming purposes), you can also look here: Without Xiph libs

iOS and macOS Configuration

โš ๏ธ Using Swift Package Manager (SPM), packages cannot set Xcode build settings on the consuming app target. So when creating a release archive (IPA), you may need to modify symbol stripping to prevent errors:

  1. Open your project in Xcode
  2. Navigate to Target Runner > Build Settings > Strip Style
  3. Change from "All Symbols" to "Non-Global Symbols"

iOS and macOS build

On macOS and iOS, the Swift Package Manager (SPM) can be used to build the plugin module. If SPM is not enabled, the build will be done using CocoaPods (using cmake). If the latter is used, please be sure you have cmake installed: brew install cmake.

Basic Usage

Initialize SoLoud in your app:

dart
void main() async {
  await SoLoud.instance.init(
    sampleRate: 44100,      // Audio quality
    bufferSize: 2048,       // Buffer size affects latency
    channels: Channels.stereo,
  );
  
  runApp(const MyApp());
}

Best Practices

  • Initialize SoLoud early in your app lifecycle
  • Handle initialization errors appropriately
  • Configure buffer size based on your latency and app needs
  • Clean up resources when your app closes