Playing multiple videos

Hi, it is me again.

In our level we have a hall with a lot of screens that play videos.
Creating one of these is fine, all you need is a BP, mediaplayer, mediasource, material, mediatexture.

Now the problem is, this would have to be repeated about 100 times.
just changing the mediasource doesn’t change the video played, we have to create duplicates of all listed components. Is that how it’s supposed to work or are we missing something?

Why are mediaplayers connected to mediatextures? Shouldn’t it be the other way around?

Is there a way (in blueprints style) to make procedural mediatextures, materials and mediaplayers for every screen?

In you begin play

in header includes

#include "MediaTexture.h" 
#include "MediaPlayer.h" 
#include "StreamMediaSource.h" 
#include "MediaPlayerFacade.h" 
#include "Engine/Texture2DDynamic.h" 

in header needed uproperties



	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UMediaTexture* VideoTexture;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UStreamMediaSource* VideoSource;

	UPROPERTY(EditAnywhere, BlueprintReadWrite)
		UMediaPlayer* VideoPlayer;


cpp

void AMyClass::BeginPlay()
{
	Super::BeginPlay();

	VideoPlayer = NewObject<UMediaPlayer>();
	VideoPlayer->SetLooping(true);

	VideoTexture = NewObject<UMediaTexture>();
	VideoTexture->SetDefaultMediaPlayer(VideoPlayer);
	VideoTexture->SetMediaPlayer(VideoPlayer);
	VideoTexture->UpdateResource();


}

1 Like

Thank you, that is what I was looking for.

I subbed the c++ code for a little more blueprint, I hope I did it correctly.

I enabled the base color of the source material to be exposed (and named it RT).
Unfortunately, the video does not play.

I verified that the open source function and play function both returned true.
I also verified that the instanced material changes according to created exposed attributes.

Any clue what might be wrong?

Does your M_VideoScreen material have the correct parameter?

Here is my material where I use the paramter RT as the target

Also media Texture & media player are made in the c++ beginplay?

Not sure why you are constucting media player though
it is being made in the begin play.

If you want the code for media texture Code in c++

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

You can also call MediaPlayer->Play();

Also try using open source latent to only play once the source is done preparing.

1 Like

My parameter looks like this


The default value of it is a media texture, one that will be overwritten by another in that begin play event.

I’m not using the c++, I find it easier to just use the construct function in the blueprint, it should do the exact same thing.

I just realized “update Resource” is what I needed to add before set Material.

Thanks again, the videos now play.
Now, on to paste 100 of these video players and lag the game.

Yes, with update resources it works, here are my nodes for copy and paste: