add missing files
This commit is contained in:
22
lib/platform.dart
Normal file
22
lib/platform.dart
Normal file
@ -0,0 +1,22 @@
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
|
||||
bool _isTV = false;
|
||||
|
||||
bool isDesktop() {
|
||||
return (Platform.isLinux || Platform.isWindows || Platform.isMacOS) && !kIsWeb;
|
||||
}
|
||||
|
||||
Future<void> loadDeviceInfo() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
_isTV = androidInfo.systemFeatures.contains('android.software.leanback_only');
|
||||
}
|
||||
|
||||
bool isTV() {
|
||||
return _isTV;
|
||||
}
|
89
lib/videoscreen.dart
Normal file
89
lib/videoscreen.dart
Normal file
@ -0,0 +1,89 @@
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import "package:dart_vlc/dart_vlc.dart";
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
|
||||
import 'api/api.dart';
|
||||
import 'api/token.dart';
|
||||
import 'platform.dart';
|
||||
|
||||
class VideoScreen extends StatefulWidget {
|
||||
const VideoScreen({Key? key, required this.videoID}) : super(key: key);
|
||||
final int videoID;
|
||||
|
||||
@override
|
||||
State<VideoScreen> createState() => _VideoScreenState();
|
||||
}
|
||||
|
||||
class _VideoScreenState extends State<VideoScreen> {
|
||||
Player player = Player(id: Random().nextInt(0x7fffffff));
|
||||
|
||||
void loadData() async {
|
||||
final data = await API.query("video", "loadVideo", {'MovieId': widget.videoID});
|
||||
|
||||
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);
|
||||
|
||||
player.open(
|
||||
media2,
|
||||
autoStart: true, // default
|
||||
);
|
||||
} else {
|
||||
// todo do mobile web stuff
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
RawKeyboard.instance.addListener((value) {
|
||||
if(value.logicalKey == LogicalKeyboardKey.arrowRight){
|
||||
player.seek(player.position.position! +const Duration(seconds: 5));
|
||||
}else if(value.logicalKey == LogicalKeyboardKey.arrowLeft){
|
||||
player.seek(player.position.position! + const Duration(seconds: -5));
|
||||
}
|
||||
});
|
||||
|
||||
loadData();
|
||||
|
||||
// todo hide appbar after some seonds
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
super.dispose();
|
||||
player.pause();
|
||||
player.stop();
|
||||
player.dispose();
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Second Route'),
|
||||
),
|
||||
body: Center(
|
||||
child: Video(
|
||||
player: player,
|
||||
scale: 1.0, // default
|
||||
showControls: true,
|
||||
playlistLength: 1, // default
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user