C++ UMediaTexture is not showing UMediaPlayer Frames when playing a UStreamMediaSource

As the title already describes, I’m trying to play a video from URL and use the frames in a material.

Here the code I use to load and play the video:

VideoTexture = NewObject<UMediaTexture>(this);
VideoTexture->AddToRoot();
VideoSource = NewObject<UStreamMediaSource>(this);
VideoSource->AddToRoot();
VideoPlayer = NewObject<UMediaPlayer>(this);
VideoPlayer->AddToRoot();

// Link the Video Texture to the Media Player
VideoTexture->SetDefaultMediaPlayer(VideoPlayer);
VideoTexture->SetMediaPlayer(VideoPlayer);


VideoSource->StreamUrl = VideoURL;
VideoPlayer->SetLooping(true);
VideoPlayer->OpenSource(VideoSource);
VideoPlayer->PlayOnOpen = true;
VideoPlayer->Play();

SetDynamicTexture(VideoTexture); // Adds the texture to the dynamic material

For VideoURL I use a demo .mp4 video. When I just create the video player using blueprints (the usual way), the video is playing.
Using C++ the video also seems to get played, since I can observe how its first buffering (print string) and then having the “IsPlaying” status.
But the Texture just stays black all the time.
For sure it compiles without any error or warning.

It seems like the UMediaPlayer frames get not written to the UMediaTexture when I instanciate it like in the code above, so I can have multiple independed instance of it in my level.
Did I miss somthing?

I appreciate any help, thanks in advance!

Best Regards

Robin

For anyone that arrives here in the future, you need to call VideoTexture->UpdateResource()

This is my code:

UMediaPlayer* MediaPlayer = NewObject<UMediaPlayer>(this);
MediaPlayer->OpenUrl(Url);
MediaPlayer->AddToRoot();

UMediaTexture* MediaTexture = NewObject<UMediaTexture>(this);
MediaTexture->SetMediaPlayer(MediaPlayer);
MediaTexture->UpdateResource();
MediaTexture->AddToRoot();

MediaPlayer->Play();
1 Like