new actor view page
fix video view overlay
This commit is contained in:
87
lib/video_screen/actor_view.dart
Normal file
87
lib/video_screen/actor_view.dart
Normal 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}';
|
||||
}
|
||||
}
|
185
lib/video_screen/videoscreen_desktop.dart
Normal file
185
lib/video_screen/videoscreen_desktop.dart
Normal file
@ -0,0 +1,185 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:math';
|
||||
|
||||
import 'package:chewie/chewie.dart';
|
||||
import "package:dart_vlc/dart_vlc.dart";
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:openmediacentermobile/preview_tile.dart';
|
||||
import 'package:openmediacentermobile/video_screen/actor_view.dart';
|
||||
import 'package:video_player/video_player.dart';
|
||||
|
||||
import '../api/api.dart';
|
||||
import '../api/token.dart';
|
||||
import '../platform.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> {
|
||||
Player? _player =
|
||||
isDesktop() ? Player(id: Random().nextInt(0x7fffffff)) : null;
|
||||
ChewieController? _chewieController;
|
||||
|
||||
bool _appBarVisible = true;
|
||||
Timer? _appBarTimer;
|
||||
|
||||
void loadData() async {
|
||||
final data =
|
||||
await API.query("video", "loadVideo", {'MovieId': widget.metaData.id});
|
||||
|
||||
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 {
|
||||
final VideoPlayerController _controller =
|
||||
VideoPlayerController.network(path);
|
||||
await _controller.initialize();
|
||||
|
||||
_chewieController = ChewieController(
|
||||
videoPlayerController: _controller,
|
||||
autoPlay: true,
|
||||
looping: true,
|
||||
allowFullScreen: true,
|
||||
allowMuting: true,
|
||||
allowPlaybackSpeedChanging: true,
|
||||
zoomAndPan: true);
|
||||
|
||||
setState(() {});
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
if (isDesktop()) {
|
||||
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();
|
||||
_setAppBarTimer();
|
||||
}
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
if (isDesktop()) {
|
||||
_player?.dispose();
|
||||
} else {
|
||||
_chewieController?.videoPlayerController.dispose();
|
||||
_chewieController?.dispose();
|
||||
}
|
||||
_controller.dispose();
|
||||
_appBarTimer?.cancel();
|
||||
super.dispose();
|
||||
}
|
||||
|
||||
void _setAppBarTimer() {
|
||||
_appBarTimer?.cancel();
|
||||
_appBarTimer = Timer(
|
||||
Duration(seconds: 3),
|
||||
() {
|
||||
setState(() {
|
||||
_appBarVisible = false;
|
||||
});
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
PageController _controller = PageController(
|
||||
initialPage: 0,
|
||||
);
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
body: MouseRegion(
|
||||
onHover: (PointerEvent event) {
|
||||
if (event.delta.dx != 0 || event.delta.dy != 0) {
|
||||
setState(() {
|
||||
_appBarVisible = true;
|
||||
});
|
||||
_setAppBarTimer();
|
||||
}
|
||||
},
|
||||
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,
|
||||
),
|
||||
),
|
||||
]),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget videoDesktop() {
|
||||
return Video(
|
||||
player: _player,
|
||||
scale: 1.0, // default
|
||||
showControls: true,
|
||||
playlistLength: 1,
|
||||
);
|
||||
}
|
||||
|
||||
Widget videoNotDesktop() {
|
||||
if (_chewieController == null) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: const [CircularProgressIndicator(), Text("loading...")],
|
||||
);
|
||||
}
|
||||
return Chewie(
|
||||
controller: _chewieController!,
|
||||
);
|
||||
}
|
||||
}
|
52
lib/video_screen/videoscreen_web.dart
Normal file
52
lib/video_screen/videoscreen_web.dart
Normal file
@ -0,0 +1,52 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import '../api/api.dart';
|
||||
import '../api/token.dart';
|
||||
import '../log/log.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> {
|
||||
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 String path = baseurl + "/videos/vids/" + url;
|
||||
Log.d(path);
|
||||
}
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
|
||||
loadData();
|
||||
|
||||
// todo hide appbar after some seonds
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text('Second Route'),
|
||||
),
|
||||
body: const Center(child: Text("Todo to implement")),
|
||||
);
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user