首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >颤栗-如何关闭youtube视频后,在网上查看回来的事件?

颤栗-如何关闭youtube视频后,在网上查看回来的事件?
EN

Stack Overflow用户
提问于 2019-04-01 02:53:23
回答 2查看 1.8K关注 0票数 0

所以我刚刚用颤音实现了这个webview,它很棒,但是当我使用WebView嵌入一个youtube视频时,这个视频仍然在播放,即使我关闭了Webview页面。我该怎么关掉它?

我使用的插件是flutter_webview_plugin

代码语言:javascript
运行
复制
final flutterWebviewPlugin =FlutterWebviewPlugin();

@override
  void initState() {
    super.initState();
    flutterWebviewPlugin.close();
  }

  @override
  void dispose() {
    super.dispose();
    flutterWebviewPlugin.dispose();
  }

这就是这个小部件:

代码语言:javascript
运行
复制
IconButton(
   icon: Icon(Icons.more_vert),
   onPressed: () {
   print('Hello there!'); flutterWebviewPlugin.launch('https://www.youtube.com/embed/m5rm8ac4Gsc');
},
)
EN

回答 2

Stack Overflow用户

发布于 2019-04-01 07:13:56

您可以做的是创建一条路由,但在其中您的webview示例:/youtubeWebview和使用Navigator.popAndPushNamed(context, '/yourRoute');返回而不是Navigator.pop(context);

票数 0
EN

Stack Overflow用户

发布于 2019-04-01 23:51:37

我终于得到了答案,但我将包改为webview_flutter,而不是flutter_webview_plugin

为了阻止来自youtube或任何其他有音频的网站的音频,我们需要更改当前we视图的url。也许它也适用于flutter_webview_plugin

代码语言:javascript
运行
复制
/* define webview controller */
WebViewController _controller;

/* before we leave current route, make sure to change the url to something */
Future<bool> _willPopCallback(WebViewController controller) async {
  controller.loadUrl('https://www.google.com/'); /* or you can use controller.reload() to just reload the page */

  return true;
}

return WillPopScope(
  onWillPop: () => _willPopCallback(_controller), /* call the function here */
  child: Scaffold(
     appBar: AppBar(
        title: Text('Just appbar'),
     ),
     body: Column(
        children: <Widget>[
           Expanded(
              child: WebView(
                key: UniqueKey(),
                javascriptMode: JavascriptMode.unrestricted,
                initialUrl: widget.videoUrl,
                onWebViewCreated: (WebViewController webViewController) { /* i am not sure what this line actually do */
                  _controller = webViewController;
                },
              ),
            ),
            Text(
              'Please pause the video before you go back',
              style: TextStyle(
                color: Colors.black,
              ),
            )
          ],
        ),
      ),
    );
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55447533

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档