-
Notifications
You must be signed in to change notification settings - Fork 157
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: Visualizer for web. * wip. * done. * update. * dart run import_sorter:main --no-comments. * dart format. * export Visualizer and add VisualizerOptions. * support barCount configuration. * Fixed bug for visualizer restart, removed setting enableVisualizer from RoomOptions. * update. * cleanup. * rename. * fix. * fix. * fix.
- Loading branch information
1 parent
a503e95
commit 6365ec6
Showing
23 changed files
with
472 additions
and
116 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import 'package:livekit_client/src/support/disposable.dart'; | ||
import '../events.dart' show AudioVisualizerEvent; | ||
import '../managers/event.dart' show EventsEmittable; | ||
import 'local/local.dart' show AudioTrack; | ||
|
||
import 'audio_visualizer_native.dart' | ||
if (dart.library.js_interop) 'audio_visualizer_web.dart'; | ||
|
||
class AudioVisualizerOptions { | ||
final bool centeredBands; | ||
final int barCount; | ||
const AudioVisualizerOptions({ | ||
this.centeredBands = true, | ||
this.barCount = 7, | ||
}); | ||
} | ||
|
||
abstract class AudioVisualizer extends DisposableChangeNotifier | ||
with EventsEmittable<AudioVisualizerEvent> { | ||
Future<void> start(); | ||
Future<void> stop(); | ||
} | ||
|
||
AudioVisualizer createVisualizer(AudioTrack track, | ||
{AudioVisualizerOptions? options}) => | ||
createVisualizerImpl(track, options: options); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
import 'dart:async'; | ||
|
||
import 'package:flutter/services.dart'; | ||
|
||
import 'package:flutter_webrtc/flutter_webrtc.dart'; | ||
|
||
import 'package:livekit_client/src/events.dart' show AudioVisualizerEvent; | ||
import 'package:livekit_client/src/track/local/local.dart'; | ||
import '../support/native.dart' show Native; | ||
import 'audio_visualizer.dart'; | ||
|
||
class AudioVisualizerNative extends AudioVisualizer { | ||
final String visualizerId = '${DateTime.now().millisecondsSinceEpoch}'; | ||
EventChannel? _eventChannel; | ||
StreamSubscription? _streamSubscription; | ||
final AudioTrack? _audioTrack; | ||
MediaStreamTrack get mediaStreamTrack => _audioTrack!.mediaStreamTrack; | ||
final AudioVisualizerOptions visualizerOptions; | ||
AudioVisualizerNative(this._audioTrack, {required this.visualizerOptions}) { | ||
onDispose(() async { | ||
await events.dispose(); | ||
}); | ||
} | ||
|
||
@override | ||
Future<void> start() async { | ||
if (_eventChannel != null) { | ||
return; | ||
} | ||
|
||
await Native.startVisualizer( | ||
mediaStreamTrack.id!, | ||
isCentered: visualizerOptions.centeredBands, | ||
barCount: visualizerOptions.barCount, | ||
visualizerId: visualizerId, | ||
); | ||
|
||
_eventChannel = EventChannel( | ||
'io.livekit.audio.visualizer/eventChannel-${mediaStreamTrack.id}-$visualizerId'); | ||
_streamSubscription = | ||
_eventChannel?.receiveBroadcastStream().listen((event) { | ||
events.emit(AudioVisualizerEvent( | ||
track: _audioTrack!, | ||
event: event, | ||
)); | ||
}); | ||
} | ||
|
||
@override | ||
Future<void> stop() async { | ||
if (_eventChannel == null) { | ||
return; | ||
} | ||
|
||
await Native.stopVisualizer(mediaStreamTrack.id!, | ||
visualizerId: visualizerId); | ||
|
||
events.emit(AudioVisualizerEvent( | ||
track: _audioTrack!, | ||
event: [], | ||
)); | ||
|
||
await _streamSubscription?.cancel(); | ||
_streamSubscription = null; | ||
_eventChannel = null; | ||
} | ||
} | ||
|
||
AudioVisualizer createVisualizerImpl(AudioTrack track, | ||
{AudioVisualizerOptions? options}) => | ||
AudioVisualizerNative(track, | ||
visualizerOptions: options ?? AudioVisualizerOptions()); |
Oops, something went wrong.