Skip to content

Instantly share code, notes, and snippets.

@januwA
Last active June 14, 2020 10:03
Show Gist options
  • Save januwA/2eec33471ceacb1f57de8c364f2ee244 to your computer and use it in GitHub Desktop.
Save januwA/2eec33471ceacb1f57de8c364f2ee244 to your computer and use it in GitHub Desktop.
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:video_box/video_box.dart';
class MyFullVideoPage extends StatefulWidget {
final VideoController controller;
const MyFullVideoPage({Key key, this.controller}) : super(key: key);
@override
_MyFullVideoPageState createState() => _MyFullVideoPageState();
}
class _MyFullVideoPageState extends State<MyFullVideoPage>
with WidgetsBindingObserver {
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
switch (state) {
case AppLifecycleState.resumed:
break;
case AppLifecycleState.inactive:
widget.controller.pause();
break;
case AppLifecycleState.paused:
// When turning off the screen
widget.controller.onFullScreenSwitch(context);
break;
case AppLifecycleState.detached:
break;
default:
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(child: VideoBox(controller: widget.controller)),
);
}
}
class MyFullScreen implements CustomFullScreen {
const MyFullScreen();
@override
void close(BuildContext context, VideoController controller) {
print('pop...');
Navigator.of(context).pop(controller.value.positionText);
}
@override
Future open(BuildContext context, VideoController controller) async {
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
]);
SystemChrome.setEnabledSystemUIOverlays([]);
await Navigator.of(context)
.push<String>(
MaterialPageRoute(
builder: (_) => MyFullVideoPage(controller: controller),
),
)
.then(print);
SystemChrome.setPreferredOrientations([
DeviceOrientation.landscapeRight,
DeviceOrientation.landscapeLeft,
DeviceOrientation.portraitUp,
DeviceOrientation.portraitDown,
]);
SystemChrome.setEnabledSystemUIOverlays(SystemUiOverlay.values);
}
}
class OneVideoCtrl extends StatefulWidget {
@override
_OneVideoCtrlState createState() => _OneVideoCtrlState();
}
class _OneVideoCtrlState extends State<OneVideoCtrl> {
VideoController vc;
ScrollController controller = ScrollController();
@override
void initState() {
super.initState();
vc = VideoController(
source: VideoPlayerController.network(<video src>),
customFullScreen: const MyFullScreen(),
)..initialize().then((_) {
// initialized
});
}
@override
void dispose() {
vc.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('one video ctrl'),
),
body: ListView(
controller: controller,
children: <Widget>[
AspectRatio(
aspectRatio: 16 / 9,
child: VideoBox(controller: vc),
),
],
),
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment