-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Youtube videos playing on background when device is inactive. Which cause playstore to reject app #372
Comments
For Android, you can use Check the API docs if you need more detail. Howevert, here is an example with a YouTube video: import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
InAppWebViewController webView;
@override
void initState() {
WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print('state = $state');
if (webView != null) {
if (state == AppLifecycleState.paused) {
webView.pauseTimers();
if (Platform.isAndroid) {
webView.android.pause();
}
} else {
webView.resumeTimers();
if (Platform.isAndroid) {
webView.android.resume();
}
}
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('InAppWebView Example'),
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
initialUrl: "https://www.youtube.com/watch?v=NfNdXgJZfFo",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {},
onLoadStop: (InAppWebViewController controller, String url) {},
))
])),
),
);
}
} |
inAppWebview flickering anyway to go around that? |
What do you mean? Can you make an example/screen record? |
I mean it flickers when keyboard show ups any way to go around that |
Unfortunately no. This is related to how Flutter embeds Android native views inside its widget tree. I know that somebody is working on another way to embed Android native views. |
Ok awesome thank very helpfull |
@thang510023 have u ever fixed bug when playing mp3 ? |
This solution is working on Android but still have the issue on iOS |
I got it working for both android and iOS by having import 'dart:async';
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
Future main() async {
WidgetsFlutterBinding.ensureInitialized();
runApp(MyApp());
}
class MyApp extends StatefulWidget {
@override
_MyAppState createState() => new _MyAppState();
}
class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
InAppWebViewController webView;
@override
void initState() {
WidgetsBinding.instance.addObserver(this);
super.initState();
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
print('state = $state');
if (webView != null) {
if (state == AppLifecycleState.paused) {
if (Platform.isAndroid) {
webView.pauseTimers(); // Pause timers only for android
webView.android.pause();
}
} else {
if (Platform.isAndroid) {
webView.resumeTimers(); // Resume timers only for android
webView.android.resume();
}
}
}
}
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
appBar: AppBar(
title: const Text('InAppWebView Example'),
),
body: Container(
child: Column(children: <Widget>[
Expanded(
child: InAppWebView(
initialUrl: "https://www.youtube.com/watch?v=NfNdXgJZfFo",
initialHeaders: {},
initialOptions: InAppWebViewGroupOptions(
crossPlatform: InAppWebViewOptions(
debuggingEnabled: true,
),
),
onWebViewCreated: (InAppWebViewController controller) {
webView = controller;
},
onLoadStart: (InAppWebViewController controller, String url) {},
onLoadStop: (InAppWebViewController controller, String url) {},
))
])),
),
);
}
} |
I must say, you guys have done an amazing job. |
This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug and a minimal reproduction of the issue. |
Environment
Flutter version: 1.17.0
Plugin version: flutter_inappwebview 3.3.0
Android version: 9.0
iOS version:---
Xcode version: ---
Device information: techno
Description
Expected behavior:
Current behavior:
Steps to reproduce
Images
Stacktrace/Logcat
The text was updated successfully, but these errors were encountered: