I have a custom C++ actor that holds a MediaPlayer and allows playback of an MP4 texture directly into the actor’s mesh material.
Up until UE5.0, in order to also have the actor playback the audio from the MP4 source, I had to attach a MediaSoundComponent to the actor that contained the MediaPlayer and assign its MediaPlayer to the MediaSoundComponent when the MediaPlayer’s OnMediaOpened event was triggered.
In UE5.1 this is no longer working for me - playback works fine if no MediaSoundComponent is created (except, of course, it does not play audio); it works fine even if I attach the MediaSoundComponent (for example on construction with CreateDefaultSubobject), it only stops working as soon as I assign the MediaPlayer to it.
I’ve tried the following:
- instantiating the MediaSoundComponent at different moments in time (constructor, beginplay, on tick when specific conditions about the MediaPlayer being ready were met, etc.)
- attaching the component in different ways (MediaSoundComponent->AttachToComponent(), ->RegisterComponent(), ->AddToRoot(), ->SetupAttachment(this))
- calling MediaSoundComponent->SetMediaPlayer() at different times
None of these fixed the issue.
I’ve noticed that, as I go through some code steps using the debugger, at certain attempts, when I hit continue play, it manages to get playback working with audio, which suggests this may be a concurrency issue?
Comparing the source code changes between 5.0 and 5.1 shows some new classes have been created, namely FMediaSoundGenerator, but after some inspection it seems like my MediaSoundComponent’s generator is always null and I don’t have any control over it (to create one myself for example).
Any insights would be much appreciated!
I’m using ElectraPlayer btw.