2021-11-11 21:32:05 -05:00
|
|
|
import 'dart:async';
|
2021-11-15 00:03:18 -05:00
|
|
|
import 'dart:io';
|
2021-11-11 21:32:05 -05:00
|
|
|
import 'package:mobx/mobx.dart';
|
|
|
|
|
import 'package:webview_flutter/webview_flutter.dart';
|
|
|
|
|
|
|
|
|
|
part 'video_store.g.dart';
|
|
|
|
|
|
|
|
|
|
class VideoStore = _VideoStoreBase with _$VideoStore;
|
|
|
|
|
|
|
|
|
|
abstract class _VideoStoreBase with Store {
|
|
|
|
|
late final WebViewController controller;
|
|
|
|
|
|
|
|
|
|
late Timer timer;
|
|
|
|
|
|
|
|
|
|
_VideoStoreBase() {
|
2021-11-12 16:50:02 -05:00
|
|
|
timer = Timer(const Duration(seconds: 3), () => menuVisible = false);
|
2021-11-11 21:32:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@observable
|
|
|
|
|
var menuVisible = true;
|
|
|
|
|
|
|
|
|
|
@observable
|
|
|
|
|
var paused = false;
|
|
|
|
|
|
|
|
|
|
void handlePausePlay() {
|
2021-11-13 03:44:32 -05:00
|
|
|
if (paused) {
|
|
|
|
|
controller.runJavascript('document.getElementsByTagName("video")[0].play();');
|
|
|
|
|
} else {
|
|
|
|
|
controller.runJavascript('document.getElementsByTagName("video")[0].pause();');
|
2021-11-13 03:27:28 -05:00
|
|
|
}
|
2021-11-13 03:44:32 -05:00
|
|
|
|
|
|
|
|
paused = !paused;
|
2021-11-11 21:32:05 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void handleVideoTap() async {
|
2021-11-12 03:45:27 -05:00
|
|
|
if (menuVisible) {
|
|
|
|
|
timer.cancel();
|
|
|
|
|
|
2021-11-11 21:32:05 -05:00
|
|
|
menuVisible = false;
|
2021-11-12 03:45:27 -05:00
|
|
|
} else {
|
|
|
|
|
timer.cancel();
|
|
|
|
|
timer = Timer(const Duration(seconds: 5), () {
|
|
|
|
|
menuVisible = false;
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
menuVisible = true;
|
|
|
|
|
}
|
2021-11-11 21:32:05 -05:00
|
|
|
}
|
|
|
|
|
|
2021-11-14 04:25:33 -05:00
|
|
|
void initVideo() {
|
2021-11-14 18:54:21 -05:00
|
|
|
controller.runJavascript('document.getElementsByTagName("button")[0].click();');
|
|
|
|
|
controller.runJavascript('document.getElementsByTagName("video")[0].muted = false;');
|
2021-11-11 21:32:05 -05:00
|
|
|
}
|
|
|
|
|
|
2021-11-14 20:53:00 -05:00
|
|
|
void enterPictureInPicture() {
|
|
|
|
|
controller.runJavascript('document.getElementsByTagName("video")[0].disablePictureInPicture = false;');
|
|
|
|
|
controller.runJavascript('document.getElementsByTagName("video")[0].requestPictureInPicture();');
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-11 21:32:05 -05:00
|
|
|
void requestFullscreen() {
|
2021-11-15 00:03:18 -05:00
|
|
|
Platform.isIOS
|
|
|
|
|
? controller.runJavascript('document.getElementsByTagName("video")[0].webkitEnterFullscreen();')
|
|
|
|
|
: controller.runJavascript('document.getElementsByTagName("video")[0].requestFullscreen();');
|
2021-11-11 21:32:05 -05:00
|
|
|
}
|
|
|
|
|
}
|