@@ -34,16 +34,24 @@ enum VideoViewMirrorMode {
3434 mirror,
3535}
3636
37+ enum VideoRenderMode {
38+ auto,
39+ texture,
40+ platformView,
41+ }
42+
3743/// Widget that renders a [VideoTrack] .
3844class VideoTrackRenderer extends StatefulWidget {
3945 final VideoTrack track;
4046 final rtc.RTCVideoViewObjectFit fit;
4147 final VideoViewMirrorMode mirrorMode;
48+ final VideoRenderMode renderMode;
4249
4350 const VideoTrackRenderer (
4451 this .track, {
4552 this .fit = rtc.RTCVideoViewObjectFit .RTCVideoViewObjectFitContain ,
4653 this .mirrorMode = VideoViewMirrorMode .auto,
54+ this .renderMode = VideoRenderMode .auto,
4755 Key ? key,
4856 }) : super (key: key);
4957
@@ -52,14 +60,17 @@ class VideoTrackRenderer extends StatefulWidget {
5260}
5361
5462class _VideoTrackRendererState extends State <VideoTrackRenderer > {
55- rtc.RTCVideoRenderer ? _renderer;
63+ rtc.VideoRenderer ? _renderer;
5664 // for flutter web only.
5765 bool _rendererReadyForWeb = false ;
5866 EventsListener <TrackEvent >? _listener;
5967 // Used to compute visibility information
6068 late GlobalKey _internalKey;
6169
62- Future <rtc.RTCVideoRenderer > _initializeRenderer () async {
70+ Future <rtc.VideoRenderer > _initializeRenderer () async {
71+ if (widget.renderMode == VideoRenderMode .platformView) {
72+ return Null as Future <rtc.VideoRenderer >;
73+ }
6374 _renderer ?? = rtc.RTCVideoRenderer ();
6475 await _renderer! .initialize ();
6576 await _attach ();
@@ -139,7 +150,7 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
139150 widget.track.onVideoViewBuild? .call (_internalKey);
140151 });
141152 return rtc.RTCVideoView (
142- _renderer! ,
153+ _renderer! as rtc. RTCVideoRenderer ,
143154 mirror: _shouldMirror (),
144155 filterQuality: FilterQuality .medium,
145156 objectFit: widget.fit,
@@ -150,7 +161,9 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
150161 Widget _videoViewForNative () => FutureBuilder (
151162 future: _initializeRenderer (),
152163 builder: (context, snapshot) {
153- if (snapshot.hasData && _renderer != null ) {
164+ if ((snapshot.hasData && _renderer != null ) ||
165+ [VideoRenderMode .auto, VideoRenderMode .platformView]
166+ .contains (widget.renderMode)) {
154167 return Builder (
155168 key: _internalKey,
156169 builder: (ctx) {
@@ -159,8 +172,21 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
159172 ? .addPostFrameCallback ((timeStamp) {
160173 widget.track.onVideoViewBuild? .call (_internalKey);
161174 });
175+ if (lkPlatformIs (PlatformType .iOS) &&
176+ [VideoRenderMode .auto, VideoRenderMode .platformView]
177+ .contains (widget.renderMode)) {
178+ return rtc.RTCVideoPlatFormView (
179+ mirror: _shouldMirror (),
180+ objectFit: widget.fit,
181+ onViewReady: (controller) {
182+ _renderer = controller;
183+ _renderer? .srcObject = widget.track.mediaStream;
184+ _attach ();
185+ },
186+ );
187+ }
162188 return rtc.RTCVideoView (
163- _renderer! ,
189+ _renderer! as rtc. RTCVideoRenderer ,
164190 mirror: _shouldMirror (),
165191 filterQuality: FilterQuality .medium,
166192 objectFit: widget.fit,
0 commit comments