2022-12-27 23:47:55 -05:00
|
|
|
import 'dart:io';
|
|
|
|
|
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
import 'package:frosty/screens/channel/video/video_store.dart';
|
2022-12-27 23:47:55 -05:00
|
|
|
import 'package:simple_pip_mode/simple_pip.dart';
|
2022-08-31 14:11:45 -04:00
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
|
|
/// Creates a [WebView] widget that shows a channel's video stream.
|
2022-12-27 23:47:55 -05:00
|
|
|
class Video extends StatefulWidget {
|
2022-08-31 14:11:45 -04:00
|
|
|
final VideoStore videoStore;
|
|
|
|
|
|
|
|
|
|
const Video({
|
|
|
|
|
Key? key,
|
|
|
|
|
required this.videoStore,
|
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
2022-12-27 23:47:55 -05:00
|
|
|
@override
|
|
|
|
|
State<Video> createState() => _VideoState();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class _VideoState extends State<Video> with WidgetsBindingObserver {
|
|
|
|
|
@override
|
|
|
|
|
void initState() {
|
|
|
|
|
super.initState();
|
|
|
|
|
WidgetsBinding.instance.addObserver(this);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@override
|
2023-04-29 11:34:28 -04:00
|
|
|
Future<void> didChangeAppLifecycleState(
|
|
|
|
|
AppLifecycleState lifecycleState) async {
|
|
|
|
|
if (Platform.isAndroid &&
|
|
|
|
|
!await SimplePip.isAutoPipAvailable &&
|
|
|
|
|
lifecycleState == AppLifecycleState.inactive) {
|
2022-12-27 23:47:55 -05:00
|
|
|
widget.videoStore.requestPictureInPicture();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2022-08-31 14:11:45 -04:00
|
|
|
@override
|
|
|
|
|
Widget build(BuildContext context) {
|
2023-05-30 21:10:04 -04:00
|
|
|
return WebViewWidget(
|
|
|
|
|
controller: widget.videoStore.videoWebViewController,
|
2022-08-31 14:11:45 -04:00
|
|
|
);
|
|
|
|
|
}
|
2022-12-27 23:47:55 -05:00
|
|
|
|
|
|
|
|
@override
|
|
|
|
|
void dispose() {
|
|
|
|
|
WidgetsBinding.instance.removeObserver(this);
|
|
|
|
|
super.dispose();
|
|
|
|
|
}
|
2022-08-31 14:11:45 -04:00
|
|
|
}
|