From bddd4e78fed39877c2b72db25aa258c6c0ce2977 Mon Sep 17 00:00:00 2001 From: Foxocube Date: Wed, 1 Jan 2025 18:26:50 +0000 Subject: [PATCH] Fix YT API loading --- .../Providers/Youtube/YouTubeVideoFrame.razor.cs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/MediaFeeder/MediaFeeder/Providers/Youtube/YouTubeVideoFrame.razor.cs b/MediaFeeder/MediaFeeder/Providers/Youtube/YouTubeVideoFrame.razor.cs index 0623ce6..0379d78 100644 --- a/MediaFeeder/MediaFeeder/Providers/Youtube/YouTubeVideoFrame.razor.cs +++ b/MediaFeeder/MediaFeeder/Providers/Youtube/YouTubeVideoFrame.razor.cs @@ -10,20 +10,12 @@ public sealed partial class YouTubeVideoFrame private IJSObjectReference? _player; private DotNetObjectReference? _videoFrameRef; - protected override async Task OnAfterRenderAsync(bool firstRender) - { - if (firstRender) - { - _youtubeLibraryModule = await JsRuntime.InvokeAsync("import", "/iframe_api.js"); - _youtubeCustomModule = await JsRuntime.InvokeAsync("import", "./Providers/Youtube/YouTubeVideoFrame.razor.js"); - } - } - protected override async Task OnParametersSetAsync() { - if (_player == null && Video != null && _youtubeCustomModule != null) + if (_player == null && Video != null) { - ArgumentNullException.ThrowIfNull(_youtubeCustomModule); + _youtubeLibraryModule ??= await JsRuntime.InvokeAsync("import", "/iframe_api.js"); + _youtubeCustomModule ??= await JsRuntime.InvokeAsync("import", "./Providers/Youtube/YouTubeVideoFrame.razor.js"); _videoFrameRef ??= DotNetObjectReference.Create(this); _player = await _youtubeCustomModule.InvokeAsync("initPlayer", _videoFrameRef, Video.VideoId);