fix: preserve start position and subtitles in ExoPlayer→MPV fallback

This commit is contained in:
edde746
2026-03-15 11:32:25 +01:00
parent 360c3356cf
commit 0100b2a2ea
6 changed files with 44 additions and 27 deletions
+10
View File
@@ -162,6 +162,16 @@ abstract class Player {
/// [args] - Command and arguments as a list of strings.
Future<void> command(List<String> args);
// ============================================
// Subtitle Fonts
// ============================================
/// Configure subtitle fonts for libass rendering.
///
/// Extracts a comprehensive Unicode font (Go Noto) to the cache directory
/// and sets `sub-fonts-dir` and `sub-font` properties.
Future<void> configureSubtitleFonts();
// ============================================
// Passthrough Mode (Audio)
// ============================================
+23
View File
@@ -5,6 +5,7 @@ import 'package:flutter/foundation.dart' show protected;
import 'package:flutter/services.dart';
import '../../utils/app_logger.dart';
import '../font_loader.dart';
import '../models.dart';
import 'player.dart';
import 'player_state.dart';
@@ -550,6 +551,28 @@ abstract class PlayerBase with PlayerStreamControllersMixin implements Player {
// ignore: no-empty-block - base no-op, overridden by platform subclasses
Future<void> setLogLevel(String level) async {}
// ============================================
// Subtitle Fonts
// ============================================
@override
Future<void> configureSubtitleFonts() async {
try {
final fontDir = await SubtitleFontLoader.loadSubtitleFont();
if (fontDir != null) {
await setProperty('sub-fonts-dir', fontDir);
await setProperty('sub-font', SubtitleFontLoader.fontName);
}
} catch (e) {
// Font configuration is not critical - continue without it
logController.add(PlayerLog(
prefix: 'fonts',
level: PlayerLogLevel.warn,
text: 'Failed to configure subtitle fonts: $e',
));
}
}
// ============================================
// Lifecycle
// ============================================
-22
View File
@@ -2,7 +2,6 @@ import 'dart:io' show Platform;
import 'package:flutter/services.dart';
import '../font_loader.dart';
import '../models.dart';
import '../../utils/app_logger.dart';
import 'player_base.dart';
@@ -55,9 +54,6 @@ class PlayerNative extends PlayerBase {
throw Exception('Failed to initialize player');
}
// Configure subtitle fonts for libass support
await _configureSubtitleFonts();
// Subscribe to MPV properties
await observeProperty('time-pos', 'double');
await observeProperty('duration', 'double');
@@ -80,24 +76,6 @@ class PlayerNative extends PlayerBase {
}
}
/// Configures subtitle fonts for libass support.
/// Provides a comprehensive Unicode font (Go Noto) with CJK coverage to ensure
/// proper rendering of non-Latin characters in subtitles.
Future<void> _configureSubtitleFonts() async {
try {
final fontDir = await SubtitleFontLoader.loadSubtitleFont();
if (fontDir != null) {
// Configure MPV to use the extracted font for libass
await setProperty('config', 'yes');
await setProperty('sub-fonts-dir', fontDir);
await setProperty('sub-font', SubtitleFontLoader.fontName);
}
} catch (e) {
// Font configuration is not critical - continue without it
errorController.add('Failed to configure subtitle fonts: $e');
}
}
// ============================================
// Playback Control
// ============================================
+1
View File
@@ -413,6 +413,7 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
// Create player (on Android, uses ExoPlayer by default, MPV as fallback)
player = Player(useExoPlayer: useExoPlayer);
await player!.configureSubtitleFonts();
await player!.setProperty('sub-ass', 'yes'); // Enable libass
if (Platform.isAndroid && useExoPlayer) {
final tunneledPlayback = settingsService.getTunneledPlayback();