Blancduman / mediasoup-client-flutter

Flutter version of the mediasoup-client library.
MIT License
106 stars 56 forks source link

Switch Cam #29

Closed salahkamal closed 3 years ago

salahkamal commented 3 years ago

Hello again, I need to switch cam i use replaceTrack() but it doesn’t work. Any ideas please?

cycleTrack() async {
    final List<MediaDeviceInfo> devices =
        await navigator.mediaDevices.enumerateDevices();
    devices.forEach((element) {
      log('------------\n${element.kind} | ${element.deviceId} | ${element.label}');
    });
    log('------------\n${devices[1].kind} | ${devices[1].deviceId} | ${devices[1].label}');
    Map<String, dynamic> mediaConstraints = {
      'audio': false,
      'video': {
        'mandatory': {
          'minWidth':
              '720', // Provide your own width, height and frame rate here
          'minHeight': '1280',
          'minFrameRate': '30',
        },
        'sourceId': devices[0].deviceId,
      }
    };
    stream = await navigator.mediaDevices.getUserMedia(mediaConstraints);
    // var backVideoTrack = stream.getVideoTracks()[0];
    videoProducer.replaceTrack(stream.getVideoTracks()[0]);
    videoProducer.resume();

    notifyListeners();
  }
Blancduman commented 3 years ago

Close the video producer and create a new one

вт, 14 сент. 2021 г., 00:13 salahkamal @.***>:

Hello again, I need to switch cam i use replaceTrack() but it doesn’t work. Any ideas please?

`cycleTrack() async { final List devices = await navigator.mediaDevices.enumerateDevices(); devices.forEach((element) { log('------------\n${element.kind} | ${element.deviceId} | ${element.label}'); }); log('------------\n${devices[1].kind} | ${devices[1].deviceId} | ${devices[1].label}'); Map<String, dynamic> mediaConstraints = { 'audio': false, 'video': { 'mandatory': { 'minWidth': '720', // Provide your own width, height and frame rate here 'minHeight': '1280', 'minFrameRate': '30', }, 'sourceId': devices[0].deviceId, } }; stream = await navigator.mediaDevices.getUserMedia(mediaConstraints); // var backVideoTrack = stream.getVideoTracks()[0]; videoProducer.replaceTrack(stream.getVideoTracks()[0]); videoProducer.resume();

notifyListeners();

}`

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/Blancduman/mediasoup-client-flutter/issues/29, or unsubscribe https://github.com/notifications/unsubscribe-auth/AIVXEO2EBVWW3S55JEDCIN3UBZSPBANCNFSM5D6WOZVA .