How to pause and mute the video in Flutter Webrtc

125 views Asked by At

I was working on flutter webrtc to implement a streaming from a camera using the package https://pub.dev/packages/flutter_kinesis_video_webrtc. In the Mobile UI side we have an option for pausing and to mute the video. How can we achieve this using this package?

Actually the package uses https://pub.dev/packages/flutter_webrtc for implementing webrtc.

1

There are 1 answers

0
superwch1 On

You can toggle the video and audio track by setting their states. Assume you have a MediaStream? localStream that is used for capturing the media via the device camera.

bool EnableVideo = true;
bool EnableAudio = true;

Future<void> ToggleVideoTrack() async {
    EnableVideo = !EnableVideo;
    for(var track in LocalStream!.getVideoTracks()) {
        track.enabled = EnableVideo;
    }
}

Future<void> ToggleAudioTrack() async {
    EnableAudio = !EnableAudio;
    for(var track in LocalStream!.getAudioTracks()) {
        track.enabled = EnableAudio;
    }
}