fix: COMMAND_FAILED error on videos with external subtitles

This commit is contained in:
edde746
2026-01-27 16:16:16 +01:00
parent 9ea8f637cd
commit 06d69a5fce
2 changed files with 9 additions and 3 deletions
+5 -1
View File
@@ -814,7 +814,11 @@ class VideoPlayerScreenState extends State<VideoPlayerScreen> with WidgetsBindin
if (player != null && mounted) {
await player!.play();
final pos = player!.state.position;
await player!.seek(pos.inMilliseconds > 0 ? pos : Duration.zero);
try {
await player!.seek(pos.inMilliseconds > 0 ? pos : Duration.zero);
} catch (e) {
appLogger.w('Non-critical seek after subtitle load failed', error: e);
}
// Fallback if playbackRestart doesn't fire
Future.delayed(const Duration(seconds: 3), () {
+4 -2
View File
@@ -208,9 +208,11 @@ void MpvPlayerPlugin::HandleMethodCall(
// Use async command to prevent UI blocking during network operations
// Move result into shared_ptr for safe capture in callback
auto result_ptr = std::make_shared<std::unique_ptr<flutter::MethodResult<flutter::EncodableValue>>>(std::move(result));
player_->CommandAsync(command_args, [result_ptr](int error) {
std::string cmd_name = command_args.empty() ? "unknown" : command_args[0];
player_->CommandAsync(command_args, [result_ptr, cmd_name](int error) {
if (error < 0) {
(*result_ptr)->Error("COMMAND_FAILED", "MPV command failed");
(*result_ptr)->Error("COMMAND_FAILED",
"MPV command failed: " + cmd_name + " (error " + std::to_string(error) + ")");
} else {
(*result_ptr)->Success();
}