Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: torrent playback error when bt-server is not installed #82

Merged
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions lib/pages/detail/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class DetailPageController extends GetxController {
// 判断是否有 key
if (MiruStorage.getSetting(SettingKey.tmdbKay) == "") {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: 'detail.tmdb-key-missing'.i18n,
severity: fluent.InfoBarSeverity.error,
);
Expand All @@ -165,7 +165,7 @@ class DetailPageController extends GetxController {
));
} else {
data = await fluent.showDialog(
context: cuurentContext,
context: currentContext,
builder: (context) => TMDBBinding(title: detail!.title),
);
}
Expand Down Expand Up @@ -198,21 +198,21 @@ class DetailPageController extends GetxController {
// 弹出错误信息
if (runtime.value == null) {
final content = FlutterI18n.translate(
cuurentContext,
currentContext,
'common.extension-missing',
translationParams: {
'package': package,
},
);
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: content,
severity: fluent.InfoBarSeverity.error,
);
throw content;
} else {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
title: 'detail.get-lastest-data-error'.i18n,
content: e.toString().split('\n')[0],
severity: fluent.InfoBarSeverity.error,
Expand Down Expand Up @@ -293,7 +293,7 @@ class DetailPageController extends GetxController {
);
} catch (e) {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: e.toString().split('\n')[0],
severity: fluent.InfoBarSeverity.error,
);
Expand All @@ -311,9 +311,9 @@ class DetailPageController extends GetxController {
) async {
if (runtime.value == null) {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: FlutterI18n.translate(
cuurentContext,
currentContext,
'common.extension-missing',
translationParams: {
'package': package,
Expand All @@ -329,9 +329,9 @@ class DetailPageController extends GetxController {

if (player != 'built-in') {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: FlutterI18n.translate(
cuurentContext,
currentContext,
'external-player-launching',
translationParams: {
'player': player,
Expand All @@ -344,7 +344,7 @@ class DetailPageController extends GetxController {
as ExtensionBangumiWatch;
} catch (e) {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: e.toString().split('\n')[0],
severity: fluent.InfoBarSeverity.error,
);
Expand All @@ -359,7 +359,7 @@ class DetailPageController extends GetxController {
return;
} catch (e) {
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: e.toString().split('\n')[0],
severity: fluent.InfoBarSeverity.error,
);
Expand Down
2 changes: 1 addition & 1 deletion lib/pages/extension_repo/controller.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ExtensionRepoPageController extends GetxController {
if (Platform.isAndroid && extensions.isEmpty) {
// ignore: use_build_context_synchronously
showPlatformSnackbar(
context: cuurentContext,
context: currentContext,
content: 'extension-repo.empty'.i18n,
);
}
Expand Down
36 changes: 33 additions & 3 deletions lib/pages/watch/video_controller.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
// ignore_for_file: use_build_context_synchronously

import 'dart:async';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:dio/dio.dart';
import 'package:file_picker/file_picker.dart';
import 'package:fluent_ui/fluent_ui.dart';
import 'package:flutter/services.dart';
import 'package:flutter_i18n/flutter_i18n.dart';
import 'package:get/get.dart';
import 'package:media_kit/media_kit.dart';
import 'package:media_kit_video/media_kit_video.dart';
import 'package:miru_app/api/bt_server.dart';
import 'package:miru_app/models/index.dart';
import 'package:miru_app/pages/bt_dialog/view.dart';
import 'package:miru_app/pages/home/controller.dart';
import 'package:miru_app/pages/main/controller.dart';
import 'package:miru_app/router/router.dart';
Expand All @@ -22,6 +25,7 @@ import 'package:miru_app/utils/layout.dart';
import 'package:miru_app/utils/miru_directory.dart';
import 'package:window_manager/window_manager.dart';
import 'package:path/path.dart' as path;
import 'package:fluent_ui/fluent_ui.dart' as fluent;

class VideoPlayerController extends GetxController {
final String title;
Expand Down Expand Up @@ -64,6 +68,8 @@ class VideoPlayerController extends GetxController {

String _torrenHash = "";

// 复制当前 context

@override
void onInit() {
if (Platform.isAndroid) {
Expand Down Expand Up @@ -115,7 +121,7 @@ class VideoPlayerController extends GetxController {
Message(
Text(
FlutterI18n.translate(
cuurentContext,
currentContext,
"video.subtitle-change",
translationParams: {"title": value.files.first.name},
),
Expand All @@ -132,7 +138,7 @@ class VideoPlayerController extends GetxController {
Message(
Text(
FlutterI18n.translate(
cuurentContext,
currentContext,
"video.subtitle-change",
translationParams: {"title": subtitles[callback].title},
),
Expand Down Expand Up @@ -182,6 +188,11 @@ class VideoPlayerController extends GetxController {
}

play() async {
// 如果已经 delete 当前 controller
if (!Get.isRegistered<VideoPlayerController>(tag: title)) {
return;
}

try {
subtitles.clear();
selectedSubtitle.value = -1;
Expand Down Expand Up @@ -231,6 +242,25 @@ class VideoPlayerController extends GetxController {
}
subtitles.addAll(watchData.subtitles ?? []);
} catch (e) {
if (e is StartServerException) {
if (Platform.isAndroid) {
await showDialog(
context: currentContext,
builder: (context) => const BTDialog(),
);
} else {
await fluent.showDialog(
context: currentContext,
builder: (context) => const BTDialog(),
);
}

// 延时 3 秒再重试
await Future.delayed(const Duration(seconds: 3));

play();
return;
}
sendMessage(
Message(
Text(e.toString()),
Expand Down
2 changes: 1 addition & 1 deletion lib/router/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import 'package:miru_app/pages/settings/view.dart';
final rootNavigatorKey = GlobalKey<NavigatorState>();
final _shellNavigatorKey = GlobalKey<NavigatorState>();

BuildContext get cuurentContext {
BuildContext get currentContext {
if (Platform.isAndroid) {
return Get.context!;
}
Expand Down
11 changes: 10 additions & 1 deletion lib/utils/bt_server.dart
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class BTServerUtils {
Get.find<BTDialogController>().isInstalled.value = false;
}
}
rethrow;
throw StartServerException('Start bt-server failed');
}
checkServer();
}
Expand Down Expand Up @@ -157,3 +157,12 @@ class BTServerUtils {
return "btserver";
}
}

class StartServerException implements Exception {
final String message;
StartServerException(this.message);
@override
String toString() {
return message;
}
}
4 changes: 2 additions & 2 deletions lib/utils/layout.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ class LayoutUtils {

// 获取当前宽度
static double get getWidth {
return MediaQuery.of(cuurentContext).size.width;
return MediaQuery.of(currentContext).size.width;
}

// 获取当前高度
static double get getHeight {
return MediaQuery.of(cuurentContext).size.height;
return MediaQuery.of(currentContext).size.height;
}

// 是否是平板
Expand Down