Hello,
I’m trying to use async methods to avoid to see my game freezing when I’m loading videos (and converting them to precached media source files), or when I’m opening a video with a media player. I’m doing all this throught C++ only.
I don’t know if this is the best method though, so do not hesitate to give me hints about how to load and play multiple videos without freezing. Indeed, the loading takes time, and the media player OpenSource() method also takes time. Plus I cannot use the media player callbacks such as “OnMediaOpened”, they do not work for some reason (?!).
Currently I use a class FOpenFile : public FNonAbandonableTask to open my videos (throught the DoWork() overriden method). Then I call my callback.
But I get this warning :
Warning: ModuleManager: Attempting to
load ‘WmfMedia’ outside the main
thread. This module was already
loaded - so we didn’t crash but this
isn’t safe. Please call LoadModule on
the main/game thread only. You can
use GetModule or GetModuleChecked
instead, those are safe to call
outside the game thread.
And sometimes I also get this error (but the game doesn’t stop):
LogOutputDevice: Error: Ensure condition failed: IsInGameThread() [File:D:\Build++UE4\Sync\Engine\Source\Runtime\Core\Private\Modules\ModuleManager.cpp] [Line: 358]
What I understand is that I shouldn’t be loading the Media and WmfMedia modules in another thread than the main thread. But I don’t know how to fix my media player issue.
I found these wiki and post :
A new, community-hosted Unreal Engine Wiki - Announcements - Epic Developer Community Forums Launch Error : ImageWrapperModule was nullptr - Programming & Scripting - Epic Developer Community Forums
But I don’t really get where I should put which code to have this working properly. I tried to add this in the method (in the main thread) launching my async task :
IMediaModule& MediaModule = FModuleManager::GetModuleChecked<IMediaModule>(TEXT("Media"));
IMediaModule& WmfMediaModule = FModuleManager::GetModuleChecked<IMediaModule>(TEXT("WmfMedia"));
But nothing changes.
Is it the good way to do this ?
If it is, how to fix this warnings/errors ?
Thanks !