import 'dart:async'; import 'package:flutter/material.dart'; import 'package:media_kit/media_kit.dart'; import 'package:media_kit_video/media_kit_video.dart'; import 'package:openmediacentermobile/db/settings_db.dart'; import '../api/video_api.dart'; import '../screen_loading.dart'; import '../types/video.dart'; import '../types/video_data.dart'; import '../utils/platform.dart'; import 'info_view.dart'; class VideoScreen extends StatefulWidget { const VideoScreen({Key? key, required this.metaData}) : super(key: key); final VideoT metaData; @override State createState() => _VideoScreenState(); } class _VideoScreenState extends State { bool _appBarVisible = true; Timer? _appBarTimer; late Future _videoData; PageController _controller = PageController( initialPage: 0, ); // Create a [Player] to control playback. late final player = Player(); // Create a [VideoController] to handle video output from [Player]. late final controller = VideoController(player); String url = ""; void initPlayer() async { final videodata = await _videoData; final settings = await SettingsDB.getInstance().getSettings(); final path = settings.domain + settings.videopath + videodata.movieUrl; player.open(Media(path)); url = path; } @override void initState() { super.initState(); _videoData = loadVideoData(widget.metaData.id); initPlayer(); _setAppBarTimer(); } @override void dispose() { super.dispose(); player.dispose(); _controller.dispose(); _appBarTimer?.cancel(); } void _setAppBarTimer() { _appBarTimer?.cancel(); _appBarTimer = Timer( Duration(seconds: 3), () { setState(() { _appBarVisible = false; }); }, ); } @override Widget build(BuildContext context) { return Scaffold( body: FutureBuilder( future: _videoData, builder: (context, AsyncSnapshot snapshot) { if (snapshot.hasError) { return Text("Error"); } else if (snapshot.hasData) { return MouseRegion( onHover: (PointerEvent event) async { if (isDesktop()) { if (event.delta.dx != 0 || event.delta.dy != 0) { setState(() { _appBarVisible = true; }); _setAppBarTimer(); } } }, child: GestureDetector( onPanDown: (details) async { if (_appBarVisible) { await Future.delayed(Duration(milliseconds: 300)); setState(() { _appBarVisible = false; }); } else { if (!isDesktop()) { setState(() { _appBarVisible = true; }); _setAppBarTimer(); } } }, // behavior: HitTestBehavior.opaque, child: Stack(children: [ PageView( scrollDirection: Axis.vertical, controller: _controller, children: [ Center( child: Video(controller: controller)), InfoView( videoId: widget.metaData.id, ) ]), if (_appBarVisible) new Positioned( top: 0.0, left: 0.0, right: 0.0, child: AppBar( title: Text(widget.metaData.title), leading: new IconButton( icon: new Icon(Icons.arrow_back_ios, color: Colors.grey), onPressed: () async { await player.stop(); Navigator.of(context).pop(); }, ), backgroundColor: Theme.of(context).primaryColor.withOpacity(0.3), elevation: 0.0, ), ), ]), ), ); } else { return ScreenLoading(); } }, ), ); } }