From fc8d89a404581bfb3e48d41d6509e2427779cd1d Mon Sep 17 00:00:00 2001 From: KenwoodFox Date: Wed, 11 Mar 2026 01:12:28 -0400 Subject: [PATCH] This fixes the issue for me but might not be the right solution, after setVisible i 'think' mpv gets called too early and before drawing we get that 'no render context set' if we wrap a promise around scheduling just one frame it holds it and seems to work for me, since the context is ready by the time it continies. Maybe that wait could be integrated into the setvisible? --- lib/mpv/player/player_native.dart | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/lib/mpv/player/player_native.dart b/lib/mpv/player/player_native.dart index 96fb3506..eceaafcf 100644 --- a/lib/mpv/player/player_native.dart +++ b/lib/mpv/player/player_native.dart @@ -1,5 +1,7 @@ +import 'dart:async'; import 'dart:io' show Platform; +import 'package:flutter/widgets.dart'; import 'package:flutter/services.dart'; import '../models.dart'; @@ -99,6 +101,14 @@ class PlayerNative extends PlayerBase { // Show the video layer await setVisible(true); + // Linux: wait one frame so texture populate() runs and creates MPV render context before loadfile. + if (Platform.isLinux) { + WidgetsBinding.instance.scheduleFrame(); + final c = Completer(); + WidgetsBinding.instance.addPostFrameCallback((_) => c.complete()); + await c.future; + } + // Set HTTP headers for Plex authentication and profile if (media.headers != null && media.headers!.isNotEmpty) { final headerList = media.headers!.entries.map((e) => '${e.key}: ${e.value}').toList();