90 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
		
		
			
		
	
	
			90 lines
		
	
	
		
			2.0 KiB
		
	
	
	
		
			Dart
		
	
	
	
	
	
| 
								 | 
							
								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
							 | 
						||
| 
								 | 
							
								        ),
							 | 
						||
| 
								 | 
							
								      ),
							 | 
						||
| 
								 | 
							
								    );
							 | 
						||
| 
								 | 
							
								  }
							 | 
						||
| 
								 | 
							
								}
							 |