2

I'm trying to record a video stream in Flutter Android platform but getting the error that "It's for Flutter Web only". Does it support recording video streaming in mobile platform? How can I record the video streaming in the mobile platform?

Future<bool> _checkPermissions() async {
  final status = await Permission.storage.request();
  return status.isGranted;
}


Future<String> _getRecordingPath() async {
  final directory = await getApplicationDocumentsDirectory();
  final timestamp = DateTime.now().millisecondsSinceEpoch;
  return '${directory.path}/webrtc_recording_$timestamp.mp4';
}


Future<void> _startRecording() async {
  if (!await _checkPermissions()) {
    ScaffoldMessenger.of(context).showSnackBar(
      SnackBar(content: Text('Storage permission required')),
    );
    return;
  }

  try {
    final path = await _getRecordingPath();
    await _mediaRecorder.start(path,videoTrack: 
    signaling!.localStream!.getVideoTracks().first,audioChannel: 
    RecorderAudioChannel.INPUT,);
    
    // Add the stream to the recorder
    _mediaRecorder.startWeb(signaling!.localStream!,onDataChunk: (value, islast){
      print('onDataChunk: $value');
    },mimeType: "video");
    // await _mediaRecorder.addStream(_localRenderer);
    
    setState(() {
      _isRecording = true;
      _recordingPath = path;
    });
    
    ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(content: Text('Recording started: $path')), );
    
  } catch (e) {
    print('Failed to start recording: $e');
    ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(content: Text('Failed to start recording: $e')),);
  }
}
5
  • 3
    which package are you using?
    – Munsif Ali
    Commented Apr 14 at 11:03
  • Try to look at your imports, probably there is some there using a web package. Commented Apr 14 at 12:05
  • I'm using the "flutter_webrtc" @MunsifAli Commented Apr 14 at 18:02
  • You're using _mediaRecorder.startWeb, which implies that it's a web-only method.
    – Abion47
    Commented Apr 14 at 19:00
  • Check the documentation it is given that MediaRecorder is supported on web currently.
    – Munsif Ali
    Commented Apr 15 at 4:05

1 Answer 1

1

if you go the documentation of flutter_webrtc on pub.dev. Under Functionality section it is given that the MediaRecorder is currently available on web only.

Functionality Image from the documentation of flutter_webrtc

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.