ionorg / ion-sdk-flutter

ion flutter sdk
MIT License
116 stars 74 forks source link

Example app crashes when captureFrame is invoked #2

Open UMFsimke opened 4 years ago

UMFsimke commented 4 years ago

Your environment.

What did you do?

Due to our project requirements, we need to have an ability for a user to take a photo during video calls and send that image to the other participants. In order to do something like that we explored multiple approaches and the only viable approach would be to use captureFrame(path) method that Flutter WebRTC provides on local video MediaStreamTrack. The main reason for such a decision is that Ion SDK "locks" the camera even when you disabled it, and you can't open a second session for that camera until local video stream is connected. It would be very bad UX that user just disappears when he wants to take the photo and that is why we chose to utilize captureFrame(path) method since it exists.

In order to do something like this we simply changed in your example project in pubspec.yaml we added a dependency:

path_provider:

and in the meeting_page.dart:

//Switch local camera
  _switchCamera() async {
    if (_localVideo != null && _localVideo.stream.getVideoTracks().length > 0) {
      //_localVideo.stream.getVideoTracks()[0].switchCamera();
      final storagePath = await getTemporaryDirectory();
      final filePath = storagePath.path + '/test.jpg';
      _localVideo.stream.getVideoTracks()[0].captureFrame(filePath);
    } else {
      _showSnackBar(":::Unable to switch the camera:::");
    }
  }

In ios/Runner/Info.plist we added:

<key>NSPhotoLibraryAddUsageDescription</key>
<string>write</string>
<key>NSPhotoLibraryUsageDescription</key>
<string>write</string>

What did you expect?

Application should capture a frame and save it in the JPG file.

What happened?

The application crashed without any stacktrace when run on iOS 13.2.

We also tested the official Web RTC sample which supports captureFrame and it worked as expected without any crash.

UMFsimke commented 4 years ago

any update on this issue?