Skip to content

Commit

Permalink
feat: video player achieved full torrent support
Browse files Browse the repository at this point in the history
  • Loading branch information
K3vinb5 committed Sep 12, 2024
1 parent 055b003 commit 2e2afb1
Show file tree
Hide file tree
Showing 12 changed files with 212 additions and 121 deletions.
28 changes: 20 additions & 8 deletions lib/screens/video_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:flutter_acrylic/window.dart';
import 'package:loading_animation_widget/loading_animation_widget.dart';
import 'package:unyo/dialogs/dialogs.dart';
import 'package:unyo/util/utils.dart';
import 'package:unyo/widgets/video/m_video_player.dart' as my;
import 'package:unyo/widgets/video/m_video_player.dart';
import 'package:unyo/widgets/widgets.dart';
// import 'package:video_player/video_player.dart';

Expand Down Expand Up @@ -40,7 +40,7 @@ class VideoScreen extends StatefulWidget {
class _VideoScreenState extends State<VideoScreen> {
late MixedController _mixedController;
Timer? _hideControlsTimer;
late Timer isVideoPlaying;
Timer? isVideoPlaying;
bool _showControls = true;
bool paused = false;
String? captions;
Expand All @@ -60,6 +60,7 @@ class _VideoScreenState extends State<VideoScreen> {
source: widget.source,
episode: widget.episode,
updateEntry: widget.updateEntry,
cancelTimers: cancelTimers,
resetHideControlsTimer: _resetHideControlsTimer,
controlsOverlayOnTap: controlsOverlayOnTap,
);
Expand All @@ -74,10 +75,15 @@ class _VideoScreenState extends State<VideoScreen> {

@override
void dispose() {
super.dispose();
_hideControlsTimer?.cancel();
isVideoPlaying?.cancel();
_mixedController.dispose();
isVideoPlaying.cancel();
super.dispose();
}

void cancelTimers() {
_hideControlsTimer?.cancel();
isVideoPlaying?.cancel();
}

String getUtf8Text(String text) {
Expand Down Expand Up @@ -123,6 +129,9 @@ class _VideoScreenState extends State<VideoScreen> {
exception:
"An error occured, try using another source or server/quality",
onPressedAfterPop: () {
if (!_mixedController.canDispose) return;
_hideControlsTimer?.cancel();
isVideoPlaying?.cancel();
_mixedController.dispose();
Window.exitFullscreen();
interactScreen(false);
Expand Down Expand Up @@ -158,6 +167,7 @@ class _VideoScreenState extends State<VideoScreen> {
children: [
MouseRegion(
onHover: (event) {
// print("hover");
_resetHideControlsTimer();
},
cursor: _showControls
Expand All @@ -168,11 +178,12 @@ class _VideoScreenState extends State<VideoScreen> {
alignment: Alignment.center,
children: [
if (widget.streamData.tracks != null)
my.VideoPlayer(_mixedController.audioController),
VideoPlayer(_mixedController.audioController),
AspectRatio(
aspectRatio: 16 / 9,
child: my.VideoPlayer(
_mixedController.videoController)),
aspectRatio: 16 / 9,
child:
VideoPlayer(_mixedController.videoController),
),
VideoSubtitles(mixedController: _mixedController),
//Overlay controls, and slider
StyledVideoPlaybackControls(
Expand Down Expand Up @@ -212,6 +223,7 @@ class _VideoScreenState extends State<VideoScreen> {
showControls: _showControls,
title: widget.title,
mixedController: _mixedController,
cancelTimers: cancelTimers,
updateEntry: widget.updateEntry),
!fullScreen
? const WindowBarButtons(startIgnoreWidth: 70)
Expand Down
4 changes: 2 additions & 2 deletions lib/sources/anime/embedded_anime_source.dart
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ class EmbeddedAnimeSource implements AnimeSource {
TrackData(file: e.split(";")[0], lang: e.split(";")[1]))
.toList())
.toList()
: null;
: null;

List<dynamic>? headersKeysResponse = jsonResponse["headersKeys"] != "null"
? jsonResponse["headersKeys"]
Expand Down Expand Up @@ -101,7 +101,7 @@ class EmbeddedAnimeSource implements AnimeSource {
headersValues: headersValues,
);
}

@override
Future<List<List<String>>> getAnimeTitlesAndIds(String query) async {
var urlStream = Uri.parse(
Expand Down
4 changes: 4 additions & 0 deletions lib/util/data/caption_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@ class CaptionData {
CaptionData({
required this.file,
required this.lang,
this.embedded,
this.index,
});

final String file;
final String lang;
final bool? embedded;
final int? index;
}
6 changes: 3 additions & 3 deletions lib/util/data/stream_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ class StreamData {
StreamData.empy({
this.streams = const [],
this.qualities = const [],
this.captions,
this.captions = const [],
this.tracks,
this.headersKeys = const [],
this.headersValues = const [],
});

final List<String> streams;
final List<String> qualities;
final List<List<CaptionData>>? captions;
final List<List<TrackData>>? tracks;
final List<List<CaptionData>> captions;
List<List<TrackData>>? tracks;
final List<List<String>> headersKeys;
final List<List<String>> headersValues;

Expand Down
4 changes: 3 additions & 1 deletion lib/util/data/track_data.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
class TrackData {
TrackData({required this.file, required this.lang});
TrackData({required this.file, required this.lang, this.embedded, this.index});

final String file;
final String lang;
final bool? embedded;
final int? index;
}
Loading

0 comments on commit 2e2afb1

Please sign in to comment.