2022-04-15 16:15:44 +00:00
|
|
|
import 'dart:convert';
|
|
|
|
import 'dart:math';
|
|
|
|
|
2022-04-15 18:19:09 +00:00
|
|
|
import 'package:chewie/chewie.dart';
|
2022-04-15 16:15:44 +00:00
|
|
|
import "package:dart_vlc/dart_vlc.dart";
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter/services.dart';
|
2022-04-15 19:57:15 +00:00
|
|
|
import 'package:openmediacentermobile/preview_tile.dart';
|
2022-04-15 18:19:09 +00:00
|
|
|
import 'package:video_player/video_player.dart';
|
2022-04-15 16:15:44 +00:00
|
|
|
|
|
|
|
import 'api/api.dart';
|
|
|
|
import 'api/token.dart';
|
|
|
|
import 'platform.dart';
|
|
|
|
|
|
|
|
class VideoScreen extends StatefulWidget {
|
2022-08-25 17:48:09 +00:00
|
|
|
const VideoScreen({Key? key, required this.metaData}) : super(key: key);
|
|
|
|
final VideoT metaData;
|
2022-04-15 16:15:44 +00:00
|
|
|
|
|
|
|
@override
|
|
|
|
State<VideoScreen> createState() => _VideoScreenState();
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VideoScreenState extends State<VideoScreen> {
|
2022-08-25 20:48:44 +00:00
|
|
|
Player? _player =
|
|
|
|
isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
|
2022-04-15 18:19:09 +00:00
|
|
|
ChewieController? _chewieController;
|
2022-04-15 16:15:44 +00:00
|
|
|
|
|
|
|
void loadData() async {
|
2022-08-25 20:48:44 +00:00
|
|
|
final data =
|
|
|
|
await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
|
2022-04-15 16:15:44 +00:00
|
|
|
|
|
|
|
final d = jsonDecode(data);
|
|
|
|
|
|
|
|
final url = d["MovieUrl"];
|
|
|
|
final token = await Token.getInstance().getToken();
|
|
|
|
if (token == null) return;
|
|
|
|
|
|
|
|
final baseurl = token.domain;
|
|
|
|
// todo not static middle path
|
|
|
|
final path = baseurl + "/videos/vids/" + url;
|
|
|
|
|
|
|
|
if (isDesktop()) {
|
|
|
|
final media2 = Media.network(path);
|
|
|
|
|
2022-08-25 17:48:09 +00:00
|
|
|
_player?.open(
|
2022-04-15 16:15:44 +00:00
|
|
|
media2,
|
|
|
|
autoStart: true, // default
|
|
|
|
);
|
|
|
|
} else {
|
2022-08-25 20:48:44 +00:00
|
|
|
final VideoPlayerController _controller =
|
|
|
|
VideoPlayerController.network(path);
|
2022-04-15 18:19:09 +00:00
|
|
|
await _controller.initialize();
|
|
|
|
|
|
|
|
_chewieController = ChewieController(
|
2022-08-25 20:48:44 +00:00
|
|
|
videoPlayerController: _controller,
|
|
|
|
autoPlay: true,
|
|
|
|
looping: true,
|
|
|
|
allowFullScreen: true,
|
|
|
|
allowMuting: true,
|
|
|
|
allowPlaybackSpeedChanging: true,
|
|
|
|
zoomAndPan: true);
|
2022-04-15 18:19:09 +00:00
|
|
|
|
|
|
|
setState(() {});
|
2022-04-15 16:15:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
|
2022-08-25 20:48:44 +00:00
|
|
|
if (isDesktop()) {
|
2022-04-15 19:57:15 +00:00
|
|
|
RawKeyboard.instance.addListener((value) {
|
|
|
|
if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
|
2022-08-25 20:48:44 +00:00
|
|
|
_player
|
|
|
|
?.seek(_player!.position.position! + const Duration(seconds: 5));
|
2022-04-15 19:57:15 +00:00
|
|
|
} else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) {
|
2022-08-25 20:48:44 +00:00
|
|
|
_player
|
|
|
|
?.seek(_player!.position.position! + const Duration(seconds: -5));
|
2022-04-15 19:57:15 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-04-15 16:15:44 +00:00
|
|
|
loadData();
|
|
|
|
|
|
|
|
// todo hide appbar after some seonds
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
2022-04-15 18:19:09 +00:00
|
|
|
if (isDesktop()) {
|
2022-08-25 17:48:09 +00:00
|
|
|
_player?.dispose();
|
2022-04-15 18:19:09 +00:00
|
|
|
} else {
|
|
|
|
_chewieController?.videoPlayerController.dispose();
|
|
|
|
_chewieController?.dispose();
|
|
|
|
}
|
2022-04-15 16:15:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: AppBar(
|
2022-08-25 17:48:09 +00:00
|
|
|
title: Text(widget.metaData.title),
|
2022-04-15 16:15:44 +00:00
|
|
|
),
|
2022-04-15 18:19:09 +00:00
|
|
|
body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
Widget videoDesktop() {
|
|
|
|
return Video(
|
2022-08-25 20:48:44 +00:00
|
|
|
player: _player,
|
|
|
|
scale: 1.0, // default
|
|
|
|
showControls: true);
|
2022-04-15 18:19:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
Widget videoNotDesktop() {
|
|
|
|
if (_chewieController == null) {
|
|
|
|
return Column(
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
children: const [CircularProgressIndicator(), Text("loading...")],
|
|
|
|
);
|
|
|
|
}
|
|
|
|
return Chewie(
|
|
|
|
controller: _chewieController!,
|
2022-04-15 16:15:44 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|