Skip to content

基于自定义规则的番剧采集APP,支持流媒体在线观看,支持弹幕,支持实时超分辨率。

fix: fix webview parser log

Predidit9d08af74f452
diff --git a/lib/pages/video/video_controller.dart b/lib/pages/video/video_controller.dart
index 39f8e89c..42a522f2 100644
--- a/lib/pages/video/video_controller.dart
+++ b/lib/pages/video/video_controller.dart
@@ -1,3 +1,4 @@
+import 'dart:async';
import 'package:kazumi/modules/roads/road_module.dart';
import 'package:kazumi/plugins/plugins_controller.dart';
import 'package:flutter_modular/flutter_modular.dart';
@@ -93,6 +94,14 @@ abstract class _VideoPageController with Store {
/// 长生命周期的视频源提供者(页面生命周期内复用,WebView 实例在 Provider 内复用)
WebViewVideoSourceProvider? _videoSourceProvider;
+ /// 视频提供者日志流控制器
+ final StreamController<String> _logStreamController =
+ StreamController<String>.broadcast();
+
+ Stream<String> get logStream => _logStreamController.stream;
+
+ StreamSubscription<String>? _logSubscription;
+
/// 初始化离线播放模式
void initForOfflinePlayback({
required BangumiItem bangumiItem,
@@ -240,6 +249,13 @@ abstract class _VideoPageController with Store {
loading = true;
_videoSourceProvider ??= WebViewVideoSourceProvider();
+ await _logSubscription?.cancel();
+ _logSubscription = _videoSourceProvider!.onLog.listen((log) {
+ if (!_logStreamController.isClosed) {
+ _logStreamController.add(log);
+ }
+ });
+
try {
final source = await _videoSourceProvider!.resolve(
url,
@@ -287,6 +303,11 @@ abstract class _VideoPageController with Store {
/// 取消当前视频源解析并销毁 Provider(页面退出时调用)
void cancelVideoSourceResolution() {
+ _logSubscription?.cancel();
+ _logSubscription = null;
+ if (!_logStreamController.isClosed) {
+ _logStreamController.close();
+ }
_videoSourceProvider?.dispose();
_videoSourceProvider = null;
}
diff --git a/lib/pages/video/video_page.dart b/lib/pages/video/video_page.dart
index 1e63fdf4..75279fe1 100644
--- a/lib/pages/video/video_page.dart
+++ b/lib/pages/video/video_page.dart
@@ -42,6 +42,7 @@ class _VideoPageState extends State<VideoPage>
late bool playResume;
bool showDebugLog = false;
List<String> webviewLogLines = [];
+ StreamSubscription<String>? _logSubscription;
final FocusNode keyboardFocus = FocusNode();
ScrollController scrollController = ScrollController();
@@ -180,6 +181,17 @@ class _VideoPageState extends State<VideoPage>
}
currentRoad = videoPageController.currentRoad;
+ _logSubscription = videoPageController.logStream.listen((log) {
+ if (mounted) {
+ setState(() {
+ webviewLogLines.add(log);
+ if (webviewLogLines.length > 100) {
+ webviewLogLines.removeAt(0);
+ }
+ });
+ }
+ });
+
// 使用 Provider 模式启动播放
WidgetsBinding.instance.addPostFrameCallback((_) {
changeEpisode(videoPageController.currentEpisode,
@@ -202,6 +214,9 @@ class _VideoPageState extends State<VideoPage>
try {
_syncChatSubscription.cancel();
} catch (_) {}
+ try {
+ _logSubscription?.cancel();
+ } catch (_) {}
try {
playerController.dispose();
} catch (e) {
diff --git a/lib/providers/webview_video_source_provider.dart b/lib/providers/webview_video_source_provider.dart
index 69f5e6ba..3f02fe33 100644
--- a/lib/providers/webview_video_source_provider.dart
+++ b/lib/providers/webview_video_source_provider.dart
@@ -11,9 +11,14 @@ import 'package:kazumi/providers/video_source_provider.dart';
class WebViewVideoSourceProvider implements IVideoSourceProvider {
WebviewItemController? _webview;
StreamSubscription? _subscription;
+ StreamSubscription? _logSubscription;
Completer<VideoSource>? _completer;
bool _isCancelled = false;
+ final StreamController<String> _logController =
+ StreamController<String>.broadcast();
+ Stream<String> get onLog => _logController.stream;
+
@override
Future<VideoSource> resolve(
String episodeUrl, {
@@ -29,6 +34,12 @@ class WebViewVideoSourceProvider implements IVideoSourceProvider {
if (_webview == null) {
_webview = WebviewItemControllerFactory.getController();
await _webview!.init();
+
+ _logSubscription = _webview!.onLog.listen((log) {
+ if (!_logController.isClosed) {
+ _logController.add(log);
+ }
+ });
}
if (_isCancelled) {
@@ -99,6 +110,9 @@ class WebViewVideoSourceProvider implements IVideoSourceProvider {
@override
void dispose() {
_cancelCurrentResolve();
+ _logSubscription?.cancel();
+ _logSubscription = null;
+ _logController.close();
_webview?.dispose();
_webview = null;
}