From 64cb2a3fcdc81dccbf9e359c955b6f886edd77ac Mon Sep 17 00:00:00 2001 From: ngfchl Date: Sat, 18 Jul 2026 17:25:20 +0800 Subject: [PATCH] fix macos embedded player initialization --- lib/widgets/media_player_dialog.dart | 19 +++++++++++++++++-- 1 file changed, 17 insertions(+), 2 deletions(-) diff --git a/lib/widgets/media_player_dialog.dart b/lib/widgets/media_player_dialog.dart index 1099f07..0f250f2 100644 --- a/lib/widgets/media_player_dialog.dart +++ b/lib/widgets/media_player_dialog.dart @@ -1,4 +1,5 @@ import 'dart:async'; +import 'dart:io' show Platform; import 'dart:math' as math; import 'package:flutter/material.dart'; @@ -66,9 +67,20 @@ class _MediaPlayerDialogState extends ConsumerState { @override void initState() { super.initState(); - _player = Player(); + _player = Player( + configuration: PlayerConfiguration(async: !Platform.isMacOS), + ); try { - _controller = VideoController(_player); + _controller = VideoController( + _player, + configuration: VideoControllerConfiguration( + // The macOS OpenGL texture backend can abort libmpv while creating + // a render context. Software textures keep the embedded player + // stable; other desktop and mobile platforms retain GPU output. + enableHardwareAcceleration: !Platform.isMacOS, + hwdec: Platform.isMacOS ? 'no' : null, + ), + ); unawaited( _controller.platform.future.then( (_) {}, @@ -102,6 +114,9 @@ class _MediaPlayerDialogState extends ConsumerState { }); } try { + // NativeVideoController applies mpv output configuration asynchronously. + // Opening only after it is ready avoids racing the render context setup. + await _controller.platform.future; final url = await ref .read(fileProvider.notifier) .playbackUrl(_currentFile);