├── example ├── linux │ ├── .gitignore │ ├── flutter │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugins.cmake │ │ └── CMakeLists.txt │ ├── main.cc │ ├── my_application.h │ ├── my_application.cc │ └── CMakeLists.txt ├── windows │ ├── flutter │ │ ├── .template_version │ │ ├── generated_plugin_registrant.h │ │ ├── generated_plugin_registrant.cc │ │ ├── generated_plugins.cmake │ │ └── CMakeLists.txt │ ├── runner │ │ ├── resources │ │ │ └── app_icon.ico │ │ ├── utils.h │ │ ├── resource.h │ │ ├── utils.cpp │ │ ├── CMakeLists.txt │ │ ├── runner.exe.manifest │ │ ├── run_loop.h │ │ ├── main.cpp │ │ ├── flutter_window.h │ │ ├── Runner.rc │ │ ├── flutter_window.cpp │ │ ├── run_loop.cpp │ │ ├── win32_window.h │ │ └── win32_window.cpp │ ├── .gitignore │ └── CMakeLists.txt ├── README.md ├── .metadata ├── pubspec.yaml ├── .gitignore ├── pubspec.lock └── lib │ └── main.dart ├── lib ├── source │ ├── core │ │ ├── channel.dart │ │ ├── devices.dart │ │ └── events.dart │ ├── types │ │ ├── audio.dart │ │ └── source.dart │ └── main.dart └── flutter_audio_desktop.dart ├── windows ├── .gitignore ├── include │ └── flutter_audio_desktop │ │ ├── flutter_audio_desktop_plugin.h │ │ └── flutter_types.hpp ├── CMakeLists.txt └── flutter_audio_desktop_plugin.cpp ├── .gitignore ├── linux ├── include │ └── flutter_audio_desktop │ │ ├── flutter_audio_desktop_plugin.h │ │ └── flutter_types.hpp ├── CMakeLists.txt └── flutter_audio_desktop_plugin.cc ├── pubspec.yaml ├── audioplayer ├── internal │ ├── callbacks.hpp │ └── audiodevices.hpp ├── main.cpp └── audioplayer.hpp ├── flutter_audio_desktop.iml ├── LICENSE ├── README.md ├── CHANGELOG.md └── pubspec.lock /example/linux/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral 2 | -------------------------------------------------------------------------------- /example/windows/flutter/.template_version: -------------------------------------------------------------------------------- 1 | 7 2 | -------------------------------------------------------------------------------- /example/windows/runner/resources/app_icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/alexmercerind/flutter_audio_desktop/HEAD/example/windows/runner/resources/app_icon.ico -------------------------------------------------------------------------------- /example/README.md: -------------------------------------------------------------------------------- 1 | # [flutter_audio_desktop_example](https://github.com/alexmercerind/flutter_audio_desktop) 2 | 3 | Demonstrates how to use the flutter_audio_desktop plugin. -------------------------------------------------------------------------------- /lib/source/core/channel.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter/services.dart'; 2 | 3 | /// Internal method channel used by plugin. 4 | final MethodChannel channel = MethodChannel('flutter_audio_desktop'); 5 | -------------------------------------------------------------------------------- /example/windows/runner/utils.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_UTILS_H_ 2 | #define RUNNER_UTILS_H_ 3 | 4 | // Creates a console for the process, and redirects stdout and stderr to 5 | // it for both the runner and the Flutter library. 6 | void CreateAndAttachConsole(); 7 | 8 | #endif // RUNNER_UTILS_H_ 9 | -------------------------------------------------------------------------------- /example/.metadata: -------------------------------------------------------------------------------- 1 | # This file tracks properties of this Flutter project. 2 | # Used by Flutter tool to assess capabilities and perform upgrades etc. 3 | # 4 | # This file should be version controlled and should not be manually edited. 5 | 6 | version: 7 | revision: ce40de69b7b4f89c66d19c8dbd3bd86ae30f1bc6 8 | channel: dev 9 | 10 | project_type: app 11 | -------------------------------------------------------------------------------- /windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # vscode 2 | 3 | .vscode 4 | 5 | # audio 6 | 7 | *.mp3 8 | 9 | # dart 10 | 11 | .dart_tool 12 | .packages 13 | 14 | # flutter 15 | 16 | .flutter-plugins 17 | .flutter-plugins-dependencies 18 | 19 | # miniaudio: https://github.com/mackron/miniaudio 20 | # Get miniaudio.h & miniaudio_engine.h from the link above & place at the following location. 21 | audioplayer/miniaudio/* -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 6 | #define GENERATED_PLUGIN_REGISTRANT_ 7 | 8 | #include 9 | 10 | // Registers Flutter plugins. 11 | void fl_register_plugins(FlPluginRegistry* registry); 12 | 13 | #endif // GENERATED_PLUGIN_REGISTRANT_ 14 | -------------------------------------------------------------------------------- /example/windows/.gitignore: -------------------------------------------------------------------------------- 1 | flutter/ephemeral/ 2 | 3 | # Visual Studio user-specific files. 4 | *.suo 5 | *.user 6 | *.userosscache 7 | *.sln.docstates 8 | 9 | # Visual Studio build-related files. 10 | x64/ 11 | x86/ 12 | 13 | # Visual Studio cache files 14 | # files ending in .cache can be ignored 15 | *.[Cc]ache 16 | # but keep track of directories ending in .cache 17 | !*.[Cc]ache/ 18 | -------------------------------------------------------------------------------- /example/linux/main.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | int main(int argc, char** argv) { 4 | // Only X11 is currently supported. 5 | // Wayland support is being developed: https://github.com/flutter/flutter/issues/57932. 6 | gdk_set_allowed_backends("x11"); 7 | 8 | g_autoptr(MyApplication) app = my_application_new(); 9 | return g_application_run(G_APPLICATION(app), argc, argv); 10 | } 11 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.h: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #ifndef GENERATED_PLUGIN_REGISTRANT_ 8 | #define GENERATED_PLUGIN_REGISTRANT_ 9 | 10 | #include 11 | 12 | // Registers Flutter plugins. 13 | void RegisterPlugins(flutter::PluginRegistry* registry); 14 | 15 | #endif // GENERATED_PLUGIN_REGISTRANT_ 16 | -------------------------------------------------------------------------------- /example/pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_audio_desktop_example 2 | description: Demonstrates how to use the flutter_audio_desktop plugin. 3 | 4 | publish_to: 'none' 5 | 6 | environment: 7 | sdk: ">=2.7.0 <3.0.0" 8 | 9 | dependencies: 10 | flutter: 11 | sdk: flutter 12 | 13 | flutter_audio_desktop: 14 | path: ../ 15 | 16 | dev_dependencies: 17 | flutter_test: 18 | sdk: flutter 19 | 20 | flutter: 21 | uses-material-design: true -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | // clang-format off 6 | 7 | #include "generated_plugin_registrant.h" 8 | 9 | #include 10 | 11 | void RegisterPlugins(flutter::PluginRegistry* registry) { 12 | FlutterAudioDesktopPluginRegisterWithRegistrar( 13 | registry->GetRegistrarForPlugin("FlutterAudioDesktopPlugin")); 14 | } 15 | -------------------------------------------------------------------------------- /lib/flutter_audio_desktop.dart: -------------------------------------------------------------------------------- 1 | export 'package:flutter_audio_desktop/source/main.dart'; 2 | export 'package:flutter_audio_desktop/source/types/source.dart'; 3 | export 'package:flutter_audio_desktop/source/types/audio.dart'; 4 | export 'package:flutter_audio_desktop/source/core/devices.dart'; 5 | 6 | const String title = "flutter_audio_desktop"; 7 | const String author = "alexmercerind"; 8 | const String license = "MIT"; 9 | const String version = "0.0.9"; 10 | -------------------------------------------------------------------------------- /example/linux/my_application.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_MY_APPLICATION_H_ 2 | #define FLUTTER_MY_APPLICATION_H_ 3 | 4 | #include 5 | 6 | G_DECLARE_FINAL_TYPE(MyApplication, my_application, MY, APPLICATION, 7 | GtkApplication) 8 | 9 | /** 10 | * my_application_new: 11 | * 12 | * Creates a new Flutter-based application. 13 | * 14 | * Returns: a new #MyApplication. 15 | */ 16 | MyApplication* my_application_new(); 17 | 18 | #endif // FLUTTER_MY_APPLICATION_H_ 19 | -------------------------------------------------------------------------------- /example/windows/runner/resource.h: -------------------------------------------------------------------------------- 1 | //{{NO_DEPENDENCIES}} 2 | // Microsoft Visual C++ generated include file. 3 | // Used by Runner.rc 4 | // 5 | #define IDI_APP_ICON 101 6 | 7 | // Next default values for new objects 8 | // 9 | #ifdef APSTUDIO_INVOKED 10 | #ifndef APSTUDIO_READONLY_SYMBOLS 11 | #define _APS_NEXT_RESOURCE_VALUE 102 12 | #define _APS_NEXT_COMMAND_VALUE 40001 13 | #define _APS_NEXT_CONTROL_VALUE 1001 14 | #define _APS_NEXT_SYMED_VALUE 101 15 | #endif 16 | #endif 17 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugin_registrant.cc: -------------------------------------------------------------------------------- 1 | // 2 | // Generated file. Do not edit. 3 | // 4 | 5 | #include "generated_plugin_registrant.h" 6 | 7 | #include 8 | 9 | void fl_register_plugins(FlPluginRegistry* registry) { 10 | g_autoptr(FlPluginRegistrar) flutter_audio_desktop_registrar = 11 | fl_plugin_registry_get_registrar_for_plugin(registry, "FlutterAudioDesktopPlugin"); 12 | flutter_audio_desktop_plugin_register_with_registrar(flutter_audio_desktop_registrar); 13 | } 14 | -------------------------------------------------------------------------------- /example/linux/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | flutter_audio_desktop 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/linux plugins/${plugin}) 13 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 16 | endforeach(plugin) 17 | -------------------------------------------------------------------------------- /example/windows/flutter/generated_plugins.cmake: -------------------------------------------------------------------------------- 1 | # 2 | # Generated file, do not edit. 3 | # 4 | 5 | list(APPEND FLUTTER_PLUGIN_LIST 6 | flutter_audio_desktop 7 | ) 8 | 9 | set(PLUGIN_BUNDLED_LIBRARIES) 10 | 11 | foreach(plugin ${FLUTTER_PLUGIN_LIST}) 12 | add_subdirectory(flutter/ephemeral/.plugin_symlinks/${plugin}/windows plugins/${plugin}) 13 | target_link_libraries(${BINARY_NAME} PRIVATE ${plugin}_plugin) 14 | list(APPEND PLUGIN_BUNDLED_LIBRARIES $) 15 | list(APPEND PLUGIN_BUNDLED_LIBRARIES ${${plugin}_bundled_libraries}) 16 | endforeach(plugin) 17 | -------------------------------------------------------------------------------- /example/windows/runner/utils.cpp: -------------------------------------------------------------------------------- 1 | #include "utils.h" 2 | 3 | #include 4 | #include 5 | #include 6 | #include 7 | 8 | #include 9 | 10 | void CreateAndAttachConsole() { 11 | if (::AllocConsole()) { 12 | FILE *unused; 13 | if (freopen_s(&unused, "CONOUT$", "w", stdout)) { 14 | _dup2(_fileno(stdout), 1); 15 | } 16 | if (freopen_s(&unused, "CONOUT$", "w", stderr)) { 17 | _dup2(_fileno(stdout), 2); 18 | } 19 | std::ios::sync_with_stdio(); 20 | FlutterDesktopResyncOutputStreams(); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /example/windows/runner/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | project(runner LANGUAGES CXX) 3 | 4 | add_executable(${BINARY_NAME} WIN32 5 | "flutter_window.cpp" 6 | "main.cpp" 7 | "run_loop.cpp" 8 | "utils.cpp" 9 | "win32_window.cpp" 10 | "${FLUTTER_MANAGED_DIR}/generated_plugin_registrant.cc" 11 | "Runner.rc" 12 | "runner.exe.manifest" 13 | ) 14 | apply_standard_settings(${BINARY_NAME}) 15 | target_compile_definitions(${BINARY_NAME} PRIVATE "NOMINMAX") 16 | target_link_libraries(${BINARY_NAME} PRIVATE flutter flutter_wrapper_app) 17 | target_include_directories(${BINARY_NAME} PRIVATE "${CMAKE_SOURCE_DIR}") 18 | add_dependencies(${BINARY_NAME} flutter_assemble) 19 | -------------------------------------------------------------------------------- /lib/source/types/audio.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | class Audio { 4 | /// Currently loaded [File]. 5 | File file; 6 | 7 | /// Current playback state of audio player. 8 | bool isPlaying; 9 | 10 | /// Audio source completion state of audio player. 11 | bool isCompleted; 12 | 13 | /// Whether an [AudioSource] is loaded or not. 14 | bool isStopped; 15 | 16 | /// Current position of playback in [Duration]. 17 | Duration position; 18 | 19 | /// [Duration] of currently loaded audio source. 20 | Duration duration; 21 | 22 | Audio( 23 | {this.file, 24 | this.isPlaying, 25 | this.isStopped, 26 | this.isCompleted, 27 | this.position, 28 | this.duration}); 29 | } 30 | -------------------------------------------------------------------------------- /windows/include/flutter_audio_desktop/flutter_audio_desktop_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_FLUTTER_AUDIO_DESKTOP_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_FLUTTER_AUDIO_DESKTOP_PLUGIN_H_ 3 | 4 | #include 5 | 6 | #ifdef FLUTTER_PLUGIN_IMPL 7 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllexport) 8 | #else 9 | #define FLUTTER_PLUGIN_EXPORT __declspec(dllimport) 10 | #endif 11 | 12 | #if defined(__cplusplus) 13 | extern "C" { 14 | #endif 15 | 16 | FLUTTER_PLUGIN_EXPORT void FlutterAudioDesktopPluginRegisterWithRegistrar( 17 | FlutterDesktopPluginRegistrarRef registrar); 18 | 19 | #if defined(__cplusplus) 20 | } // extern "C" 21 | #endif 22 | 23 | #endif // FLUTTER_PLUGIN_FLUTTER_AUDIO_DESKTOP_PLUGIN_H_ 24 | -------------------------------------------------------------------------------- /example/.gitignore: -------------------------------------------------------------------------------- 1 | # Miscellaneous 2 | *.class 3 | *.log 4 | *.pyc 5 | *.swp 6 | .DS_Store 7 | .atom/ 8 | .buildlog/ 9 | .history 10 | .svn/ 11 | 12 | # IntelliJ related 13 | *.iml 14 | *.ipr 15 | *.iws 16 | .idea/ 17 | 18 | # The .vscode folder contains launch configuration and tasks you configure in 19 | # VS Code which you may wish to be included in version control, so this line 20 | # is commented out by default. 21 | #.vscode/ 22 | 23 | # Flutter/Dart/Pub related 24 | **/doc/api/ 25 | **/ios/Flutter/.last_build_id 26 | .dart_tool/ 27 | .flutter-plugins 28 | .flutter-plugins-dependencies 29 | .packages 30 | .pub-cache/ 31 | .pub/ 32 | /build/ 33 | 34 | # Web related 35 | lib/generated_plugin_registrant.dart 36 | 37 | # Symbolication related 38 | app.*.symbols 39 | 40 | # Obfuscation related 41 | app.*.map.json 42 | -------------------------------------------------------------------------------- /linux/include/flutter_audio_desktop/flutter_audio_desktop_plugin.h: -------------------------------------------------------------------------------- 1 | #ifndef FLUTTER_PLUGIN_FLUTTER_AUDIO_DESKTOP_PLUGIN_H_ 2 | #define FLUTTER_PLUGIN_FLUTTER_AUDIO_DESKTOP_PLUGIN_H_ 3 | 4 | #include 5 | 6 | G_BEGIN_DECLS 7 | 8 | #ifdef FLUTTER_PLUGIN_IMPL 9 | #define FLUTTER_PLUGIN_EXPORT __attribute__((visibility("default"))) 10 | #else 11 | #define FLUTTER_PLUGIN_EXPORT 12 | #endif 13 | 14 | typedef struct _FlutterAudioDesktopPlugin FlutterAudioDesktopPlugin; 15 | typedef struct { 16 | GObjectClass parent_class; 17 | } FlutterAudioDesktopPluginClass; 18 | 19 | FLUTTER_PLUGIN_EXPORT GType flutter_audio_desktop_plugin_get_type(); 20 | 21 | FLUTTER_PLUGIN_EXPORT void flutter_audio_desktop_plugin_register_with_registrar( 22 | FlPluginRegistrar* registrar); 23 | 24 | G_END_DECLS 25 | 26 | #endif 27 | -------------------------------------------------------------------------------- /pubspec.yaml: -------------------------------------------------------------------------------- 1 | name: flutter_audio_desktop 2 | description: An audio playback library for Flutter Desktop. Supports Windows & Linux. Based on miniaudio. 3 | version: 0.1.0 4 | homepage: https://github.com/alexmercerind/flutter_audio_desktop 5 | repository: https://github.com/alexmercerind/flutter_audio_desktop 6 | documentation: https://github.com/alexmercerind/flutter_audio_desktop/blob/master/README.md 7 | 8 | environment: 9 | sdk: ">=2.7.0 <3.0.0" 10 | flutter: ">=1.20.0" 11 | 12 | dependencies: 13 | flutter: 14 | sdk: flutter 15 | path: ^1.7.0 16 | path_provider: ^2.0.0 17 | 18 | dev_dependencies: 19 | flutter_test: 20 | sdk: flutter 21 | flutter: 22 | plugin: 23 | platforms: 24 | linux: 25 | pluginClass: FlutterAudioDesktopPlugin 26 | windows: 27 | pluginClass: FlutterAudioDesktopPlugin -------------------------------------------------------------------------------- /audioplayer/internal/callbacks.hpp: -------------------------------------------------------------------------------- 1 | #include "../miniaudio/miniaudio.h" 2 | 3 | 4 | void dataCallbackStream(ma_device* pDevice, void* pOutput, const void* pInput, ma_uint32 frameCount) { 5 | ma_data_source_read_pcm_frames((ma_data_source*)pDevice->pUserData, pOutput, frameCount, NULL, MA_TRUE); 6 | (void)pInput; 7 | } 8 | 9 | void dataCallbackWave(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount) { 10 | ma_waveform *pSineWave; 11 | pSineWave = (ma_waveform *)pDevice->pUserData; 12 | ma_waveform_read_pcm_frames(pSineWave, pOutput, frameCount); 13 | (void)pInput; 14 | } 15 | 16 | void dataCallbackNoise(ma_device *pDevice, void *pOutput, const void *pInput, ma_uint32 frameCount) { 17 | ma_noise *pNoise; 18 | pNoise = (ma_noise *)pDevice->pUserData; 19 | ma_noise_read_pcm_frames(pNoise, pOutput, frameCount); 20 | (void)pInput; 21 | } 22 | -------------------------------------------------------------------------------- /linux/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | set(PROJECT_NAME "flutter_audio_desktop") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | set(PLUGIN_NAME "${PROJECT_NAME}_plugin") 6 | 7 | add_library(${PLUGIN_NAME} SHARED 8 | "${PLUGIN_NAME}.cc" 9 | ) 10 | apply_standard_settings(${PLUGIN_NAME}) 11 | set_target_properties(${PLUGIN_NAME} PROPERTIES 12 | CXX_VISIBILITY_PRESET hidden) 13 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 14 | list(APPEND includePath "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../audioplayer") 15 | target_include_directories(${PLUGIN_NAME} INTERFACE 16 | "$" 17 | ) 18 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter) 19 | target_link_libraries(${PLUGIN_NAME} PRIVATE PkgConfig::GTK) 20 | set(flutter_audio_desktop_bundled_libraries 21 | "" 22 | PARENT_SCOPE 23 | ) 24 | -------------------------------------------------------------------------------- /windows/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.15) 2 | set(PROJECT_NAME "flutter_audio_desktop") 3 | project(${PROJECT_NAME} LANGUAGES CXX) 4 | 5 | set(PLUGIN_NAME "${PROJECT_NAME}_plugin") 6 | 7 | add_library(${PLUGIN_NAME} SHARED 8 | "${PLUGIN_NAME}.cpp" 9 | ) 10 | apply_standard_settings(${PLUGIN_NAME}) 11 | set_target_properties(${PLUGIN_NAME} PROPERTIES 12 | CXX_VISIBILITY_PRESET hidden) 13 | target_compile_definitions(${PLUGIN_NAME} PRIVATE FLUTTER_PLUGIN_IMPL) 14 | list(APPEND includePath "${CMAKE_CURRENT_SOURCE_DIR}/include" "${CMAKE_CURRENT_SOURCE_DIR}/../audioplayer") 15 | target_include_directories(${PLUGIN_NAME} INTERFACE 16 | "$" 17 | ) 18 | target_link_libraries(${PLUGIN_NAME} PRIVATE flutter flutter_wrapper_plugin) 19 | 20 | # List of absolute paths to libraries that should be bundled with the plugin 21 | set(flutter_audio_desktop_bundled_libraries 22 | "" 23 | PARENT_SCOPE 24 | ) 25 | -------------------------------------------------------------------------------- /example/windows/runner/runner.exe.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | PerMonitorV2 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | -------------------------------------------------------------------------------- /flutter_audio_desktop.iml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2021 Hitesh Kumar Saini 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /example/windows/runner/run_loop.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_RUN_LOOP_H_ 2 | #define RUNNER_RUN_LOOP_H_ 3 | 4 | #include 5 | 6 | #include 7 | #include 8 | 9 | // A runloop that will service events for Flutter instances as well 10 | // as native messages. 11 | class RunLoop { 12 | public: 13 | RunLoop(); 14 | ~RunLoop(); 15 | 16 | // Prevent copying 17 | RunLoop(RunLoop const&) = delete; 18 | RunLoop& operator=(RunLoop const&) = delete; 19 | 20 | // Runs the run loop until the application quits. 21 | void Run(); 22 | 23 | // Registers the given Flutter instance for event servicing. 24 | void RegisterFlutterInstance( 25 | flutter::FlutterEngine* flutter_instance); 26 | 27 | // Unregisters the given Flutter instance from event servicing. 28 | void UnregisterFlutterInstance( 29 | flutter::FlutterEngine* flutter_instance); 30 | 31 | private: 32 | using TimePoint = std::chrono::steady_clock::time_point; 33 | 34 | // Processes all currently pending messages for registered Flutter instances. 35 | TimePoint ProcessFlutterMessages(); 36 | 37 | std::set flutter_instances_; 38 | }; 39 | 40 | #endif // RUNNER_RUN_LOOP_H_ 41 | -------------------------------------------------------------------------------- /example/windows/runner/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "flutter_window.h" 6 | #include "run_loop.h" 7 | #include "utils.h" 8 | 9 | int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, 10 | _In_ wchar_t *command_line, _In_ int show_command) { 11 | // Attach to console when present (e.g., 'flutter run') or create a 12 | // new console when running with a debugger. 13 | if (!::AttachConsole(ATTACH_PARENT_PROCESS) && ::IsDebuggerPresent()) { 14 | CreateAndAttachConsole(); 15 | } 16 | 17 | // Initialize COM, so that it is available for use in the library and/or 18 | // plugins. 19 | ::CoInitializeEx(nullptr, COINIT_APARTMENTTHREADED); 20 | 21 | RunLoop run_loop; 22 | 23 | flutter::DartProject project(L"data"); 24 | FlutterWindow window(&run_loop, project); 25 | Win32Window::Point origin(10, 10); 26 | Win32Window::Size size(1280, 720); 27 | if (!window.CreateAndShow(L"flutter_audio_desktop_example", origin, size)) { 28 | return EXIT_FAILURE; 29 | } 30 | window.SetQuitOnClose(true); 31 | 32 | run_loop.Run(); 33 | 34 | ::CoUninitialize(); 35 | return EXIT_SUCCESS; 36 | } 37 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.h: -------------------------------------------------------------------------------- 1 | #ifndef RUNNER_FLUTTER_WINDOW_H_ 2 | #define RUNNER_FLUTTER_WINDOW_H_ 3 | 4 | #include 5 | #include 6 | 7 | #include 8 | 9 | #include "run_loop.h" 10 | #include "win32_window.h" 11 | 12 | // A window that does nothing but host a Flutter view. 13 | class FlutterWindow : public Win32Window { 14 | public: 15 | // Creates a new FlutterWindow driven by the |run_loop|, hosting a 16 | // Flutter view running |project|. 17 | explicit FlutterWindow(RunLoop* run_loop, 18 | const flutter::DartProject& project); 19 | virtual ~FlutterWindow(); 20 | 21 | protected: 22 | // Win32Window: 23 | bool OnCreate() override; 24 | void OnDestroy() override; 25 | LRESULT MessageHandler(HWND window, UINT const message, WPARAM const wparam, 26 | LPARAM const lparam) noexcept override; 27 | 28 | private: 29 | // The run loop driving events for this window. 30 | RunLoop* run_loop_; 31 | 32 | // The project to run. 33 | flutter::DartProject project_; 34 | 35 | // The Flutter instance hosted by this window. 36 | std::unique_ptr flutter_controller_; 37 | }; 38 | 39 | #endif // RUNNER_FLUTTER_WINDOW_H_ 40 | -------------------------------------------------------------------------------- /audioplayer/main.cpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include "audioplayer.hpp" 5 | 6 | 7 | class AudioPlayers { 8 | public: 9 | AudioPlayers() { 10 | this->audioDevices = AudioDevices::getAll(); 11 | } 12 | 13 | AudioPlayer* get(int id, std::string deviceId = "default") { 14 | if (this->audioPlayers.find(id) == this->audioPlayers.end()) { 15 | AudioDevice* preferredAudioDevice = nullptr; 16 | if (deviceId != "default") { 17 | for (AudioDevice* audioDevice: this->audioDevices) { 18 | if (std::to_string(audioDevice->id) == deviceId) { 19 | preferredAudioDevice = audioDevice; 20 | break; 21 | }; 22 | } 23 | } 24 | this->audioPlayers[id] = new AudioPlayer(preferredAudioDevice); 25 | } 26 | return this->audioPlayers[id]; 27 | } 28 | 29 | private: 30 | std::map audioPlayers; 31 | std::vector audioDevices; 32 | }; 33 | 34 | 35 | AudioPlayers* audioPlayers = new AudioPlayers(); 36 | 37 | 38 | int main(int argc, const char **argv) { 39 | try { 40 | AudioDevices::getDefault(); 41 | AudioPlayer* audioPlayer = audioPlayers->get(0); 42 | audioPlayer->load(argv[1]); 43 | audioPlayer->play(); 44 | std::cin.get(); 45 | } 46 | catch (std::string exception) { 47 | std::cout << exception << std::endl; 48 | } 49 | return 0; 50 | } -------------------------------------------------------------------------------- /example/linux/my_application.cc: -------------------------------------------------------------------------------- 1 | #include "my_application.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | struct _MyApplication { 8 | GtkApplication parent_instance; 9 | }; 10 | 11 | G_DEFINE_TYPE(MyApplication, my_application, GTK_TYPE_APPLICATION) 12 | 13 | // Implements GApplication::activate. 14 | static void my_application_activate(GApplication* application) { 15 | GtkWindow* window = 16 | GTK_WINDOW(gtk_application_window_new(GTK_APPLICATION(application))); 17 | GtkHeaderBar *header_bar = GTK_HEADER_BAR(gtk_header_bar_new()); 18 | gtk_widget_show(GTK_WIDGET(header_bar)); 19 | gtk_header_bar_set_title(header_bar, "flutter_audio_desktop"); 20 | gtk_header_bar_set_show_close_button(header_bar, TRUE); 21 | gtk_window_set_titlebar(window, GTK_WIDGET(header_bar)); 22 | gtk_window_set_default_size(window, 600, 720); 23 | gtk_widget_show(GTK_WIDGET(window)); 24 | 25 | g_autoptr(FlDartProject) project = fl_dart_project_new(); 26 | 27 | FlView* view = fl_view_new(project); 28 | gtk_widget_show(GTK_WIDGET(view)); 29 | gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(view)); 30 | 31 | fl_register_plugins(FL_PLUGIN_REGISTRY(view)); 32 | 33 | gtk_widget_grab_focus(GTK_WIDGET(view)); 34 | } 35 | 36 | static void my_application_class_init(MyApplicationClass* klass) { 37 | G_APPLICATION_CLASS(klass)->activate = my_application_activate; 38 | } 39 | 40 | static void my_application_init(MyApplication* self) {} 41 | 42 | MyApplication* my_application_new() { 43 | return MY_APPLICATION(g_object_new(my_application_get_type(), 44 | "application-id", APPLICATION_ID, 45 | nullptr)); 46 | } 47 | -------------------------------------------------------------------------------- /example/windows/runner/Runner.rc: -------------------------------------------------------------------------------- 1 | // Microsoft Visual C++ generated resource script. 2 | // 3 | #pragma code_page(65001) 4 | #include "resource.h" 5 | 6 | #define APSTUDIO_READONLY_SYMBOLS 7 | ///////////////////////////////////////////////////////////////////////////// 8 | // 9 | // Generated from the TEXTINCLUDE 2 resource. 10 | // 11 | #include "winres.h" 12 | 13 | ///////////////////////////////////////////////////////////////////////////// 14 | #undef APSTUDIO_READONLY_SYMBOLS 15 | 16 | ///////////////////////////////////////////////////////////////////////////// 17 | // English (United States) resources 18 | 19 | #if !defined(AFX_RESOURCE_DLL) || defined(AFX_TARG_ENU) 20 | LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US 21 | 22 | #ifdef APSTUDIO_INVOKED 23 | ///////////////////////////////////////////////////////////////////////////// 24 | // 25 | // TEXTINCLUDE 26 | // 27 | 28 | 1 TEXTINCLUDE 29 | BEGIN 30 | "resource.h\0" 31 | END 32 | 33 | 2 TEXTINCLUDE 34 | BEGIN 35 | "#include ""winres.h""\r\n" 36 | "\0" 37 | END 38 | 39 | 3 TEXTINCLUDE 40 | BEGIN 41 | "\r\n" 42 | "\0" 43 | END 44 | 45 | #endif // APSTUDIO_INVOKED 46 | 47 | 48 | ///////////////////////////////////////////////////////////////////////////// 49 | // 50 | // Icon 51 | // 52 | 53 | // Icon with lowest ID value placed first to ensure application icon 54 | // remains consistent on all systems. 55 | IDI_APP_ICON ICON "resources\\app_icon.ico" 56 | 57 | #endif // English (United States) resources 58 | ///////////////////////////////////////////////////////////////////////////// 59 | 60 | 61 | 62 | #ifndef APSTUDIO_INVOKED 63 | ///////////////////////////////////////////////////////////////////////////// 64 | // 65 | // Generated from the TEXTINCLUDE 3 resource. 66 | // 67 | 68 | 69 | ///////////////////////////////////////////////////////////////////////////// 70 | #endif // not APSTUDIO_INVOKED 71 | -------------------------------------------------------------------------------- /lib/source/core/devices.dart: -------------------------------------------------------------------------------- 1 | import 'package:flutter_audio_desktop/source/core/channel.dart'; 2 | 3 | class AudioDevice { 4 | /// ID of this audio device. 5 | final String id; 6 | 7 | /// Name of this audio device. 8 | final String name; 9 | 10 | /// A playback audio device connected to the device. 11 | AudioDevice(this.id, this.name); 12 | } 13 | 14 | class AudioDevices { 15 | /// ### Gets all connected playback devices 16 | /// 17 | /// Returns [List] of all [AudioDevice] connected to the device. 18 | /// 19 | /// ```dart 20 | /// List devices = await AudioDevices.allDevices; 21 | /// ``` 22 | /// 23 | static Future> get allDevices async { 24 | List devices = []; 25 | var devicesMap = await channel.invokeMethod( 26 | 'getDevices', 27 | {}, 28 | ); 29 | devicesMap.forEach((id, name) { 30 | if (id != 'default') 31 | devices.add( 32 | new AudioDevice( 33 | id?.toString(), 34 | name?.toString(), 35 | ), 36 | ); 37 | }); 38 | return devices; 39 | } 40 | 41 | /// ### Gets default connected playback device 42 | /// 43 | /// Returns default [AudioDevice] with id `'default'`. 44 | /// 45 | /// ```dart 46 | /// List devices = await AudioDevices.allDevices; 47 | /// ``` 48 | /// 49 | static Future get defaultDevice async { 50 | AudioDevice defaultDevice; 51 | var devicesMap = await channel.invokeMethod( 52 | 'getDevices', 53 | {}, 54 | ); 55 | devicesMap.forEach((id, name) { 56 | if (id == 'default') 57 | defaultDevice = new AudioDevice( 58 | id?.toString(), 59 | name?.toString(), 60 | ); 61 | }); 62 | if (defaultDevice == null) { 63 | throw 'EXCEPTION: Could not find the default device.'; 64 | } 65 | return defaultDevice; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /example/windows/runner/flutter_window.cpp: -------------------------------------------------------------------------------- 1 | #include "flutter_window.h" 2 | 3 | #include 4 | 5 | #include "flutter/generated_plugin_registrant.h" 6 | 7 | FlutterWindow::FlutterWindow(RunLoop* run_loop, 8 | const flutter::DartProject& project) 9 | : run_loop_(run_loop), project_(project) {} 10 | 11 | FlutterWindow::~FlutterWindow() {} 12 | 13 | bool FlutterWindow::OnCreate() { 14 | if (!Win32Window::OnCreate()) { 15 | return false; 16 | } 17 | 18 | RECT frame = GetClientArea(); 19 | 20 | // The size here must match the window dimensions to avoid unnecessary surface 21 | // creation / destruction in the startup path. 22 | flutter_controller_ = std::make_unique( 23 | frame.right - frame.left, frame.bottom - frame.top, project_); 24 | // Ensure that basic setup of the controller was successful. 25 | if (!flutter_controller_->engine() || !flutter_controller_->view()) { 26 | return false; 27 | } 28 | RegisterPlugins(flutter_controller_->engine()); 29 | run_loop_->RegisterFlutterInstance(flutter_controller_->engine()); 30 | SetChildContent(flutter_controller_->view()->GetNativeWindow()); 31 | return true; 32 | } 33 | 34 | void FlutterWindow::OnDestroy() { 35 | if (flutter_controller_) { 36 | run_loop_->UnregisterFlutterInstance(flutter_controller_->engine()); 37 | flutter_controller_ = nullptr; 38 | } 39 | 40 | Win32Window::OnDestroy(); 41 | } 42 | 43 | LRESULT 44 | FlutterWindow::MessageHandler(HWND hwnd, UINT const message, 45 | WPARAM const wparam, 46 | LPARAM const lparam) noexcept { 47 | // Give Flutter, including plugins, an opporutunity to handle window messages. 48 | if (flutter_controller_) { 49 | std::optional result = 50 | flutter_controller_->HandleTopLevelWindowProc(hwnd, message, wparam, 51 | lparam); 52 | if (result) { 53 | return *result; 54 | } 55 | } 56 | return Win32Window::MessageHandler(hwnd, message, wparam, lparam); 57 | } 58 | -------------------------------------------------------------------------------- /lib/source/types/source.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | import 'package:flutter/widgets.dart'; 3 | import 'package:flutter/services.dart' show rootBundle; 4 | import 'package:path/path.dart' as path; 5 | import 'package:path_provider/path_provider.dart' as path; 6 | 7 | class AudioSource { 8 | /// ### Creates a new audio source for loading in AudioPlayer. 9 | /// 10 | /// This class contains two static methods [AudioSource.fromFile] & [AudioSource.fromAsset]. 11 | /// 12 | /// - Audio source using file. 13 | /// ```dart 14 | /// AudioSource source = await AudioSource.fromFile(new File(filePath)); 15 | /// ``` 16 | /// 17 | /// - Audio source using asset. 18 | /// ```dart 19 | /// AudioSource source = await AudioSource.fromAsset('assets/audio.MP3'); 20 | /// ``` 21 | /// 22 | 23 | AudioSource({@required this.file}); 24 | 25 | /// ### Creates a new audio source using File. 26 | /// 27 | /// Provide a [File] as parameter. 28 | /// 29 | /// Throws [FileSystemException] if the file is not found. 30 | /// 31 | /// ```dart 32 | /// var source = await AudioSource.fromFile(new File(filePath)); 33 | /// ``` 34 | /// 35 | static AudioSource fromFile(File file) { 36 | if (file.existsSync()) { 37 | return new AudioSource(file: file); 38 | } else { 39 | throw FileSystemException('EXCEPTION: File does not exist.', file.path); 40 | } 41 | } 42 | 43 | /// ### Creates a new audio source using File. 44 | /// 45 | /// Provide asset path as [String] in the parameter. 46 | /// 47 | /// 48 | /// ```dart 49 | /// var source = await AudioSource.fromAsset('assets/audio.MP3'); 50 | /// ``` 51 | /// 52 | static Future fromAsset(String asset) async { 53 | String temporaryDirectoryPath = (await path.getTemporaryDirectory()).path; 54 | String temporaryFilePath = path.join( 55 | temporaryDirectoryPath, 56 | 'audio.${asset.split('.').last}', 57 | ); 58 | File audioFile = new File(temporaryFilePath); 59 | await audioFile.writeAsBytes( 60 | (await rootBundle.load(asset)).buffer.asUint8List(), 61 | ); 62 | return new AudioSource( 63 | file: audioFile, 64 | ); 65 | } 66 | 67 | File file; 68 | } 69 | -------------------------------------------------------------------------------- /example/windows/runner/run_loop.cpp: -------------------------------------------------------------------------------- 1 | #include "run_loop.h" 2 | 3 | #include 4 | 5 | #include 6 | 7 | RunLoop::RunLoop() {} 8 | 9 | RunLoop::~RunLoop() {} 10 | 11 | void RunLoop::Run() { 12 | bool keep_running = true; 13 | TimePoint next_flutter_event_time = TimePoint::clock::now(); 14 | while (keep_running) { 15 | std::chrono::nanoseconds wait_duration = 16 | std::max(std::chrono::nanoseconds(0), 17 | next_flutter_event_time - TimePoint::clock::now()); 18 | ::MsgWaitForMultipleObjects( 19 | 0, nullptr, FALSE, static_cast(wait_duration.count() / 1000), 20 | QS_ALLINPUT); 21 | bool processed_events = false; 22 | MSG message; 23 | // All pending Windows messages must be processed; MsgWaitForMultipleObjects 24 | // won't return again for items left in the queue after PeekMessage. 25 | while (::PeekMessage(&message, nullptr, 0, 0, PM_REMOVE)) { 26 | processed_events = true; 27 | if (message.message == WM_QUIT) { 28 | keep_running = false; 29 | break; 30 | } 31 | ::TranslateMessage(&message); 32 | ::DispatchMessage(&message); 33 | // Allow Flutter to process messages each time a Windows message is 34 | // processed, to prevent starvation. 35 | next_flutter_event_time = 36 | std::min(next_flutter_event_time, ProcessFlutterMessages()); 37 | } 38 | // If the PeekMessage loop didn't run, process Flutter messages. 39 | if (!processed_events) { 40 | next_flutter_event_time = 41 | std::min(next_flutter_event_time, ProcessFlutterMessages()); 42 | } 43 | } 44 | } 45 | 46 | void RunLoop::RegisterFlutterInstance( 47 | flutter::FlutterEngine* flutter_instance) { 48 | flutter_instances_.insert(flutter_instance); 49 | } 50 | 51 | void RunLoop::UnregisterFlutterInstance( 52 | flutter::FlutterEngine* flutter_instance) { 53 | flutter_instances_.erase(flutter_instance); 54 | } 55 | 56 | RunLoop::TimePoint RunLoop::ProcessFlutterMessages() { 57 | TimePoint next_event_time = TimePoint::max(); 58 | for (auto instance : flutter_instances_) { 59 | std::chrono::nanoseconds wait_duration = instance->ProcessMessages(); 60 | if (wait_duration != std::chrono::nanoseconds::max()) { 61 | next_event_time = 62 | std::min(next_event_time, TimePoint::clock::now() + wait_duration); 63 | } 64 | } 65 | return next_event_time; 66 | } 67 | -------------------------------------------------------------------------------- /audioplayer/internal/audiodevices.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "../miniaudio/miniaudio.h" 6 | 7 | 8 | class AudioDevice { 9 | public: 10 | int id; 11 | ma_device_info info; 12 | 13 | AudioDevice(int index, ma_device_info info) { 14 | this->id = index; 15 | this->info = info; 16 | } 17 | }; 18 | 19 | ma_context deviceContext; 20 | 21 | class AudioDevices { 22 | public: 23 | static std::vector getAll() { 24 | std::vector audioDevices; 25 | bool success = true; 26 | if (ma_context_init(NULL, 0, NULL, &deviceContext) != 0) { 27 | success = false; 28 | } 29 | ma_device_info *playbackDeviceInfos; 30 | unsigned int playbackDeviceCount; 31 | if (ma_context_get_devices(&deviceContext, &playbackDeviceInfos, &playbackDeviceCount, NULL, NULL) != 0) { 32 | success = false; 33 | } 34 | for (uint32_t index = 0; index < playbackDeviceCount; index++) { 35 | AudioDevice* device = new AudioDevice( 36 | index, 37 | playbackDeviceInfos[index] 38 | ); 39 | audioDevices.push_back(device); 40 | } 41 | if (!success) { 42 | throw std::string("EXCEPTION: Audio devices could not be found."); 43 | } 44 | return audioDevices; 45 | } 46 | 47 | static AudioDevice* getDefault() { 48 | std::vector audioDevices = AudioDevices::getAll(); 49 | AudioDevice* defaultAudioDevice = audioDevices[0]; 50 | for (AudioDevice* audioDevice: audioDevices) { 51 | if (audioDevice->info.isDefault) { 52 | defaultAudioDevice = audioDevice; 53 | break; 54 | }; 55 | } 56 | return defaultAudioDevice; 57 | } 58 | 59 | static std::map getAllMap() { 60 | std::map devices; 61 | for (AudioDevice* device: AudioDevices::getAll()) { 62 | devices[std::to_string(device->id)] = device->info.name; 63 | } 64 | devices["default"] = AudioDevices::getDefault()->info.name; 65 | return devices; 66 | } 67 | }; 68 | 69 | 70 | enum PlaybackState { 71 | deviceFind, 72 | deviceInit, 73 | resourceManagerInit, 74 | dataSourceInit, 75 | deviceStart, 76 | }; 77 | -------------------------------------------------------------------------------- /windows/include/flutter_audio_desktop/flutter_types.hpp: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | #include 5 | #include 6 | #include 7 | #include 8 | 9 | 10 | class Method { 11 | public: 12 | const flutter::MethodCall* methodCall; 13 | std::string name; 14 | std::map arguments; 15 | std::unique_ptr> result; 16 | 17 | Method(const flutter::MethodCall* methodCall, std::unique_ptr> result) { 18 | this->methodCall = methodCall; 19 | this->name = std::string(this->methodCall->method_name()); 20 | this->arguments = std::get(*methodCall->arguments()); 21 | this->result = std::move(result); 22 | } 23 | 24 | template 25 | void returnValue(T value); 26 | 27 | template <> 28 | void returnValue(int value) { 29 | this->result->Success( 30 | flutter::EncodableValue(value) 31 | ); 32 | } 33 | 34 | template <> 35 | void returnValue(std::string value) { 36 | const char* resultCString = value.c_str(); 37 | this->result->Success( 38 | flutter::EncodableValue(resultCString) 39 | ); 40 | } 41 | 42 | template <> 43 | void returnValue>(std::map value) { 44 | auto map = flutter::EncodableMap(); 45 | for (const auto& pair : value) { 46 | map[flutter::EncodableValue(pair.first)] = flutter::EncodableValue(pair.second); 47 | } 48 | this->result->Success(map); 49 | } 50 | 51 | void returnNull() { 52 | this->result->Success( 53 | flutter::EncodableValue(nullptr) 54 | ); 55 | } 56 | 57 | void returnNotImplemented() { 58 | this->result->NotImplemented(); 59 | } 60 | 61 | template 62 | T getArgument(const char* argument); 63 | 64 | template <> 65 | int getArgument(const char* argument) { 66 | flutter::EncodableValue value = this->arguments[flutter::EncodableValue(argument)]; 67 | return std::get(value); 68 | } 69 | 70 | template <> 71 | std::string getArgument(const char* argument) { 72 | flutter::EncodableValue value = this->arguments[flutter::EncodableValue(argument)]; 73 | return std::get(value); 74 | } 75 | 76 | template <> 77 | float getArgument(const char* argument) { 78 | flutter::EncodableValue value = this->arguments[flutter::EncodableValue(argument)]; 79 | return static_cast(std::get(value)); 80 | } 81 | 82 | void returnResult() {} 83 | }; 84 | -------------------------------------------------------------------------------- /example/linux/flutter/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required(VERSION 3.10) 2 | 3 | set(EPHEMERAL_DIR "${CMAKE_CURRENT_SOURCE_DIR}/ephemeral") 4 | 5 | # Configuration provided via flutter tool. 6 | include(${EPHEMERAL_DIR}/generated_config.cmake) 7 | 8 | # TODO: Move the rest of this into files in ephemeral. See 9 | # https://github.com/flutter/flutter/issues/57146. 10 | 11 | # Serves the same purpose as list(TRANSFORM ... PREPEND ...), 12 | # which isn't available in 3.10. 13 | function(list_prepend LIST_NAME PREFIX) 14 | set(NEW_LIST "") 15 | foreach(element ${${LIST_NAME}}) 16 | list(APPEND NEW_LIST "${PREFIX}${element}") 17 | endforeach(element) 18 | set(${LIST_NAME} "${NEW_LIST}" PARENT_SCOPE) 19 | endfunction() 20 | 21 | # === Flutter Library === 22 | # System-level dependencies. 23 | find_package(PkgConfig REQUIRED) 24 | pkg_check_modules(GTK REQUIRED IMPORTED_TARGET gtk+-3.0) 25 | pkg_check_modules(GLIB REQUIRED IMPORTED_TARGET glib-2.0) 26 | pkg_check_modules(GIO REQUIRED IMPORTED_TARGET gio-2.0) 27 | pkg_check_modules(BLKID REQUIRED IMPORTED_TARGET blkid) 28 | 29 | set(FLUTTER_LIBRARY "${EPHEMERAL_DIR}/libflutter_linux_gtk.so") 30 | 31 | # Published to parent scope for install step. 32 | set(FLUTTER_LIBRARY ${FLUTTER_LIBRARY} PARENT_SCOPE) 33 | set(FLUTTER_ICU_DATA_FILE "${EPHEMERAL_DIR}/icudtl.dat" PARENT_SCOPE) 34 | set(PROJECT_BUILD_DIR "${PROJECT_DIR}/build/" PARENT_SCOPE) 35 | set(AOT_LIBRARY "${PROJECT_DIR}/build/lib/libapp.so" PARENT_SCOPE) 36 | 37 | list(APPEND FLUTTER_LIBRARY_HEADERS 38 | "fl_basic_message_channel.h" 39 | "fl_binary_codec.h" 40 | "fl_binary_messenger.h" 41 | "fl_dart_project.h" 42 | "fl_engine.h" 43 | "fl_json_message_codec.h" 44 | "fl_json_method_codec.h" 45 | "fl_message_codec.h" 46 | "fl_method_call.h" 47 | "fl_method_channel.h" 48 | "fl_method_codec.h" 49 | "fl_method_response.h" 50 | "fl_plugin_registrar.h" 51 | "fl_plugin_registry.h" 52 | "fl_standard_message_codec.h" 53 | "fl_standard_method_codec.h" 54 | "fl_string_codec.h" 55 | "fl_value.h" 56 | "fl_view.h" 57 | "flutter_linux.h" 58 | ) 59 | list_prepend(FLUTTER_LIBRARY_HEADERS "${EPHEMERAL_DIR}/flutter_linux/") 60 | add_library(flutter INTERFACE) 61 | target_include_directories(flutter INTERFACE 62 | "${EPHEMERAL_DIR}" 63 | ) 64 | target_link_libraries(flutter INTERFACE "${FLUTTER_LIBRARY}") 65 | target_link_libraries(flutter INTERFACE 66 | PkgConfig::GTK 67 | PkgConfig::GLIB 68 | PkgConfig::GIO 69 | PkgConfig::BLKID 70 | ) 71 | add_dependencies(flutter flutter_assemble) 72 | 73 | # === Flutter tool backend === 74 | # _phony_ is a non-existent file to force this command to run every time, 75 | # since currently there's no way to get a full input/output list from the 76 | # flutter tool. 77 | add_custom_command( 78 | OUTPUT ${FLUTTER_LIBRARY} ${FLUTTER_LIBRARY_HEADERS} 79 | ${CMAKE_CURRENT_BINARY_DIR}/_phony_ 80 | COMMAND ${CMAKE_COMMAND} -E env 81 | ${FLUTTER_TOOL_ENVIRONMENT} 82 | "${FLUTTER_ROOT}/packages/flutter_tools/bin/tool_backend.sh" 83 | linux-x64 ${CMAKE_BUILD_TYPE} 84 | ) 85 | add_custom_target(flutter_assemble DEPENDS 86 | "${FLUTTER_LIBRARY}" 87 | ${FLUTTER_LIBRARY_HEADERS} 88 | ) 89 | -------------------------------------------------------------------------------- /lib/source/core/events.dart: -------------------------------------------------------------------------------- 1 | import 'dart:io'; 2 | 3 | import 'package:flutter_audio_desktop/source/core/channel.dart'; 4 | import 'package:flutter_audio_desktop/source/types/audio.dart'; 5 | 6 | class AudioPlayerInternal { 7 | /// Unique ID of the audio player instance. 8 | int id; 9 | 10 | /// Device ID of the device ,to which the audio player is playing. 11 | String deviceId; 12 | 13 | /// Broadcast stream to listen to playback events e.g. completion, loading, play/pause etc. 14 | Stream