### Audio Context with Platform Specific Details Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of creating an audio context with platform-specific configurations. ```dart player.setAudioContext(AudioContext( android: AudioContextAndroid(/*...*/), iOS: AudioContextIOS(/*...*/), )); ``` -------------------------------- ### Release Mode Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of setting the release mode to loop. ```dart await player.setReleaseMode(ReleaseMode.loop); ``` -------------------------------- ### Global Audio Context Configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of setting the global audio context configuration. ```dart AudioPlayer.global.setAudioContext(AudioContextConfig(/*...*/).build()); ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Installs bundled libraries from plugins. ```cmake foreach(bundled_library ${PLUGIN_BUNDLED_LIBRARIES}) install(FILES "${bundled_library}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endforeach(bundled_library) ``` -------------------------------- ### Installation - Bundle Directory Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the installation prefix to a bundle directory and ensures it's clean. ```cmake set(BUILD_BUNDLE_DIR "${PROJECT_BINARY_DIR}/bundle") if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() install(CODE " file(REMOVE_RECURSE \"${BUILD_BUNDLE_DIR}/\") " COMPONENT Runtime) set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}/lib") ``` -------------------------------- ### Install Flutter Assets Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Installs Flutter assets by removing the old directory and then copying the new one. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Install Native Assets Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Installs native assets provided by build.dart. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/linux/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Player Specific Audio Context Configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of setting an audio context for a specific player. ```dart player.setAudioContext(AudioContextConfig(/*...*/).build()); ``` -------------------------------- ### Playback Rate Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of how to set the playback rate for an audio player. ```dart await player.setPlaybackRate(0.5); // half speed ``` -------------------------------- ### Install AOT Library Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Installs the AOT library on non-Debug builds. ```cmake # Install the AOT library on non-Debug builds only. if(NOT CMAKE_BUILD_TYPE MATCHES "Debug") install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Initializing AudioPlayer with Custom playerId Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of initializing an AudioPlayer instance with a specific, user-defined playerId. ```dart final player = AudioPlayer(playerId: 'my_unique_playerId'); ``` -------------------------------- ### Log Level Control Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of setting the global log level for AudioLogger. ```dart AudioLogger.logLevel = AudioLogLevel.info; ``` -------------------------------- ### Instantiate AudioPlayer Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Creates a new instance of the AudioPlayer class. ```dart final player = AudioPlayer(); ``` -------------------------------- ### Customizing PositionUpdater Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of customizing the position stream update interval using TimerPositionUpdater. ```dart player.positionUpdater = TimerPositionUpdater( interval: const Duration(milliseconds: 100), getPosition: player.getCurrentPosition, ); ``` -------------------------------- ### Playing Local Assets (Default) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of playing a local asset using the default AudioCache configuration, assuming the asset is in '/assets/audio/my-audio.wav'. ```dart final player = AudioPlayer(); await player.play(AssetSource('audio/my-audio.wav')); ``` -------------------------------- ### Install Application Executable Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Installs the main application executable to the specified runtime destination. This makes the application available for execution. ```cmake install(TARGETS ${BINARY_NAME} RUNTIME DESTINATION "${CMAKE_INSTALL_PREFIX}" COMPONENT Runtime) ``` -------------------------------- ### Playing Local Assets (No Prefix) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of removing the default asset prefix for all players by reconfiguring the global AudioCache instance. ```dart AudioCache.instance = AudioCache(prefix: '') final player = AudioPlayer(); await player.play(AssetSource('assets/audio/my-audio.wav')); ``` -------------------------------- ### Run the server locally Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/server/README.md Command to run the HTTP server locally. ```bash $ dart run bin/server.dart ``` -------------------------------- ### Playing Local Assets (Custom Prefix) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Example of setting a custom asset prefix for a specific player instance, useful for assets from other packages. ```dart final player = AudioPlayer(); player.audioCache = AudioCache(prefix: 'packages/OTHER_PACKAGE/assets/') await player.play(AssetSource('other-package-audio.wav')); ``` -------------------------------- ### System-level Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Finds PkgConfig and checks for GTK+ 3.0. ```cmake find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) add_definitions(-DAPPLICATION_ID="${APPLICATION_ID}") ``` -------------------------------- ### Add audioplayers to pubspec.yaml Source: https://github.com/bluefireteam/audioplayers/blob/main/migration_guide.md Example of how to add the latest version of audioplayers to your pubspec.yaml file. ```yaml dependencies: audioplayers: ^2.0.0 ``` -------------------------------- ### Simple audio player app example Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/example.md A complete example showcasing all _audioplayers_ features. ```dart import 'dart:async'; import 'package:audioplayers/audioplayers.dart'; import 'package:flutter/material.dart'; void main() { runApp(const MaterialApp(home: _SimpleExampleApp())); } class _SimpleExampleApp extends StatefulWidget { const _SimpleExampleApp(); @override _SimpleExampleAppState createState() => _SimpleExampleAppState(); } class _SimpleExampleAppState extends State<_SimpleExampleApp> { late AudioPlayer player = AudioPlayer(); @override void initState() { super.initState(); // Create the audio player. player = AudioPlayer(); // Set the release mode to keep the source after playback has completed. player.setReleaseMode(ReleaseMode.stop); // Start the player as soon as the app is displayed. WidgetsBinding.instance.addPostFrameCallback((_) async { await player.setSource(AssetSource('ambient_c_motion.mp3')); await player.resume(); }); } @override void dispose() { // Release all sources and dispose the player. player.dispose(); super.dispose(); } @override Widget build(BuildContext context) { return Scaffold( appBar: AppBar( title: const Text('Simple Player'), ), body: PlayerWidget(player: player), ); } } // The PlayerWidget is a copy of "/lib/components/player_widget.dart". //#region PlayerWidget class PlayerWidget extends StatefulWidget { final AudioPlayer player; const PlayerWidget({ required this.player, super.key, }); @override State createState() { return _PlayerWidgetState(); } } class _PlayerWidgetState extends State { PlayerState? _playerState; Duration? _duration; Duration? _position; StreamSubscription? _durationSubscription; StreamSubscription? _positionSubscription; StreamSubscription? _playerCompleteSubscription; StreamSubscription? _playerStateChangeSubscription; bool get _isPlaying => _playerState == PlayerState.playing; bool get _isPaused => _playerState == PlayerState.paused; String get _durationText => _duration?.toString().split('.').first ?? ''; String get _positionText => _position?.toString().split('.').first ?? ''; AudioPlayer get player => widget.player; @override void initState() { super.initState(); // Use initial values from player _playerState = player.state; player.getDuration().then( (value) => setState(() { _duration = value; }), ); player.getCurrentPosition().then( (value) => setState(() { _position = value; }), ); _initStreams(); } @override void setState(VoidCallback fn) { // Subscriptions only can be closed asynchronously, // therefore events can occur after widget has been disposed. if (mounted) { super.setState(fn); } } @override void dispose() { _durationSubscription?.cancel(); _positionSubscription?.cancel(); _playerCompleteSubscription?.cancel(); _playerStateChangeSubscription?.cancel(); super.dispose(); } @override Widget build(BuildContext context) { final color = Theme.of(context).primaryColor; return Column( mainAxisSize: MainAxisSize.min, children: [ Row( mainAxisSize: MainAxisSize.min, children: [ IconButton( key: const Key('play_button'), onPressed: _isPlaying ? null : _play, iconSize: 48.0, icon: const Icon(Icons.play_arrow), color: color, ), IconButton( key: const Key('pause_button'), onPressed: _isPlaying ? _pause : null, iconSize: 48.0, icon: const Icon(Icons.pause), color: color, ), IconButton( key: const Key('stop_button'), onPressed: _isPlaying || _isPaused ? _stop : null, iconSize: 48.0, icon: const Icon(Icons.stop), color: color, ), ], ), Slider( onChanged: (value) { final duration = _duration; if (duration == null) { return; } final position = value * duration.inMilliseconds; player.seek(Duration(milliseconds: position.round())); }, value: (_position != null && _duration != null && _position!.inMilliseconds > 0 && _position!.inMilliseconds < _duration!.inMilliseconds) ? _position!.inMilliseconds / _duration!.inMilliseconds ``` -------------------------------- ### Define Installation Directories Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Sets the destination directories for installing data and library files within the application bundle. This organizes the deployed application structure. ```cmake set(INSTALL_BUNDLE_DATA_DIR "${CMAKE_INSTALL_PREFIX}/data") set(INSTALL_BUNDLE_LIB_DIR "${CMAKE_INSTALL_PREFIX}") ``` -------------------------------- ### Runtime Path Configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the runtime path for bundled libraries. ```cmake set(CMAKE_INSTALL_RPATH "$ORIGIN/lib") ``` -------------------------------- ### Project-level configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the minimum CMake version and project name. ```cmake cmake_minimum_required(VERSION 3.10) project(runner LANGUAGES CXX) ``` -------------------------------- ### Play Audio from Device File Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Sets the audio source from a local file on the device and starts playback immediately. ```dart await player.play(DeviceFileSource(localFile)); ``` -------------------------------- ### Build Configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the build type (Debug, Profile, Release) if not already defined. ```cmake if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() ``` -------------------------------- ### Resume Playback Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Starts or resumes audio playback from the current position. ```dart await player.resume(); ``` -------------------------------- ### Cross-building Sysroot Configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Configures sysroot and find root path for cross-compilation. ```cmake if(FLUTTER_TARGET_PLATFORM_SYSROOT) set(CMAKE_SYSROOT ${FLUTTER_TARGET_PLATFORM_SYSROOT}) set(CMAKE_FIND_ROOT_PATH ${CMAKE_SYSROOT}) set(CMAKE_FIND_ROOT_PATH_MODE_PROGRAM NEVER) set(CMAKE_FIND_ROOT_PATH_MODE_PACKAGE ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_LIBRARY ONLY) set(CMAKE_FIND_ROOT_PATH_MODE_INCLUDE ONLY) endif() ``` -------------------------------- ### Flutter Managed Directory Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the directory for Flutter managed files. ```cmake set(FLUTTER_MANAGED_DIR "${CMAKE_CURRENT_SOURCE_DIR}/flutter") add_subdirectory(${FLUTTER_MANAGED_DIR}) ``` -------------------------------- ### Application Target Definition Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Defines the main executable target and lists its source files. ```cmake add_executable(${BINARY_NAME} "main.cc" "my_application.cc" "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" ) apply_standard_settings(${BINARY_NAME}) ``` -------------------------------- ### Generated Plugin Build Rules Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Includes the CMake file for generated plugin build rules. ```cmake include(flutter/generated_plugins.cmake) ``` -------------------------------- ### Set Installation Prefix for Bundle Directory Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Configures the installation prefix to be the directory next to the executable, allowing support files to run in place. This is crucial for Visual Studio builds. ```cmake set(BUILD_BUNDLE_DIR "$") set(CMAKE_VS_INCLUDE_INSTALL_TO_DEFAULT_BUILD 1) if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT) set(CMAKE_INSTALL_PREFIX "${BUILD_BUNDLE_DIR}" CACHE PATH "..." FORCE) endif() ``` -------------------------------- ### Install Bundled Plugin Libraries Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Installs any bundled plugin libraries to the library directory within the application bundle. This ensures that all necessary plugin code is available at runtime. ```cmake if(PLUGIN_BUNDLED_LIBRARIES) install(FILES "${PLUGIN_BUNDLED_LIBRARIES}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) endif() ``` -------------------------------- ### Log Event (Global) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Listens for global log messages from the native platform across all player instances. ```dart AudioPlayer.global.onLog.listen( (String message) => Logger.log(message), onError: (Object e, [StackTrace? stackTrace]) => Logger.error(e, stackTrace), ); ``` -------------------------------- ### Apply Standard Settings Function Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Defines a function to apply standard compilation settings to a target. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_14) target_compile_options(${TARGET} PRIVATE -Wall -Werror) target_compile_options(${TARGET} PRIVATE "$<$>:-O3>") target_compile_definitions(${TARGET} PRIVATE "$<$>:NDEBUG>") endfunction() ``` -------------------------------- ### Modern CMake Behaviors Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Explicitly opts in to modern CMake behaviors to avoid warnings. ```cmake cmake_policy(SET CMP0063 NEW) ``` -------------------------------- ### Install Flutter Library Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Installs the main Flutter library file to the library directory within the application bundle. This is a core component for the Flutter application. ```cmake install(FILES "${FLUTTER_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Link Libraries Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Links the application target to the Flutter and GTK libraries. ```cmake target_link_libraries(${BINARY_NAME} PRIVATE flutter) target_link_libraries(${BINARY_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Bootstrap Project Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/contributing.md Initializes project dependencies locally using Melos, linking all plugins, examples, and tests. ```bash melos bootstrap ``` -------------------------------- ### Set Audio Source (Asset) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Configures the player to play an audio asset from the application's assets directory. ```dart await player.setSource(AssetSource('sounds/coin.wav')); ``` -------------------------------- ### Set Audio Source (URL Shortcut) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md A shortcut method to set the audio source from a remote URL. ```dart await player.setSourceUrl(url); ``` -------------------------------- ### Flutter Assemble Dependency Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Adds a dependency on the flutter_assemble target. ```cmake add_dependencies(${BINARY_NAME} flutter_assemble) ``` -------------------------------- ### Install AOT Library for Release/Profile Builds Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Installs the Ahead-Of-Time (AOT) compiled library to the data directory within the application bundle, but only for Profile and Release configurations. This optimizes performance for non-debug builds. ```cmake install(FILES "${AOT_LIBRARY}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" CONFIGURATIONS Profile;Release COMPONENT Runtime) ``` -------------------------------- ### Basic Usage Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/README.md A simple example of how to play an audio file from a URL. ```dart import 'package:audioplayers/audioplayers.dart'; // ... final player = AudioPlayer(); await player.play(UrlSource('https://example.com/my-audio.wav')); ``` -------------------------------- ### Runtime Output Directory Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Sets the runtime output directory for the executable to avoid direct execution of unbundled copies. ```cmake set_target_properties(${BINARY_NAME} PROPERTIES RUNTIME_OUTPUT_DIRECTORY "${CMAKE_BINARY_DIR}/intermediates_do_not_run" ) ``` -------------------------------- ### Install Melos Source: https://github.com/bluefireteam/audioplayers/blob/main/contributing.md Installs Melos, a tool for managing Dart/Flutter projects, globally. ```bash flutter pub global activate melos ``` -------------------------------- ### Release Player Resources Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Releases resources associated with the player, equivalent to calling stop and deallocating memory. The player can be reused after this. ```dart await player.release(); ``` -------------------------------- ### Executable and Application ID Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/linux/CMakeLists.txt Defines the name of the executable and the GTK application identifier. ```cmake set(BINARY_NAME "audioplayers_example") set(APPLICATION_ID "xyz.luan.audioplayers.example") ``` -------------------------------- ### Install ICU Data File Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Installs the ICU data file to the data directory within the application bundle. This is required for internationalization support. ```cmake install(FILES "${FLUTTER_ICU_DATA_FILE}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Simple Audio Player UI and Logic Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/example.md This code snippet shows the implementation of a basic audio player UI with controls for play, pause, and stop, along with state management for duration, position, and player state. ```Dart : 0.0, ), Text( _position != null ? '$_positionText / $_durationText' : _duration != null ? _durationText : '', style: const TextStyle(fontSize: 16.0), ), ], ); } void _initStreams() { _durationSubscription = player.onDurationChanged.listen((duration) { setState(() => _duration = duration); }); _positionSubscription = player.onPositionChanged.listen( (p) => setState(() => _position = p), ); _playerCompleteSubscription = player.onPlayerComplete.listen((event) { setState(() { _playerState = PlayerState.stopped; _position = Duration.zero; }); }); _playerStateChangeSubscription = player.onPlayerStateChanged.listen((state) { setState(() { _playerState = state; }); }); } Future _play() async { await player.resume(); setState(() => _playerState = PlayerState.playing); } Future _pause() async { await player.pause(); setState(() => _playerState = PlayerState.paused); } Future _stop() async { await player.stop(); setState(() { _playerState = PlayerState.stopped; _position = Duration.zero; }); } } //#endregion ``` -------------------------------- ### Combined Event Stream (Instance) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Obtains all mentioned events through a single combined event stream for a specific player instance. ```dart player.eventStream.listen((AudioEvent event) { print(event.eventType); }); ``` -------------------------------- ### Fedora/RHEL Flutter Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/README.md Installs Flutter development dependencies on Fedora/RHEL-based systems. ```bash sudo dnf install clang cmake ninja-build pkg-config ``` -------------------------------- ### Combined Event Stream (Global) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Obtains all mentioned events through a single combined event stream for global events across all player instances. ```dart AudioPlayer.global.eventStream.listen((GlobalAudioEvent event) { print(event.eventType); }); ``` -------------------------------- ### Fedora/RHEL GStreamer Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/README.md Installs GStreamer development dependencies on Fedora/RHEL-based systems. ```bash sudo dnf install gstreamer1-devel gstreamer1-plugins-base-devel ``` -------------------------------- ### ArchLinux Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/README.md Installs GStreamer and its core plugins on Arch Linux. ```bash sudo pacman -S gstreamer gst-libav gst-plugins-base gst-plugins-good ``` -------------------------------- ### Log Event (Instance) Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Listens for log messages from the native platform for a specific player instance. Logs are handled by default via Logger.log() and errors via Logger.error(). ```dart player.onLog.listen( (String message) => Logger.log(message), onError: (Object e, [StackTrace? stackTrace]) => Logger.error(e, stackTrace), ); ``` -------------------------------- ### Set Minimum CMake Version and Project Name Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Sets the minimum required CMake version to 3.15 and defines the project name for the Audioplayers example. ```cmake cmake_minimum_required(VERSION 3.15) project(audioplayers_example LANGUAGES CXX) ``` -------------------------------- ### Install Native Assets Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Copies native assets provided by the build.dart script from all packages to the library directory within the application bundle. This ensures all necessary native resources are included. ```cmake set(NATIVE_ASSETS_DIR "${PROJECT_BUILD_DIR}native_assets/windows/") install(DIRECTORY "${NATIVE_ASSETS_DIR}" DESTINATION "${INSTALL_BUNDLE_LIB_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Debian Dev Dependencies Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/README.md Installs Flutter and GStreamer development dependencies on Debian-based systems. ```bash sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev ``` ```bash sudo apt-get install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev ``` -------------------------------- ### Flutter Clean and Get Source: https://github.com/bluefireteam/audioplayers/blob/main/troubleshooting.md Commands to clean the Flutter project and refresh dependencies, often helpful for resolving build issues. ```bash flutter clean rm -rf build rm -rf ~/.pub-cache flutter pub get ``` -------------------------------- ### Re-copy Assets Directory and Install Flutter Assets Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Removes and then copies the Flutter assets directory to the data directory within the application bundle. This ensures that the assets are up-to-date and correctly placed. ```cmake set(FLUTTER_ASSET_DIR_NAME "flutter_assets") install(CODE " file(REMOVE_RECURSE \"${INSTALL_BUNDLE_DATA_DIR}/${FLUTTER_ASSET_DIR_NAME}\") " COMPONENT Runtime) install(DIRECTORY "${PROJECT_BUILD_DIR}/${FLUTTER_ASSET_DIR_NAME}" DESTINATION "${INSTALL_BUNDLE_DATA_DIR}" COMPONENT Runtime) ``` -------------------------------- ### Debian Optional GStreamer Plugins Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/README.md Installs optional GStreamer plugins for additional media format support on Debian-based systems. ```bash sudo apt-get install gstreamer1.0-plugins-good gstreamer1.0-plugins-bad ``` -------------------------------- ### Pause Playback Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Pauses the audio playback, retaining the current position. ```dart await player.pause(); ``` -------------------------------- ### Stop Playback Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Stops the audio playback and resets the current position to the beginning. ```dart await player.stop(); ``` -------------------------------- ### Seek Playback Position Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Changes the current playback position to a specified duration. ```dart await player.seek(Duration(milliseconds: 1200)); ``` -------------------------------- ### Set Volume Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Sets the playback volume, ranging from 0.0 (mute) to 1.0 (maximum). ```dart await player.setVolume(0.5); ``` -------------------------------- ### Dispose Player Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Disposes of the player instance, releasing resources and closing streams. The player instance should not be used after this. ```dart await player.dispose(); ``` -------------------------------- ### Position Event Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Listens for updates to the current playback position of the audio. This is useful for implementing progress bars. ```dart player.onPositionChanged.listen((Duration p) => { print('Current position: $p'); setState(() => position = p); }); ``` -------------------------------- ### Set Stereo Balance Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Adjusts the stereo balance of the audio. 0.0 is centered, 1.0 is right channel only, -1.0 is left channel only. ```dart await player.setBalance(1.0); // right channel only ``` -------------------------------- ### State Event Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Listens for changes in the player's state (e.g., playing, stopped, paused). This can be used to update the UI to reflect the current playback status. ```dart player.onPlayerStateChanged.listen((PlayerState s) => { print('Current player state: $s'); setState(() => playerState = s); }); ``` -------------------------------- ### Duration Event Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Listens for changes in the audio file's duration. This event provides the total duration once it's available, which might involve buffering or downloading. ```dart player.onDurationChanged.listen((Duration d) { print('Max duration: $d'); setState(() => duration = d); }); ``` -------------------------------- ### Completion Event Source: https://github.com/bluefireteam/audioplayers/blob/main/getting_started.md Fires when the audio finishes playing. It's commonly used for actions like looping or updating the UI to indicate completion. Note that this event does not fire if playback is interrupted by pause or stop. ```dart player.onPlayerComplete.listen((_) { onComplete(); setState(() { position = duration; }); }); ``` -------------------------------- ### System-level dependencies and linking Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/linux/CMakeLists.txt This snippet details the system dependencies required for the plugin, such as PkgConfig, GTK, GLIB, and GStreamer, and how to link them. ```cmake # System-level dependencies. find_package(PkgConfig REQUIRED) pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) pkg_search_module(GLIB REQUIRED glib-2.0) pkg_check_modules(GSTREAMER REQUIRED gstreamer-1.0) pkg_check_modules(GST_APP REQUIRED gstreamer-app-1.0) pkg_check_modules(GSTREAMER-AUDIO REQUIRED gstreamer-audio-1.0) include_directories( ${GLIB_INCLUDE_DIRS} ${GSTREAMER_INCLUDE_DIRS} ${GSTREAMER-APP_INCLUDE_DIRS} ${GSTREAMER-AUDIO_INCLUDE_DIRS} ${CMAKE_CURRENT_SOURCE_DIR} ) link_directories( ${GLIB_LIBRARY_DIRS} ${GSTREAMER_LIBRARY_DIRS} ${GSTREAMER-APP_LIBRARY_DIRS} ${GSTREAMER-AUDIO_LIBRARY_DIRS} ) target_include_directories(${PLUGIN_NAME} PRIVATE ${GST_INCLUDE_DIRS} ${GLIB_INCLUDE_DIRS}) target_link_libraries(${PLUGIN_NAME} PRIVATE ${GST_APP_LIBRARIES} ${GLIB_LIBRARIES}) target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) target_include_directories(${PLUGIN_NAME} INTERFACE "${CMAKE_CURRENT_SOURCE_DIR}/include") target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) ``` -------------------------------- ### Bundled libraries configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/linux/CMakeLists.txt Defines a list of absolute paths to libraries that should be bundled with the plugin. ```cmake # List of absolute paths to libraries that should be bundled with the plugin set(audioplayers_linux_bundled_libraries "" PARENT_SCOPE ) ``` -------------------------------- ### Apply CMP0091 Policy in CMakeLists.txt Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_windows/README.md Alternatively, explicitly set the CMP0091 CMake policy to NEW before the project() command in your CMakeLists.txt to resolve compatibility issues. ```diff cmake_policy(SET CMP0091 NEW) project(my_project_name LANGUAGES CXX) ``` -------------------------------- ### Enable Unicode Support Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Adds definitions to enable Unicode support for all projects. This ensures proper handling of international characters. ```cmake add_definitions(-DUNICODE -D_UNICODE) ``` -------------------------------- ### Define Profile Build Mode Settings Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Sets linker and compiler flags for the Profile build mode, mirroring the settings for the Release build mode. This ensures consistent performance tuning. ```cmake set(CMAKE_EXE_LINKER_FLAGS_PROFILE "${CMAKE_EXE_LINKER_FLAGS_RELEASE}") set(CMAKE_SHARED_LINKER_FLAGS_PROFILE "${CMAKE_SHARED_LINKER_FLAGS_RELEASE}") set(CMAKE_C_FLAGS_PROFILE "${CMAKE_C_FLAGS_RELEASE}") set(CMAKE_CXX_FLAGS_PROFILE "${CMAKE_CXX_FLAGS_RELEASE}") ``` -------------------------------- ### Configure Build Types for Multi-Config Generators Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Sets the available build configurations (Debug, Profile, Release) when using a multi-configuration generator. This allows for flexible build options. ```cmake get_property(IS_MULTICONFIG GLOBAL PROPERTY GENERATOR_IS_MULTI_CONFIG) if(IS_MULTICONFIG) set(CMAKE_CONFIGURATION_TYPES "Debug;Profile;Release" CACHE STRING "" FORCE) else() if(NOT CMAKE_BUILD_TYPE AND NOT CMAKE_CONFIGURATION_TYPES) set(CMAKE_BUILD_TYPE "Debug" CACHE STRING "Flutter build mode" FORCE) set_property(CACHE CMAKE_BUILD_TYPE PROPERTY STRINGS "Debug" "Profile" "Release") endif() endif() ``` -------------------------------- ### Apply Standard Compilation Settings Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers/example/windows/CMakeLists.txt Defines a function to apply standard compilation settings to a target, including C++17 standard, warning levels, exception handling, and debug definitions. ```cmake function(APPLY_STANDARD_SETTINGS TARGET) target_compile_features(${TARGET} PUBLIC cxx_std_17) target_compile_options(${TARGET} PRIVATE /W4 /WX /wd"4100") target_compile_options(${TARGET} PRIVATE /EHsc) target_compile_definitions(${TARGET} PRIVATE "_HAS_EXCEPTIONS=0") target_compile_definitions(${TARGET} PRIVATE "$:_DEBUG") endfunction() ``` -------------------------------- ### Main CMakeLists.txt configuration Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_linux/linux/CMakeLists.txt This snippet shows the main configuration for the audioplayers_linux plugin, including setting the project name, defining the library, and including standard settings. ```cmake cmake_minimum_required(VERSION 3.10) set(PROJECT_NAME "audioplayers_linux") project(${PROJECT_NAME} LANGUAGES CXX) include(FetchContent) # This value is used when generating builds using this plugin, so it must # not be changed set(PLUGIN_NAME "${PROJECT_NAME}_plugin") add_library(${PLUGIN_NAME} SHARED "audioplayers_linux_plugin.cc" "audio_player.h" "audio_player.cc" ) apply_standard_settings(${PLUGIN_NAME}) set_target_properties(${PLUGIN_NAME} PROPERTIES CXX_VISIBILITY_PRESET hidden) target_compile_features(${PLUGIN_NAME} PRIVATE cxx_std_17) ``` -------------------------------- ### Update CMakeLists.txt for Windows Source: https://github.com/bluefireteam/audioplayers/blob/main/packages/audioplayers_windows/README.md Modify your project's CMakeLists.txt to ensure compatibility with newer CMake policies required by audioplayers. This involves updating the minimum required CMake version. ```diff cmake_minimum_required(VERSION 3.14) # ... cmake_policy(VERSION 3.14...3.25) ``` ```diff cmake_minimum_required(VERSION 3.15) # ... cmake_policy(VERSION 3.15...3.25) ```