Added VideoPlayerWidget.LoadAndPlayAsync method

Previous commits removed the async loading of videos, which can be a problem for videos played in the radar widget mid-game because it can cause a lag spike. This loads the video on a separate thread and runs it on the main thread whenever it is loaded, not blocking the main thread meanwhile and allowing the game to continue while the video loads.
Also add back cancelling of already playing video and add a check to not try to run onComplete if it is null.
This commit is contained in:
penev92
2023-02-02 22:54:20 +02:00
committed by abcdefg30
parent c3fcbf77ed
commit 2c51e791ad
2 changed files with 56 additions and 17 deletions

View File

@@ -62,22 +62,7 @@ namespace OpenRA.Mods.Common.Scripting
public static void PlayFMVInRadar(string videoFileName, Action onComplete)
{
var player = Ui.Root.Get<VideoPlayerWidget>("PLAYER");
try
{
player.LoadAndPlay(videoFileName);
}
catch (FileNotFoundException)
{
onComplete();
return;
}
player.PlayThen(() =>
{
onComplete();
player.CloseVideo();
});
player.LoadAndPlayAsync(videoFileName, onComplete);
}
}
}