add android support

This commit is contained in:
lukas 2022-04-15 20:19:09 +02:00
parent 77a5c52c3a
commit 0fce95faa0
6 changed files with 246 additions and 42 deletions

View File

@ -10,8 +10,9 @@ import 'platform.dart';
// main app entry point
void main() async {
Log.i("App init!");
if (isDesktop()) {
DartVLC.initialize();
if (isDesktop()) {
} else {
await loadDeviceInfo();
}

View File

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

View File

@ -0,0 +1,123 @@
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:video_player/video_player.dart';
import 'api/api.dart';
import 'api/token.dart';
import 'log/log.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> {
late Player player;
ChewieController? _chewieController;
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()) {
player = Player(id: Random().nextInt(0x7fffffff));
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,
);
setState(() {});
}
}
@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();
if (isDesktop()) {
player.pause();
player.stop();
player.dispose();
} else {
_chewieController?.videoPlayerController.dispose();
_chewieController?.dispose();
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Second Route'),
),
body: Center(child: isDesktop() ? videoDesktop() : videoNotDesktop()),
);
}
Widget videoDesktop() {
return Video(
player: player,
scale: 1.0, // default
showControls: true,
playlistLength: 1, // default
);
}
Widget videoNotDesktop() {
if (_chewieController == null) {
return Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.center,
children: const [CircularProgressIndicator(), Text("loading...")],
);
}
return Chewie(
controller: _chewieController!,
);
}
}

View File

@ -1,13 +1,9 @@
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);
@ -18,8 +14,6 @@ class VideoScreen extends StatefulWidget {
}
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});
@ -33,56 +27,25 @@ class _VideoScreenState extends State<VideoScreen> {
// 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
),
body: const Center(
child: Text("Todo to implement")
),
);
}

View File

@ -36,6 +36,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.1"
chewie:
dependency: "direct main"
description:
name: chewie
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.2"
clock:
dependency: transitive
description:
@ -50,6 +57,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.15.0"
csslib:
dependency: transitive
description:
name: csslib
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.1"
cupertino_icons:
dependency: "direct main"
description:
@ -205,6 +219,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
html:
dependency: transitive
description:
name: html
url: "https://pub.dartlang.org"
source: hosted
version: "0.15.0"
http:
dependency: "direct main"
description:
@ -261,6 +282,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.7.0"
nested:
dependency: transitive
description:
name: nested
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.0"
path:
dependency: transitive
description:
@ -330,7 +358,7 @@ packages:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.2"
process:
dependency: transitive
description:
@ -338,6 +366,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "4.2.4"
provider:
dependency: transitive
description:
name: provider
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.2"
sky_engine:
dependency: transitive
description: flutter
@ -399,6 +434,83 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
very_good_analysis:
dependency: transitive
description:
name: very_good_analysis
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
video_player:
dependency: "direct main"
description:
name: video_player
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.0"
video_player_android:
dependency: transitive
description:
name: video_player_android
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.2"
video_player_avfoundation:
dependency: transitive
description:
name: video_player_avfoundation
url: "https://pub.dartlang.org"
source: hosted
version: "2.3.1"
video_player_platform_interface:
dependency: transitive
description:
name: video_player_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "5.1.1"
video_player_web:
dependency: transitive
description:
name: video_player_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.7"
wakelock:
dependency: transitive
description:
name: wakelock
url: "https://pub.dartlang.org"
source: hosted
version: "0.6.1+2"
wakelock_macos:
dependency: transitive
description:
name: wakelock_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
wakelock_platform_interface:
dependency: transitive
description:
name: wakelock_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "0.3.0"
wakelock_web:
dependency: transitive
description:
name: wakelock_web
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.0"
wakelock_windows:
dependency: transitive
description:
name: wakelock_windows
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.0"
win32:
dependency: transitive
description:

View File

@ -40,6 +40,8 @@ dependencies:
flutter_staggered_grid_view: ^0.6.1
dart_vlc: ^0.1.9
device_info_plus: ^3.2.3
video_player: ^2.3.0
chewie: ^1.3.2
dev_dependencies:
flutter_test: