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 index.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>

See the Web Platform Guide for more details.

Linux Setup

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

# 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 onces available in the system:

# Default - use bundled libraries
flutter build run

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

Rasperry Pi Setup

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

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:

TRY_SYSTEM_LIBS_FIRST=1 flutter run

iOS Configuration

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:

void main() async {
  await SoLoud.instance.init(
    sampleRate: 44100,      // Audio quality
    bufferSize: 2048,       // Buffer size affects latency
    channels: Channels.stereo,
  );
  
  runApp(const MyApp());
}
The bufferSize parameter affects audio latency, which generally means the time it takes from triggering a sound to the sound actually coming out of the speakers. The smaller the latency, the better, but could lead to choppy audio depending on the complexity of the audio processing. The default is 2048, but it can be adjusted to 1024 or 512.

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