flutter_inappwebview icon indicating copy to clipboard operation
flutter_inappwebview copied to clipboard

我在使用inappwebview的时候,打开了一个视频播放,页面卡死闪退,没有报错。

Open DavidChZh opened this issue 1 year ago • 4 comments

Flutter 3.16.3 使用inappwebview的时候,打开了一个视频播放,页面卡死闪退,没有报错。 我在flutter_inappwebview example上复现了这个问题。 该视频播放页面放在 webview_flutter: ^4.2.0,运行正常。

具体操作是: 1、下载flutter_inappwebview ,使用studio打开example项目 2、使用inappwebview随便打开一个网页,比如“http://www.baidu.com” 3、在打开网页的基础上,通过 Navigator.pushNamed(context, '/play')打开一个新的视频播放页面,视频播放插件版本 video_player: ^2.8.1,以下是我的视频播放页面代码。 ` import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:video_player/video_player.dart';

class VideoFullPlayer extends StatefulWidget { const VideoFullPlayer({ super.key, this.url = '', this.title = '', this.fullController, this.isBack = true, this.filePath = '', this.startPlaying = false, this.isAuthHeight, this.inDialog = false, });

final VideoPlayerController? fullController; final bool isBack; final String url; final String title; final String filePath; final bool startPlaying; final bool inDialog; final bool? isAuthHeight;

@override State<VideoFullPlayer> createState() => _VideoFullPlayerState(); }

class _VideoFullPlayerState extends State<VideoFullPlayer> { late VideoPlayerController controller;

@override void dispose() { controller.dispose(); controller.removeListener(videoCallBack); super.dispose(); }

bool isShowControl = true;

@override void initState() { controller = VideoPlayerController.networkUrl(Uri.parse( "https://dss2.bdstatic.com/5bVYsj_p_tVS5dKfpU_Y_D3/res/r/image/%202021-09-13-8/%E9%A3%8E.mp4")); controller.initialize().then((_) { setState(() {}); }); if (widget.startPlaying) controller.play(); controller.addListener(videoCallBack); super.initState(); }

videoCallBack() { if (controller.value.duration == controller.value.position) { controller.seekTo(Duration.zero); } setState(() {}); }

@override Widget build(BuildContext context) { return Scaffold( body: Container( width: double.infinity, height: (widget.isAuthHeight ?? false) ? null : 210, color: Colors.black, child: InkWell( onTap: () { isShowControl = !isShowControl; setState(() {}); }, child: Stack( children: [ Center( child: SizedBox( width: double.infinity, child: AspectRatio( aspectRatio: controller.value.aspectRatio, child: VideoPlayer(controller), )), ), if (isShowControl) Positioned( top: 0, left: 0, right: 0, child: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color(0x99000000), Color(0x00000000), ], )), height: 80, child: Column( children: [ if (widget.fullController != null) const SizedBox( height: 6, ), Row( children: [ InkWell( onTap: () { Navigator.pop(context); }, child: Visibility( visible: widget.isBack, child: Container( margin: const EdgeInsets.only( left: 10, top: 10, bottom: 10, right: 8), child: Text('返回'), ), ), ), ], ) ], ), ), ), ], ), ), )); } }

class VideoFullStatePage extends StatefulWidget { final VideoPlayerController controller;

const VideoFullStatePage( {super.key, required this.controller, required this.url, required this.title}); final String url; final String title; @override _VideoFullStatePageState createState() => _VideoFullStatePageState(); }

class _VideoFullStatePageState extends State<VideoFullStatePage> { @override void initState() { super.initState(); SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft, ]); }

@override void deactivate() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]); super.deactivate(); }

@override Widget build(BuildContext context) { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); return Scaffold( extendBody: true, body: PopScope( canPop: false, child: VideoFullPlayer( url: widget.url, title: widget.title, fullController: widget.controller, )), ); } }

class PlayPage extends StatefulWidget { const PlayPage({super.key});

@override State<PlayPage> createState() => _PlayPageState(); }

class _PlayPageState extends State<PlayPage> { @override Widget build(BuildContext context) { return Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top), child: VideoFullPlayer( url: "url", title: "title", filePath: "", startPlaying: true, ), ); }

late bool startPlaying; @override void initState() { super.initState(); } }

`

DavidChZh avatar Jan 10 '24 03:01 DavidChZh

👋 @resultto

NOTE: This comment is auto-generated.

Are you sure you have already searched for the same problem?

Some people open new issues but they didn't search for something similar or for the same issue. Please, search for it using the GitHub issue search box or on the official inappwebview.dev website, or, also, using Google, StackOverflow, etc. before posting a new one. You may already find an answer to your problem!

If this is really a new issue, then thank you for raising it. I will investigate it and get back to you as soon as possible. Please, make sure you have given me as much context as possible! Also, if you didn't already, post a code example that can replicate this issue.

In the meantime, you can already search for some possible solutions online! Because this plugin uses native WebView, you can search online for the same issue adding android WebView [MY ERROR HERE] or ios WKWebView [MY ERROR HERE] keywords.

Following these steps can save you, me, and other people a lot of time, thanks!

github-actions[bot] avatar Jan 10 '24 03:01 github-actions[bot]

https://github.com/flutter/flutter/issues/138947

Jinxishihenian avatar Jan 10 '24 08:01 Jinxishihenian

Please, use english to share what you’re saying to everyone (and me too), thanks.

pichillilorenzo avatar Jan 10 '24 11:01 pichillilorenzo

Please, use english to share what you’re saying to everyone (and me too), thanks.

Flutter 3.16.3 When using inappwebview, I opened a video to play, but the page got stuck and crashed, and no error was reported. I reproduced this problem on the flutter_inappwebview example. The video playback page is placed in webview_flutter: ^4.2.0 and runs normally.

The specific operations are:

  1. Download flutter_inappwebview and use studio to open the example project
  2. Use inappwebview to open a web page at will, such as "http://www.baidu.com"
  3. After opening the web page, open a new video playback page through Navigator.pushNamed(context, '/play'). The video playback plug-in version is video_player: ^2.8.1. The following is my video playback page code `import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:video_player/video_player.dart';

class VideoFullPlayer extends StatefulWidget { const VideoFullPlayer({ super.key, this.url = '', this.title = '', this.fullController, this.isBack = true, this.filePath = '', this.startPlaying = false, this.isAuthHeight, this.inDialog = false, });

final VideoPlayerController? fullController; final bool isBack; final String url; final String title; final String filePath; final bool startPlaying; final bool inDialog; final bool? isAuthHeight;

@OverRide State createState() => _VideoFullPlayerState(); }

class _VideoFullPlayerState extends State { late VideoPlayerController controller;

@OverRide void dispose() { controller.dispose(); controller.removeListener(videoCallBack); super.dispose(); }

bool isShowControl = true;

@OverRide void initState() { controller = VideoPlayerController.networkUrl(Uri.parse( "https://dss2.bdstatic.com/5bVYsj_p_tVS5dKfpU_Y_D3/res/r/image/%202021-09-13-8/%E9%A3%8E.mp4")); controller.initialize().then((_) { setState(() {}); }); if (widget.startPlaying) controller.play(); controller.addListener(videoCallBack); super.initState(); }

videoCallBack() { if (controller.value.duration == controller.value.position) { controller.seekTo(Duration.zero); } setState(() {}); }

@OverRide Widget build(BuildContext context) { return Scaffold( body: Container( width: double.infinity, height: (widget.isAuthHeight ?? false) ? null : 210, color: Colors.black, child: InkWell( onTap: () { isShowControl = !isShowControl; setState(() {}); }, child: Stack( children: [ Center( child: SizedBox( width: double.infinity, child: AspectRatio( aspectRatio: controller.value.aspectRatio, child: VideoPlayer(controller), )), ), if (isShowControl) Positioned( top: 0, left: 0, right: 0, child: Container( decoration: const BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, end: Alignment.bottomCenter, colors: [ Color(0x99000000), Color(0x00000000), ], )), height: 80, child: Column( children: [ if (widget.fullController != null) const SizedBox( height: 6, ), Row( children: [ InkWell( onTap: () { Navigator.pop(context); }, child: Visibility( visible: widget.isBack, child: Container( margin: const EdgeInsets.only( left: 10, top: 10, bottom: 10, right: 8), child: Text('返回'), ), ), ), ], ) ], ), ), ), ], ), ), )); } }

class VideoFullStatePage extends StatefulWidget { final VideoPlayerController controller;

const VideoFullStatePage( {super.key, required this.controller, required this.url, required this.title}); final String url; final String title; @OverRide _VideoFullStatePageState createState() => _VideoFullStatePageState(); }

class _VideoFullStatePageState extends State { @OverRide void initState() { super.initState(); SystemChrome.setPreferredOrientations([ DeviceOrientation.landscapeLeft, ]); }

@OverRide void deactivate() { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: [SystemUiOverlay.top, SystemUiOverlay.bottom]); super.deactivate(); }

@OverRide Widget build(BuildContext context) { SystemChrome.setEnabledSystemUIMode(SystemUiMode.manual, overlays: []); return Scaffold( extendBody: true, body: PopScope( canPop: false, child: VideoFullPlayer( url: widget.url, title: widget.title, fullController: widget.controller, )), ); } }

class PlayPage extends StatefulWidget { const PlayPage({super.key});

@OverRide State createState() => _PlayPageState(); }

class _PlayPageState extends State { @OverRide Widget build(BuildContext context) { return Container( margin: EdgeInsets.only(top: MediaQuery.of(context).padding.top), child: VideoFullPlayer( url: "url", title: "title", filePath: "", startPlaying: true, ), ); }

late bool startPlaying; @OverRide void initState() { super.initState(); } } `

DavidChZh avatar Jan 11 '24 00:01 DavidChZh