new actor view page

fix video view overlay
This commit is contained in:
lukas-heiligenbrunner 2022-08-27 19:33:28 +02:00
parent e1be7bd5e6
commit ec66a6f4a8
7 changed files with 177 additions and 38 deletions

View File

@ -1,3 +1,5 @@
import 'dart:ui';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/log/log.dart'; import 'package:openmediacentermobile/log/log.dart';
import 'package:openmediacentermobile/login/login_screen.dart'; import 'package:openmediacentermobile/login/login_screen.dart';
@ -5,6 +7,14 @@ import 'package:openmediacentermobile/login/login_screen.dart';
import 'DrawerPage.dart'; import 'DrawerPage.dart';
import 'login/logincontext.dart'; import 'login/logincontext.dart';
class AppScrollBehavior extends MaterialScrollBehavior {
@override
Set<PointerDeviceKind> get dragDevices => {
PointerDeviceKind.touch,
PointerDeviceKind.mouse,
};
}
class App extends StatelessWidget { class App extends StatelessWidget {
const App({Key? key}) : super(key: key); const App({Key? key}) : super(key: key);
@ -17,7 +27,8 @@ class App extends StatelessWidget {
if (!loginCtx.loggedIn) { if (!loginCtx.loggedIn) {
return const MaterialApp(home: LoginScreen()); return const MaterialApp(home: LoginScreen());
} else { } else {
return const MaterialApp( return MaterialApp(
scrollBehavior: AppScrollBehavior(),
home: DrawerPage( home: DrawerPage(
title: 'OpenMediaCenter', title: 'OpenMediaCenter',
)); ));

View File

@ -4,6 +4,7 @@ import 'package:flutter/material.dart';
import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart'; import 'package:flutter_staggered_grid_view/flutter_staggered_grid_view.dart';
import 'package:openmediacentermobile/platform.dart'; import 'package:openmediacentermobile/platform.dart';
import 'package:openmediacentermobile/preview_tile.dart'; import 'package:openmediacentermobile/preview_tile.dart';
import 'package:openmediacentermobile/screen_loading.dart';
class PreviewGrid extends StatefulWidget { class PreviewGrid extends StatefulWidget {
const PreviewGrid( const PreviewGrid(
@ -49,26 +50,12 @@ class _PreviewGridState extends State<PreviewGrid> {
} else if (snapshot.hasData) { } else if (snapshot.hasData) {
return _mainGrid(snapshot.data!, width); return _mainGrid(snapshot.data!, width);
} else { } else {
return _pageLoading(); return ScreenLoading();
} }
}, },
); );
} }
Widget _pageLoading() {
return Column(children: const <Widget>[
SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting result...'),
)
]);
}
Widget _mainGrid(List<VideoT> data, double width) { Widget _mainGrid(List<VideoT> data, double width) {
return Stack( return Stack(
children: [ children: [

View File

@ -1,9 +1,9 @@
import 'dart:convert'; import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:openmediacentermobile/videoscreen_desktop.dart' import 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart'
if (dart.library.html) 'package:openmediacentermobile/videoscreen_web.dart' if (dart.library.html) 'package:openmediacentermobile/video_screen/videoscreen_web.dart'
if (dart.library.io) 'package:openmediacentermobile/videoscreen_desktop.dart'; if (dart.library.io) 'package:openmediacentermobile/video_screen/videoscreen_desktop.dart';
import 'api/api.dart'; import 'api/api.dart';
import 'platform.dart'; import 'platform.dart';

20
lib/screen_loading.dart Normal file
View File

@ -0,0 +1,20 @@
import 'package:flutter/material.dart';
class ScreenLoading extends StatelessWidget {
const ScreenLoading({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Column(children: const <Widget>[
SizedBox(
width: 60,
height: 60,
child: CircularProgressIndicator(),
),
Padding(
padding: EdgeInsets.only(top: 16),
child: Text('Awaiting result...'),
)
]);
}
}

View File

@ -0,0 +1,87 @@
import 'dart:convert';
import 'package:flutter/material.dart';
import 'package:openmediacentermobile/screen_loading.dart';
import '../api/api.dart';
class ActorView extends StatefulWidget {
const ActorView({Key? key, required this.videoId}) : super(key: key);
final int videoId;
@override
State<ActorView> createState() => _ActorViewState();
}
class _ActorViewState extends State<ActorView> {
late Future<List<Actor>> _data;
@override
void initState() {
setState(() {
_data = loadData();
});
super.initState();
}
Future<List<Actor>> loadData() async {
final data = await API
.query("actor", "getActorsOfVideo", {'MovieId': widget.videoId});
if (data == 'null') {
return [];
}
final d = jsonDecode(data);
List<Actor> dta = (d as List).map((e) => Actor.fromJson(e)).toList();
return dta;
}
@override
Widget build(BuildContext context) {
return FutureBuilder(
future: _data,
builder: (context, AsyncSnapshot<List<Actor>> snapshot) {
if (snapshot.hasError) {
return Text("Error");
} else if (snapshot.hasData) {
final actors = snapshot.data;
if (actors?.isEmpty ?? true) {
return Text("no actors available");
} else {
return Column(children: _renderActors(snapshot.data!));
}
} else {
return ScreenLoading();
}
},
);
}
List<Widget> _renderActors(List<Actor> actors) {
return actors
.map((e) => Text(
e.name,
style: TextStyle(color: Colors.black),
))
.toList(growable: false);
}
}
class Actor {
int actorId;
String name;
String thumbnail;
Actor(this.actorId, this.name, this.thumbnail);
factory Actor.fromJson(dynamic json) {
return Actor(json['ActorId'] as int, json['Name'] as String,
json['Thumbnail'] as String);
}
@override
String toString() {
return 'Actor{ActorId: $actorId, Name: $name, Thumbnail: $thumbnail}';
}
}

View File

@ -7,12 +7,12 @@ import "package:dart_vlc/dart_vlc.dart";
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart'; import 'package:flutter/services.dart';
import 'package:openmediacentermobile/preview_tile.dart'; import 'package:openmediacentermobile/preview_tile.dart';
import 'package:openmediacentermobile/video_screen/actor_view.dart';
import 'package:video_player/video_player.dart'; import 'package:video_player/video_player.dart';
import 'api/api.dart'; import '../api/api.dart';
import 'api/token.dart'; import '../api/token.dart';
import 'log/log.dart'; import '../platform.dart';
import 'platform.dart';
class VideoScreen extends StatefulWidget { class VideoScreen extends StatefulWidget {
const VideoScreen({Key? key, required this.metaData}) : super(key: key); const VideoScreen({Key? key, required this.metaData}) : super(key: key);
@ -23,14 +23,16 @@ class VideoScreen extends StatefulWidget {
} }
class _VideoScreenState extends State<VideoScreen> { class _VideoScreenState extends State<VideoScreen> {
Player? _player = isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null; Player? _player =
isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
ChewieController? _chewieController; ChewieController? _chewieController;
bool _appBarVisible = true; bool _appBarVisible = true;
Timer? _appBarTimer; Timer? _appBarTimer;
void loadData() async { void loadData() async {
final data = await API.query("video", "loadVideo", {'MovieId': widget.metaData.id}); final data =
await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
final d = jsonDecode(data); final d = jsonDecode(data);
@ -50,7 +52,8 @@ class _VideoScreenState extends State<VideoScreen> {
autoStart: true, // default autoStart: true, // default
); );
} else { } else {
final VideoPlayerController _controller = VideoPlayerController.network(path); final VideoPlayerController _controller =
VideoPlayerController.network(path);
await _controller.initialize(); await _controller.initialize();
_chewieController = ChewieController( _chewieController = ChewieController(
@ -73,9 +76,11 @@ class _VideoScreenState extends State<VideoScreen> {
if (isDesktop()) { if (isDesktop()) {
RawKeyboard.instance.addListener((value) { RawKeyboard.instance.addListener((value) {
if (value.logicalKey == LogicalKeyboardKey.arrowRight) { if (value.logicalKey == LogicalKeyboardKey.arrowRight) {
_player?.seek(_player!.position.position! + const Duration(seconds: 5)); _player
?.seek(_player!.position.position! + const Duration(seconds: 5));
} else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) { } else if (value.logicalKey == LogicalKeyboardKey.arrowLeft) {
_player?.seek(_player!.position.position! + const Duration(seconds: -5)); _player
?.seek(_player!.position.position! + const Duration(seconds: -5));
} }
}); });
} }
@ -86,13 +91,15 @@ class _VideoScreenState extends State<VideoScreen> {
@override @override
void dispose() { void dispose() {
super.dispose();
if (isDesktop()) { if (isDesktop()) {
_player?.dispose(); _player?.dispose();
} else { } else {
_chewieController?.videoPlayerController.dispose(); _chewieController?.videoPlayerController.dispose();
_chewieController?.dispose(); _chewieController?.dispose();
} }
_controller.dispose();
_appBarTimer?.cancel();
super.dispose();
} }
void _setAppBarTimer() { void _setAppBarTimer() {
@ -107,12 +114,13 @@ class _VideoScreenState extends State<VideoScreen> {
); );
} }
PageController _controller = PageController(
initialPage: 0,
);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Scaffold( return Scaffold(
extendBody: true,
extendBodyBehindAppBar: true,
appBar: _appBarVisible ? AppBar(title: Text(widget.metaData.title)) : null,
body: MouseRegion( body: MouseRegion(
onHover: (PointerEvent event) { onHover: (PointerEvent event) {
if (event.delta.dx != 0 || event.delta.dy != 0) { if (event.delta.dx != 0 || event.delta.dy != 0) {
@ -122,7 +130,33 @@ class _VideoScreenState extends State<VideoScreen> {
_setAppBarTimer(); _setAppBarTimer();
} }
}, },
child: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()), child: Stack(children: [
PageView(
scrollDirection: Axis.vertical,
controller: _controller,
children: [
Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()),
ActorView(
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: () => Navigator.of(context).pop(),
),
backgroundColor:
Theme.of(context).primaryColor.withOpacity(0.3),
elevation: 0.0,
),
),
]),
), ),
); );
} }

View File

@ -2,9 +2,9 @@ import 'dart:convert';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'api/api.dart'; import '../api/api.dart';
import 'api/token.dart'; import '../api/token.dart';
import 'log/log.dart'; import '../log/log.dart';
class VideoScreen extends StatefulWidget { class VideoScreen extends StatefulWidget {
const VideoScreen({Key? key, required this.videoID}) : super(key: key); const VideoScreen({Key? key, required this.videoID}) : super(key: key);