1212// See the License for the specific language governing permissions and
1313// limitations under the License.
1414
15+ import 'dart:math' ;
16+
1517import 'package:flutter/foundation.dart' ;
1618import 'package:flutter/material.dart' ;
1719
@@ -77,6 +79,25 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
7779 return _renderer! ;
7880 }
7981
82+ void setZoom (double zoomLevel) async {
83+ final videoTrack = _renderer? .srcObject! .getVideoTracks ().first;
84+ if (videoTrack == null ) return ;
85+ await rtc.Helper .setZoom (videoTrack, zoomLevel);
86+ }
87+
88+ void onViewFinderTap (TapDownDetails details, BoxConstraints constraints) {
89+ final videoTrack = _renderer? .srcObject! .getVideoTracks ().first;
90+ if (videoTrack == null ) return ;
91+
92+ final point = Point <double >(
93+ details.localPosition.dx / constraints.maxWidth,
94+ details.localPosition.dy / constraints.maxHeight,
95+ );
96+
97+ rtc.Helper .setFocusPoint (videoTrack, point);
98+ rtc.Helper .setExposurePoint (videoTrack, point);
99+ }
100+
80101 void disposeRenderer () {
81102 try {
82103 _renderer? .srcObject = null ;
@@ -158,6 +179,28 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
158179 },
159180 );
160181
182+ Widget _videoRendererView () {
183+ if (lkPlatformIs (PlatformType .iOS) &&
184+ [VideoRenderMode .auto, VideoRenderMode .platformView]
185+ .contains (widget.renderMode)) {
186+ return rtc.RTCVideoPlatFormView (
187+ mirror: _shouldMirror (),
188+ objectFit: widget.fit,
189+ onViewReady: (controller) {
190+ _renderer = controller;
191+ _renderer? .srcObject = widget.track.mediaStream;
192+ _attach ();
193+ },
194+ );
195+ }
196+ return rtc.RTCVideoView (
197+ _renderer! as rtc.RTCVideoRenderer ,
198+ mirror: _shouldMirror (),
199+ filterQuality: FilterQuality .medium,
200+ objectFit: widget.fit,
201+ );
202+ }
203+
161204 Widget _videoViewForNative () => FutureBuilder (
162205 future: _initializeRenderer (),
163206 builder: (context, snapshot) {
@@ -172,24 +215,24 @@ class _VideoTrackRendererState extends State<VideoTrackRenderer> {
172215 ? .addPostFrameCallback ((timeStamp) {
173216 widget.track.onVideoViewBuild? .call (_internalKey);
174217 });
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- );
218+
219+ if (! lkPlatformIsMobile () || widget.track is ! LocalVideoTrack ) {
220+ return _videoRendererView ();
187221 }
188- return rtc.RTCVideoView (
189- _renderer! as rtc.RTCVideoRenderer ,
190- mirror: _shouldMirror (),
191- filterQuality: FilterQuality .medium,
192- objectFit: widget.fit,
222+ return LayoutBuilder (
223+ builder: (BuildContext context, BoxConstraints constraints) {
224+ return GestureDetector (
225+ onScaleStart: (details) {},
226+ onScaleUpdate: (details) {
227+ if (details.scale != 1.0 ) {
228+ setZoom (details.scale);
229+ }
230+ },
231+ onTapDown: (TapDownDetails details) =>
232+ onViewFinderTap (details, constraints),
233+ child: _videoRendererView (),
234+ );
235+ },
193236 );
194237 },
195238 );
0 commit comments