Skip to content

Commit

Permalink
update.
Browse files Browse the repository at this point in the history
  • Loading branch information
cloudwebrtc committed Nov 28, 2024
1 parent 47b67fb commit 5ddda8c
Showing 1 changed file with 1 addition and 103 deletions.
104 changes: 1 addition & 103 deletions example/lib/widgets/participant.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:livekit_example/theme.dart';
import 'no_video.dart';
import 'participant_info.dart';
import 'participant_stats.dart';
import 'sound_waveform.dart';

abstract class ParticipantWidget extends StatefulWidget {
// Convenience method to return relevant widget for participant
Expand Down Expand Up @@ -372,106 +373,3 @@ class RemoteTrackQualityMenuWidget extends StatelessWidget {
);
}

class SoundWaveformWidget extends StatefulWidget {
final int count;
final double width;
final double minHeight;
final double maxHeight;
final int durationInMilliseconds;
const SoundWaveformWidget({
super.key,
this.participant,
this.count = 7,
this.width = 5,
this.minHeight = 8,
this.maxHeight = 100,
this.durationInMilliseconds = 500,
});
final Participant? participant;
@override
State<SoundWaveformWidget> createState() => _SoundWaveformWidgetState();
}

class _SoundWaveformWidgetState extends State<SoundWaveformWidget>
with TickerProviderStateMixin {
late AnimationController controller;
List<double> samples = [0,0,0,0,0,0,0];
EventsListener<TrackEvent>? _listener;

_onParticipantChanged() {
for( var track in widget.participant?.audioTrackPublications ?? []) {
if (track.track != null) {
_setUpListener(track.track as AudioTrack);
}
}
}

void _setUpListener(AudioTrack track) {
_listener?.dispose();
_listener = track.createListener();
_listener?.on<AudioVisualizerEvent>((e) {
setState(() {
samples = e.event.map((e) => ((e as num) * 100).toDouble()).toList();
});
});
}
@override
void initState() {
super.initState();

widget.participant?.addListener(_onParticipantChanged);


controller = AnimationController(
vsync: this,
duration: Duration(
milliseconds: widget.durationInMilliseconds,
))
..repeat();
}

@override
void dispose() {
controller.dispose();
widget.participant?.removeListener(_onParticipantChanged);
_listener?.dispose();
super.dispose();
}

@override
Widget build(BuildContext context) {
final count = widget.count;
final minHeight = widget.minHeight;
final maxHeight = widget.maxHeight;
return AnimatedBuilder(
animation: controller,
builder: (c, child) {
//double t = controller.value;
//int current = (samples.length * t).floor();
return Row(
mainAxisSize: MainAxisSize.min,
children: List.generate(
count,
(i) => AnimatedContainer(
duration: Duration(
milliseconds: widget.durationInMilliseconds ~/ count),
margin: i == (samples.length - 1)
? EdgeInsets.zero
: const EdgeInsets.only(right: 5),
height: samples[i] < minHeight
? minHeight
: samples[i] > maxHeight
? maxHeight
: samples[i],
width: widget.width,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(9999),
),
),
),
);
},
);
}
}

0 comments on commit 5ddda8c

Please sign in to comment.