如何在不失去控件焦点的情况下向视频播放器添加双击手势?

How to add a double tap gesture to video player without loosing the focus of controls?

我试过包裹

return ClipRRect(
            borderRadius: BorderRadius.circular(30.0),
            child: Chewie(
              controller: _chewieController,
            )

return Stack(
            children: [
              ClipRRect(
                borderRadius: BorderRadius.circular(30.0),
                child: Chewie(
                  controller: _chewieController,
                ),
              ),
              Positioned.fill(child: GestureDetector(
                onDoubleTap: (){
                  print('its double tapped ');
                },
                child: Container(
                  color: Colors.transparent,
                  height: double.infinity,
                  width: double.infinity,
                ),))
            ],
          );

现在我可以双击了,但是单击一下,控制器不会出现,有什么办法可以同时实现这两个功能。
使用 doubleTap,我可以调用 like 函数并使用 onTap 来显示控制器。
chewie 0.12.0

上面使用的包

我不知道 Chewie 是如何构建的,但如果有 GestureDetector,您可以将其更改为如下所示:

GestureDetector(
    behavior: HitTestBehavior.opaque,
    onTap: () => setState(() => // show_controls,),
    onDoubleTap:() => setState(() => // like behaviour,),
    child: VideoWidget // or whatever is there
}

因此您可以在一个小部件上同时拥有两个侦听器。我认为这样 onTap 会稍有延迟来检查它是否不是 onDoubleTap。这样您就不必在小部件上放置叠加层。

如果出于某种原因你想要这个覆盖...那么这里有趣的属性是 behaviour 因为它决定后面的元素是否会接收事件。

https://api.flutter.dev/flutter/rendering/PlatformViewHitTestBehavior-class.html

更新 试试换成

GestureDetector(
                behavior: HitTestBehavior.translucent,
                onDoubleTap: (){
                  print('its double tapped ');
                }

在github项目中,这一行: https://github.com/flutter/plugins/blob/master/packages/video_player/video_player/example/lib/main.dart#L290

似乎只有在视频处于暂停状态时控件才会显示。大概是这个值controller.value.isPlaying.

为什么不在自己的 GestureDetector 中控制它?

GestureDetector(
    behavior: HitTestBehavior.opaque,
    onTap: () => setState(() => _controller.pause() ,), //changing here 
    onDoubleTap:() => setState(() => // like behaviour,),
    child: VideoWidget // or whatever is there
}

无论如何,希望你能找到答案

return GestureDetector(
            behavior: HitTestBehavior.opaque,
            onTapDown: (_) {
              setState(() {
                isMute = !isMute;
                _chewieController.setVolume(isMute ? 0 : 1);
              });
            },
            onDoubleTap: (){
              print('liked');
            },
            child: ClipRRect(
              borderRadius: BorderRadius.circular(30.0),
              child: Chewie(
                controller: _chewieController,
              ),
            ),
          );

在视频的简单 onTap 上,它显示了控制器,因此这里的 onTap 没有被覆盖
onTapDown 用作 onTap 的替代方法来使视频静音。