@@ -47,7 +47,7 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
47
47
"audio" : false ,
48
48
"video" : {
49
49
"mandatory" : {
50
- "minWidth" : '1280' , // Provide your own width, height and frame rate here
50
+ "minWidth" : '1280' , // Provide your own width, height and frame rate here
51
51
"minHeight" : '720' ,
52
52
"minFrameRate" : '30' ,
53
53
},
@@ -92,7 +92,7 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
92
92
final storagePath = await getExternalStorageDirectory ();
93
93
final filePath = storagePath.path + '/webrtc_sample/test.mp4' ;
94
94
_mediaRecorder = MediaRecorder ();
95
- setState ((){});
95
+ setState (() {});
96
96
await _localStream.getMediaTracks ();
97
97
final videoTrack = _localStream.getVideoTracks ().firstWhere ((track) => track.kind == "video" );
98
98
await _mediaRecorder.start (
@@ -103,22 +103,42 @@ class _GetUserMediaSampleState extends State<GetUserMediaSample> {
103
103
104
104
_stopRecording () async {
105
105
await _mediaRecorder? .stop ();
106
- setState ((){
106
+ setState (() {
107
107
_mediaRecorder = null ;
108
108
});
109
109
}
110
110
111
+ _captureFrame () async {
112
+ String filePath;
113
+ if (Platform .isAndroid) {
114
+ final storagePath = await getExternalStorageDirectory ();
115
+ filePath = storagePath.path + '/webrtc_sample/test.jpg' ;
116
+ } else {
117
+ final storagePath = await getApplicationDocumentsDirectory ();
118
+ filePath = storagePath.path + '/test${DateTime .now ()}.jpg' ;
119
+ }
120
+
121
+ final videoTrack = _localStream.getVideoTracks ().firstWhere ((track) => track.kind == "video" );
122
+ videoTrack.captureFrame (filePath);
123
+ }
124
+
111
125
@override
112
126
Widget build (BuildContext context) {
113
127
return new Scaffold (
114
128
appBar: new AppBar (
115
129
title: new Text ('GetUserMedia API Test' ),
116
- actions: _inCalling ? < Widget > [
117
- new IconButton (
118
- icon: Icon (_isRec ? Icons .stop : Icons .fiber_manual_record),
119
- onPressed: _isRec ? _stopRecording : _startRecording,
120
- ),
121
- ] : null ,
130
+ actions: _inCalling
131
+ ? < Widget > [
132
+ new IconButton (
133
+ icon: Icon (Icons .camera),
134
+ onPressed: _captureFrame,
135
+ ),
136
+ new IconButton (
137
+ icon: Icon (_isRec ? Icons .stop : Icons .fiber_manual_record),
138
+ onPressed: _isRec ? _stopRecording : _startRecording,
139
+ ),
140
+ ]
141
+ : null ,
122
142
),
123
143
body: new OrientationBuilder (
124
144
builder: (context, orientation) {
0 commit comments