Add auto PiP on Android and redesign stream overlay (#218)
* Improve PiP behavior (Android) Added the ability to enter PiP mode when leaving the app on Android. * Add automatic PiP option * Redesign video overlay * Update stream card uptime counter * Use gradient for overlay opacity * Restore play button when paused on iOS * Restore refresh button on overlay * Prefer above for category tooltip * Increase default overlay opacity to 80% * Improve pip behavior * Fix uptime setState after dispose * Remove automatic pip option Redundant since you can disable it in system settings * Check if `setAutoEnterEnabled` is available * Fix missing pip auto enter * Disable auto pip when leaving channel * Fix pip exception on iOS
This commit is contained in:
parent
3746665179
commit
9570d43e43
11 changed files with 288 additions and 129 deletions
|
|
@ -1,9 +1,12 @@
|
|||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:frosty/screens/channel/video/video_store.dart';
|
||||
import 'package:simple_pip_mode/simple_pip.dart';
|
||||
import 'package:webview_flutter/webview_flutter.dart';
|
||||
|
||||
/// Creates a [WebView] widget that shows a channel's video stream.
|
||||
class Video extends StatelessWidget {
|
||||
class Video extends StatefulWidget {
|
||||
final VideoStore videoStore;
|
||||
|
||||
const Video({
|
||||
|
|
@ -11,18 +14,42 @@ class Video extends StatelessWidget {
|
|||
required this.videoStore,
|
||||
}) : super(key: key);
|
||||
|
||||
@override
|
||||
State<Video> createState() => _VideoState();
|
||||
}
|
||||
|
||||
class _VideoState extends State<Video> with WidgetsBindingObserver {
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
WidgetsBinding.instance.addObserver(this);
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState lifecycleState) async {
|
||||
if (Platform.isAndroid && !await SimplePip.isAutoPipAvailable && lifecycleState == AppLifecycleState.inactive) {
|
||||
widget.videoStore.requestPictureInPicture();
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return WebView(
|
||||
backgroundColor: Colors.black,
|
||||
initialUrl: videoStore.videoUrl,
|
||||
initialUrl: widget.videoStore.videoUrl,
|
||||
javascriptMode: JavascriptMode.unrestricted,
|
||||
allowsInlineMediaPlayback: true,
|
||||
initialMediaPlaybackPolicy: AutoMediaPlaybackPolicy.always_allow,
|
||||
onWebViewCreated: (controller) => videoStore.controller = controller,
|
||||
onPageFinished: (string) => videoStore.initVideo(),
|
||||
navigationDelegate: videoStore.handleNavigation,
|
||||
javascriptChannels: videoStore.javascriptChannels,
|
||||
onWebViewCreated: (controller) => widget.videoStore.controller = controller,
|
||||
onPageFinished: (string) => widget.videoStore.initVideo(),
|
||||
navigationDelegate: widget.videoStore.handleNavigation,
|
||||
javascriptChannels: widget.videoStore.javascriptChannels,
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
super.dispose();
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue