2022-08-28 20:51:12 +00:00
|
|
|
import 'dart:async';
|
2022-11-30 23:50:55 +00:00
|
|
|
|
2022-08-28 20:51:12 +00:00
|
|
|
import 'package:flutter/material.dart';
|
2023-07-04 19:20:14 +00:00
|
|
|
import 'package:media_kit/media_kit.dart';
|
|
|
|
import 'package:media_kit_video/media_kit_video.dart';
|
2022-11-30 23:50:55 +00:00
|
|
|
import 'package:openmediacentermobile/db/settings_db.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
|
2022-08-30 21:25:21 +00:00
|
|
|
import '../api/video_api.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
import '../screen_loading.dart';
|
|
|
|
import '../types/video.dart';
|
|
|
|
import '../types/video_data.dart';
|
2022-11-30 23:50:55 +00:00
|
|
|
import '../utils/platform.dart';
|
2022-08-28 20:51:12 +00:00
|
|
|
import 'info_view.dart';
|
|
|
|
|
|
|
|
class VideoScreen extends StatefulWidget {
|
|
|
|
const VideoScreen({Key? key, required this.metaData}) : super(key: key);
|
|
|
|
final VideoT metaData;
|
|
|
|
|
|
|
|
@override
|
|
|
|
State<VideoScreen> createState() => _VideoScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VideoScreenState extends State<VideoScreen> {
|
|
|
|
bool _appBarVisible = true;
|
|
|
|
Timer? _appBarTimer;
|
|
|
|
late Future<VideoData> _videoData;
|
|
|
|
PageController _controller = PageController(
|
|
|
|
initialPage: 0,
|
|
|
|
);
|
2023-07-04 19:20:14 +00:00
|
|
|
// Create a [Player] to control playback.
|
|
|
|
late final player = Player();
|
|
|
|
// Create a [VideoController] to handle video output from [Player].
|
|
|
|
late final controller = VideoController(player);
|
2022-08-28 20:51:12 +00:00
|
|
|
|
|
|
|
String url = "";
|
|
|
|
|
|
|
|
void initPlayer() async {
|
|
|
|
final videodata = await _videoData;
|
|
|
|
|
2022-11-30 23:50:55 +00:00
|
|
|
final settings = await SettingsDB.getInstance().getSettings();
|
|
|
|
final path = settings.domain + settings.videopath + videodata.movieUrl;
|
2023-07-04 19:20:14 +00:00
|
|
|
player.open(Media(path));
|
2022-08-28 20:51:12 +00:00
|
|
|
|
|
|
|
url = path;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
2022-08-30 21:25:21 +00:00
|
|
|
_videoData = loadVideoData(widget.metaData.id);
|
2022-08-28 20:51:12 +00:00
|
|
|
initPlayer();
|
|
|
|
_setAppBarTimer();
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
2022-08-29 15:16:51 +00:00
|
|
|
super.dispose();
|
2023-07-04 19:20:14 +00:00
|
|
|
player.dispose();
|
2022-08-28 20:51:12 +00:00
|
|
|
_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<VideoData> 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) {
|
2022-10-15 18:28:31 +00:00
|
|
|
await Future.delayed(Duration(milliseconds: 300));
|
2022-08-28 20:51:12 +00:00
|
|
|
setState(() {
|
|
|
|
_appBarVisible = false;
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (!isDesktop()) {
|
|
|
|
setState(() {
|
|
|
|
_appBarVisible = true;
|
|
|
|
});
|
|
|
|
_setAppBarTimer();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2022-08-30 21:25:21 +00:00
|
|
|
// behavior: HitTestBehavior.opaque,
|
2022-08-28 20:51:12 +00:00
|
|
|
child: Stack(children: [
|
|
|
|
PageView(
|
|
|
|
scrollDirection: Axis.vertical,
|
|
|
|
controller: _controller,
|
|
|
|
children: [
|
|
|
|
Center(
|
2023-07-04 19:20:14 +00:00
|
|
|
child: Video(controller: controller)),
|
2022-08-28 20:51:12 +00:00
|
|
|
InfoView(
|
2022-08-30 21:25:21 +00:00
|
|
|
videoId: widget.metaData.id,
|
2022-08-28 20:51:12 +00:00
|
|
|
)
|
|
|
|
]),
|
|
|
|
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),
|
2023-07-04 19:20:14 +00:00
|
|
|
onPressed: () async {
|
|
|
|
await player.stop();
|
|
|
|
Navigator.of(context).pop();
|
|
|
|
},
|
2022-08-28 20:51:12 +00:00
|
|
|
),
|
|
|
|
backgroundColor:
|
|
|
|
Theme.of(context).primaryColor.withOpacity(0.3),
|
|
|
|
elevation: 0.0,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
]),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
return ScreenLoading();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|