From 87d535494379f92ba0ccb5479f87fa6b890513ed Mon Sep 17 00:00:00 2001 From: Daniel Ponte Date: Wed, 14 Aug 2024 14:36:58 -0400 Subject: [PATCH] Multiple audio drivers --- lib/controller/play.dart | 53 +++++++-- macos/Flutter/GeneratedPluginRegistrant.swift | 4 + macos/Podfile.lock | 12 ++ pubspec.lock | 108 +++++++++++++++--- pubspec.yaml | 9 +- .../flutter/generated_plugin_registrant.cc | 3 + windows/flutter/generated_plugins.cmake | 1 + 7 files changed, 157 insertions(+), 33 deletions(-) diff --git a/lib/controller/play.dart b/lib/controller/play.dart index 1a030bf..7657c42 100644 --- a/lib/controller/play.dart +++ b/lib/controller/play.dart @@ -1,20 +1,50 @@ import 'dart:typed_data'; -import 'package:audioplayers/audioplayers.dart'; +import 'package:just_audio/just_audio.dart' as justaudio; +import 'package:audioplayers/audioplayers.dart' as auplay; +import 'dart:io' show Platform; + import '../pb/stillbox.pb.dart'; +abstract class AudioDriver { + Future play(Call call); +} + class Player { - final player = AudioPlayer(); - Player(); + late AudioDriver driver; + Player() { + if (Platform.isMacOS || Platform.isIOS) { + driver = JustAudioDriver(); + } else { + driver = AudioPlayersDriver(); + } + } Future play(Call call) { - // TODO make a queue - return player.play(BytesSource(Uint8List.fromList(call.audio))); + return driver.play(call); + } + // TODO make a queue +} + +class JustAudioDriver implements AudioDriver { + final player = justaudio.AudioPlayer(); + + @override + Future play(Call call) { + player.setAudioSource(CallBytesSource(call)); + return player.play(); } } -/* -for just_audio (add just_audio and just_audio_linux) -class CallBytesSource extends StreamAudioSource { +class AudioPlayersDriver implements AudioDriver { + final player = auplay.AudioPlayer(); + + @override + Future play(Call call) { + return player.play(auplay.BytesSource(Uint8List.fromList(call.audio))); + } +} + +class CallBytesSource extends justaudio.StreamAudioSource { late Uint8List _buffer; final Call _call; @@ -25,9 +55,9 @@ class CallBytesSource extends StreamAudioSource { CallBytesSource._(this._call, this._buffer) : super(tag: 'CallBytesSource'); @override - Future request([int? start, int? end]) async { + Future request([int? start, int? end]) async { // Returning the stream audio response with the parameters - return StreamAudioResponse( + return justaudio.StreamAudioResponse( sourceLength: _buffer.length, contentLength: (end ?? _buffer.length) - (start ?? 0), offset: start ?? 0, @@ -35,5 +65,4 @@ class CallBytesSource extends StreamAudioSource { contentType: _call.audioType, ); } -} -*/ \ No newline at end of file +} \ No newline at end of file diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index ae73647..b3ee37e 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -5,12 +5,16 @@ import FlutterMacOS import Foundation +import audio_session import audioplayers_darwin import flutter_secure_storage_macos +import just_audio import path_provider_foundation func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { + AudioSessionPlugin.register(with: registry.registrar(forPlugin: "AudioSessionPlugin")) AudioplayersDarwinPlugin.register(with: registry.registrar(forPlugin: "AudioplayersDarwinPlugin")) FlutterSecureStoragePlugin.register(with: registry.registrar(forPlugin: "FlutterSecureStoragePlugin")) + JustAudioPlugin.register(with: registry.registrar(forPlugin: "JustAudioPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) } diff --git a/macos/Podfile.lock b/macos/Podfile.lock index 085d79b..858f234 100644 --- a/macos/Podfile.lock +++ b/macos/Podfile.lock @@ -1,33 +1,45 @@ PODS: + - audio_session (0.0.1): + - FlutterMacOS - audioplayers_darwin (0.0.1): - FlutterMacOS - flutter_secure_storage_macos (6.1.1): - FlutterMacOS - FlutterMacOS (1.0.0) + - just_audio (0.0.1): + - FlutterMacOS - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS DEPENDENCIES: + - audio_session (from `Flutter/ephemeral/.symlinks/plugins/audio_session/macos`) - audioplayers_darwin (from `Flutter/ephemeral/.symlinks/plugins/audioplayers_darwin/macos`) - flutter_secure_storage_macos (from `Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos`) - FlutterMacOS (from `Flutter/ephemeral`) + - just_audio (from `Flutter/ephemeral/.symlinks/plugins/just_audio/macos`) - path_provider_foundation (from `Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin`) EXTERNAL SOURCES: + audio_session: + :path: Flutter/ephemeral/.symlinks/plugins/audio_session/macos audioplayers_darwin: :path: Flutter/ephemeral/.symlinks/plugins/audioplayers_darwin/macos flutter_secure_storage_macos: :path: Flutter/ephemeral/.symlinks/plugins/flutter_secure_storage_macos/macos FlutterMacOS: :path: Flutter/ephemeral + just_audio: + :path: Flutter/ephemeral/.symlinks/plugins/just_audio/macos path_provider_foundation: :path: Flutter/ephemeral/.symlinks/plugins/path_provider_foundation/darwin SPEC CHECKSUMS: + audio_session: dea1f41890dbf1718f04a56f1d6150fd50039b72 audioplayers_darwin: dcad41de4fbd0099cb3749f7ab3b0cb8f70b810c flutter_secure_storage_macos: 59459653abe1adb92abbc8ea747d79f8d19866c9 FlutterMacOS: 8f6f14fa908a6fb3fba0cd85dbd81ec4b251fb24 + just_audio: 9b67ca7b97c61cfc9784ea23cd8cc55eb226d489 path_provider_foundation: 2b6b4c569c0fb62ec74538f866245ac84301af46 PODFILE CHECKSUM: 236401fc2c932af29a9fcf0e97baeeb2d750d367 diff --git a/pubspec.lock b/pubspec.lock index ae068fa..bd7faa9 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -9,62 +9,70 @@ packages: url: "https://pub.dev" source: hosted version: "2.11.0" + audio_session: + dependency: transitive + description: + name: audio_session + sha256: "343e83bc7809fbda2591a49e525d6b63213ade10c76f15813be9aed6657b3261" + url: "https://pub.dev" + source: hosted + version: "0.1.21" audioplayers: dependency: "direct main" description: name: audioplayers - sha256: c05c6147124cd63e725e861335a8b4d57300b80e6e92cea7c145c739223bbaef + sha256: "752039d6aa752597c98ec212e9759519061759e402e7da59a511f39d43aa07d2" url: "https://pub.dev" source: hosted - version: "5.2.1" + version: "6.0.0" audioplayers_android: dependency: transitive description: name: audioplayers_android - sha256: b00e1a0e11365d88576320ec2d8c192bc21f1afb6c0e5995d1c57ae63156acb5 + sha256: de576b890befe27175c2f511ba8b742bec83765fa97c3ce4282bba46212f58e4 url: "https://pub.dev" source: hosted - version: "4.0.3" + version: "5.0.0" audioplayers_darwin: dependency: "direct main" description: name: audioplayers_darwin - sha256: "3034e99a6df8d101da0f5082dcca0a2a99db62ab1d4ddb3277bed3f6f81afe08" + sha256: e507887f3ff18d8e5a10a668d7bedc28206b12e10b98347797257c6ae1019c3b url: "https://pub.dev" source: hosted - version: "5.0.2" + version: "6.0.0" audioplayers_linux: dependency: "direct main" description: name: audioplayers_linux - sha256: "60787e73fefc4d2e0b9c02c69885402177e818e4e27ef087074cf27c02246c9e" + sha256: "3d3d244c90436115417f170426ce768856d8fe4dfc5ed66a049d2890acfa82f9" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "4.0.0" audioplayers_platform_interface: dependency: transitive description: name: audioplayers_platform_interface - sha256: "365c547f1bb9e77d94dd1687903a668d8f7ac3409e48e6e6a3668a1ac2982adb" + sha256: "6834dd48dfb7bc6c2404998ebdd161f79cd3774a7e6779e1348d54a3bfdcfaa5" url: "https://pub.dev" source: hosted - version: "6.1.0" + version: "7.0.0" audioplayers_web: dependency: transitive description: name: audioplayers_web - sha256: "22cd0173e54d92bd9b2c80b1204eb1eb159ece87475ab58c9788a70ec43c2a62" + sha256: db8fc420dadf80da18e2286c18e746fb4c3b2c5adbf0c963299dde046828886d url: "https://pub.dev" source: hosted - version: "4.1.0" + version: "5.0.0" audioplayers_windows: dependency: transitive description: name: audioplayers_windows - sha256: "9536812c9103563644ada2ef45ae523806b0745f7a78e89d1b5fb1951de90e1a" + sha256: "8605762dddba992138d476f6a0c3afd9df30ac5b96039929063eceed416795c2" url: "https://pub.dev" source: hosted - version: "3.1.0" + version: "4.0.0" boolean_selector: dependency: transitive description: @@ -113,6 +121,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" + eventify: + dependency: transitive + description: + name: eventify + sha256: b829429f08586cc2001c628e7499e3e3c2493a1d895fd73b00ecb23351aa5a66 + url: "https://pub.dev" + source: hosted + version: "1.0.1" fake_async: dependency: transitive description: @@ -248,6 +264,46 @@ packages: url: "https://pub.dev" source: hosted version: "0.6.7" + just_audio: + dependency: "direct main" + description: + name: just_audio + sha256: b7cb6bbf3750caa924d03f432ba401ec300fd90936b3f73a9b33d58b1e96286b + url: "https://pub.dev" + source: hosted + version: "0.9.37" + just_audio_mpv: + dependency: "direct main" + description: + name: just_audio_mpv + sha256: d6e4e9fd20bfb9d2fd5e3dcd7906c90ed07f83d1d2f44f31204160821ab62fed + url: "https://pub.dev" + source: hosted + version: "0.1.7" + just_audio_platform_interface: + dependency: transitive + description: + name: just_audio_platform_interface + sha256: "0243828cce503c8366cc2090cefb2b3c871aa8ed2f520670d76fd47aa1ab2790" + url: "https://pub.dev" + source: hosted + version: "4.3.0" + just_audio_web: + dependency: transitive + description: + name: just_audio_web + sha256: "134356b0fe3d898293102b33b5fd618831ffdc72bb7a1b726140abdf22772b70" + url: "https://pub.dev" + source: hosted + version: "0.4.9" + just_audio_windows: + dependency: "direct main" + description: + name: just_audio_windows + sha256: "48ab2dec79cf6097550602fe07b1a644f341450e138dc8fdc23e42ce0ed2d928" + url: "https://pub.dev" + source: hosted + version: "0.2.1" leak_tracker: dependency: transitive description: @@ -304,6 +360,14 @@ packages: url: "https://pub.dev" source: hosted version: "1.15.0" + mpv_dart: + dependency: transitive + description: + name: mpv_dart + sha256: a33bd9a68439b496b7a5f36fecd3aa3cf6cbf0176ae15b9b60b12ae96e58f5a4 + url: "https://pub.dev" + source: hosted + version: "0.0.1" nested: dependency: transitive description: @@ -400,6 +464,14 @@ packages: url: "https://pub.dev" source: hosted version: "6.1.2" + rxdart: + dependency: transitive + description: + name: rxdart + sha256: "0c7c0cedd93788d996e33041ffecda924cc54389199cde4e6a34b440f50044cb" + url: "https://pub.dev" + source: hosted + version: "0.27.7" sky_engine: dependency: transitive description: flutter @@ -449,10 +521,10 @@ packages: dependency: transitive description: name: synchronized - sha256: "539ef412b170d65ecdafd780f924e5be3f60032a1128df156adad6c5b373d558" + sha256: a824e842b8a054f91a728b783c177c1e4731f6b124f9192468457a8913371255 url: "https://pub.dev" source: hosted - version: "3.1.0+1" + version: "3.2.0" term_glyph: dependency: transitive description: @@ -505,10 +577,10 @@ packages: dependency: transitive description: name: web - sha256: d43c1d6b787bf0afad444700ae7f4db8827f701bc61c255ac8d328c6f4d52062 + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" url: "https://pub.dev" source: hosted - version: "1.0.0" + version: "0.5.1" web_socket: dependency: transitive description: diff --git a/pubspec.yaml b/pubspec.yaml index 6836261..0c92c18 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -40,11 +40,14 @@ dependencies: protobuf: ^3.1.0 web_socket_channel: ^3.0.1 provider: ^6.1.2 - audioplayers: ^5.2.1 flutter_secure_storage: ^9.2.2 http: ^1.2.2 - audioplayers_linux: ^3.1.0 - audioplayers_darwin: ^5.0.2 + just_audio: ^0.9.37 + just_audio_mpv: ^0.1.7 + just_audio_windows: ^0.2.1 + audioplayers: ^6.0.0 + audioplayers_linux: ^4.0.0 + audioplayers_darwin: ^6.0.0 dev_dependencies: flutter_test: diff --git a/windows/flutter/generated_plugin_registrant.cc b/windows/flutter/generated_plugin_registrant.cc index 5f23188..13dfd95 100644 --- a/windows/flutter/generated_plugin_registrant.cc +++ b/windows/flutter/generated_plugin_registrant.cc @@ -8,10 +8,13 @@ #include #include +#include void RegisterPlugins(flutter::PluginRegistry* registry) { AudioplayersWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("AudioplayersWindowsPlugin")); FlutterSecureStorageWindowsPluginRegisterWithRegistrar( registry->GetRegistrarForPlugin("FlutterSecureStorageWindowsPlugin")); + JustAudioWindowsPluginRegisterWithRegistrar( + registry->GetRegistrarForPlugin("JustAudioWindowsPlugin")); } diff --git a/windows/flutter/generated_plugins.cmake b/windows/flutter/generated_plugins.cmake index 1164d9f..4ef3fab 100644 --- a/windows/flutter/generated_plugins.cmake +++ b/windows/flutter/generated_plugins.cmake @@ -5,6 +5,7 @@ list(APPEND FLUTTER_PLUGIN_LIST audioplayers_windows flutter_secure_storage_windows + just_audio_windows ) list(APPEND FLUTTER_FFI_PLUGIN_LIST