Reputation: 3665
I have a Flutter app that can show YouTube videos inside WebView. It works ok, except in one case: if you open it fullscreen and that pres=s embedded "exit from fullscreen" button in YouTube player: after exiting from fullscreen I still hear the sound, but I see a black screen with button share and watch later. In case when I exit from fullscreen mode by pressing the android back button it works ok. Ho to fix it?
Widget build(BuildContext context) {
return Container(
child: MyWebView(
initUrl:
'https://www.youtube.com/embed/${id}?autoplay=1&rel=0&showinfo=0',
),
)
}
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
class MyWebView extends StatefulWidget {
final String initUrl;
MyWebView({
this.initUrl,
});
@override
MyWebViewState createState() => MyWebViewState();
}
class MyWebViewState extends State<MyWebView> {
InAppWebViewController webView;
String url;
bool webLoadError = false;
@override
void initState() {
url = widget.initUrl;
super.initState();
}
@override
Widget build(BuildContext context) {
return Stack(
children: [
InAppWebView(
initialUrl: url,
initialHeaders: widget.headers,
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
useShouldOverrideUrlLoading: true,
clearCache: true,
mediaPlaybackRequiresUserGesture: false,
),
),
onLoadStart: (controller, string) {
setState(() {
webView = controller;
webLoadError = false;
});
},
);
}
}
Upvotes: 2
Views: 2126
Reputation: 1643
If you put in your code, maybe I could help you more. Maybe the reason is a video still not ready when you show it. You can check with _controller.value.initialized
, when a video is not ready to return Container()
code snippet:
return Center(
child: _controller.value.initialized
? AspectRatio(
aspectRatio: _controller.value.aspectRatio,
child: VideoPlayer(_controller),
)
: Container(),
);
Or if you use webview remove these lines from the application tag.
android:hardwareAccelerated="false"
android:largeHeap="true"
Upvotes: 1