diff --git a/lib/src/context/media_device_context.dart b/lib/src/context/media_device_context.dart index c54b381..0bb4806 100644 --- a/lib/src/context/media_device_context.dart +++ b/lib/src/context/media_device_context.dart @@ -96,7 +96,6 @@ class MediaDeviceContext extends ChangeNotifier { AudioCaptureOptions( deviceId: selectedAudioInputDeviceId, ), - _roomCtx.enableAudioVisulizer, ); } selectedAudioInputDeviceId = device.deviceId; @@ -138,7 +137,6 @@ class MediaDeviceContext extends ChangeNotifier { AudioCaptureOptions( deviceId: selectedAudioInputDeviceId, ), - _roomCtx.enableAudioVisulizer, ); } notifyListeners(); @@ -286,13 +284,10 @@ class MediaDeviceContext extends ChangeNotifier { bool? get isSpeakerOn => Hardware.instance.speakerOn; - void setSpeakerphoneOn(bool speakerOn) async { - if (lkPlatformIs(PlatformType.iOS)) { - if (!speakerOn && Hardware.instance.preferSpeakerOutput) { - await Hardware.instance.setPreferSpeakerOutput(false); - } - } - await Hardware.instance.setSpeakerphoneOn(speakerOn); + void setSpeakerphoneOn(bool speakerOn, + {bool forceSpeakerOutput = false}) async { + await Hardware.instance + .setSpeakerphoneOn(speakerOn, forceSpeakerOutput: forceSpeakerOutput); notifyListeners(); } diff --git a/lib/src/ui/widgets/track/audio_visualizer_widget.dart b/lib/src/ui/widgets/track/audio_visualizer_widget.dart index de03835..2e61f00 100644 --- a/lib/src/ui/widgets/track/audio_visualizer_widget.dart +++ b/lib/src/ui/widgets/track/audio_visualizer_widget.dart @@ -7,8 +7,9 @@ import '../../../context/track_reference_context.dart'; import '../theme.dart'; import 'no_track_widget.dart'; -class AudioVisualizerOptions { - final int count; +class AudioVisualizerWidgetOptions { + final int barCount; + final bool centeredBands; final double width; final double minHeight; final double maxHeight; @@ -18,8 +19,9 @@ class AudioVisualizerOptions { final double cornerRadius; final double barMinOpacity; - const AudioVisualizerOptions({ - this.count = 7, + const AudioVisualizerWidgetOptions({ + this.barCount = 7, + this.centeredBands = true, this.width = 12, this.minHeight = 12, this.maxHeight = 100, @@ -32,11 +34,11 @@ class AudioVisualizerOptions { } class AudioVisualizerWidget extends StatelessWidget { - final AudioVisualizerOptions options; + final AudioVisualizerWidgetOptions options; const AudioVisualizerWidget({ Key? key, - this.options = const AudioVisualizerOptions(), + this.options = const AudioVisualizerWidgetOptions(), }) : super(key: key); @override @@ -71,13 +73,13 @@ class AudioVisualizerWidget extends StatelessWidget { } class SoundWaveformWidget extends StatefulWidget { - final AudioVisualizerOptions options; + final AudioVisualizerWidgetOptions options; final AudioTrack? audioTrack; const SoundWaveformWidget({ super.key, this.audioTrack, - this.options = const AudioVisualizerOptions(), + this.options = const AudioVisualizerWidgetOptions(), }); @override @@ -88,10 +90,19 @@ class _SoundWaveformWidgetState extends State with TickerProviderStateMixin { late AnimationController controller; List samples = [0, 0, 0, 0, 0, 0, 0]; - EventsListener? _listener; + AudioVisualizer? _visualizer; + EventsListener? _listener; void _startVisualizer(AudioTrack? track) async { - _listener = track?.createListener(); + if (track == null) { + return; + } + samples = List.filled(widget.options.barCount, 0); + _visualizer ??= createVisualizer(track, + options: AudioVisualizerOptions( + barCount: widget.options.barCount, + centeredBands: widget.options.centeredBands)); + _listener ??= _visualizer?.createListener(); _listener?.on((e) { if (mounted) { setState(() { @@ -99,10 +110,16 @@ class _SoundWaveformWidgetState extends State }); } }); + + await _visualizer!.start(); } void _stopVisualizer() async { + await _visualizer?.stop(); + await _visualizer?.dispose(); + _visualizer = null; await _listener?.dispose(); + _listener = null; } @override @@ -128,7 +145,7 @@ class _SoundWaveformWidgetState extends State @override Widget build(BuildContext context) { - final count = widget.options.count; + final count = widget.options.barCount; final minHeight = widget.options.minHeight; final maxHeight = widget.options.maxHeight; return AnimatedBuilder( diff --git a/pubspec.yaml b/pubspec.yaml index 9cfb58d..299a62a 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -12,11 +12,11 @@ dependencies: flutter: sdk: flutter flutter_background: ^1.3.0+1 - flutter_webrtc: ^0.12.8 + flutter_webrtc: ^0.12.12+hotfix.1 google_fonts: ^6.2.1 http: ^1.2.2 intl: ^0.19.0 - livekit_client: ^2.3.6 + livekit_client: ^2.4.1 provider: ^6.1.2 responsive_builder: ^0.7.1 @@ -26,47 +26,45 @@ dev_dependencies: flutter_lints: ^4.0.0 import_sorter: ^4.6.0 - topics: - webrtc - ai - livestream - conference - agent - # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec # The following section is specific to Flutter packages. # flutter: - # To add assets to your package, add an assets section, like this: - # assets: - # - images/a_dot_burr.jpeg - # - images/a_dot_ham.jpeg - # - # For details regarding assets in packages, see - # https://flutter.dev/to/asset-from-package - # - # An image asset can refer to one or more resolution-specific "variants", see - # https://flutter.dev/to/resolution-aware-images +# To add assets to your package, add an assets section, like this: +# assets: +# - images/a_dot_burr.jpeg +# - images/a_dot_ham.jpeg +# +# For details regarding assets in packages, see +# https://flutter.dev/to/asset-from-package +# +# An image asset can refer to one or more resolution-specific "variants", see +# https://flutter.dev/to/resolution-aware-images - # To add custom fonts to your package, add a fonts section here, - # in this "flutter" section. Each entry in this list should have a - # "family" key with the font family name, and a "fonts" key with a - # list giving the asset and other descriptors for the font. For - # example: - # fonts: - # - family: Schyler - # fonts: - # - asset: fonts/Schyler-Regular.ttf - # - asset: fonts/Schyler-Italic.ttf - # style: italic - # - family: Trajan Pro - # fonts: - # - asset: fonts/TrajanPro.ttf - # - asset: fonts/TrajanPro_Bold.ttf - # weight: 700 - # - # For details regarding fonts in packages, see - # https://flutter.dev/to/font-from-package +# To add custom fonts to your package, add a fonts section here, +# in this "flutter" section. Each entry in this list should have a +# "family" key with the font family name, and a "fonts" key with a +# list giving the asset and other descriptors for the font. For +# example: +# fonts: +# - family: Schyler +# fonts: +# - asset: fonts/Schyler-Regular.ttf +# - asset: fonts/Schyler-Italic.ttf +# style: italic +# - family: Trajan Pro +# fonts: +# - asset: fonts/TrajanPro.ttf +# - asset: fonts/TrajanPro_Bold.ttf +# weight: 700 +# +# For details regarding fonts in packages, see +# https://flutter.dev/to/font-from-package