MediaPlayer->OpenUrl fails

Hi All,

I am observing that OpenUrl fails always. I have tried keeping the file inside Blueprints->Movies of my project folder, on desktop etc, but it always fails. Please help.

The mesh is not obtained as null and on printing the url is obtained as “C:\Users\100365\Documents\Unreal Projects\UI_explore\Content\StarterContent\Blueprints\Movies\t1.wmv”

The code I am using is given below:

UMediaPlayer * m_mediaPlayer = ConstructObject<UMediaPlayer>(UMediaPlayer::StaticClass());

if (m_mediaPlayer != NULL)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:m_mediaPlayer successfully created!"));
}
else
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:m_mediaPlayer creation failed!"));
}

UMediaTexture * m_mediaTexture = ConstructObject<UMediaTexture>(UMediaTexture::StaticClass());

if (m_mediaTexture != NULL)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:m_mediaTexture successfully created!"));
}
else
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:m_mediaTexture creation failed!"));
}

m_mediaPlayer->SetLooping(false);

m_mediaTexture->SetMediaPlayer(m_mediaPlayer);

//add the media texture to the mesh
UStaticMeshComponent * mesh = AAMyActorExtendingClass::GetMyWall();

if (mesh != NULL)
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:mesh successfully created!"));
}
else
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:mesh creation failed!"));
}


UMaterialInstanceDynamic  * material = mesh->CreateDynamicMaterialInstance(0);
material->SetTextureParameterValue("Video", m_mediaTexture);
mesh->SetMaterial(0, material);

GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, FString::Printf(TEXT("Play_MediaTexture: url name: %s"), *url));

if (m_mediaPlayer->OpenUrl(url))
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:OpenUrl success!"));
}
else
{
	GEngine->AddOnScreenDebugMessage(-1, 5.f, FColor::Red, TEXT("Play_MediaTexture:OpenUrl failed!"));
}
m_mediaPlayer->Rewind();
m_mediaPlayer->Play();

Is this when running from the Editor or when running the packaged game?

Please note that movies currently have to be in the /Content/Movies directory, so in your case that would be C:\Users\100365\Documents\Unreal Projects\UI_explore\Content\Movies. Otherwise the movies will not get packaged and your game won’t be able to find it at run-time.

Let me know if that fixes it, thanks!

Hi,

I was able to play the movie from \Content\Movies. I had read somewhere that this issue was there only in older versions of ue4 and it has been fixed. Can’t movies be played from some other location when running the game?

Thanks for your help.

Hi,

I had one more query. When I apply the material to a cube or a wall, I see that the video is played through all faces of the cube. How can I get it to play on only one face of the cube? Please help.

/Content/Movies is still a requirement for now. The content cooker doesn’t know about any other locations for the time being.

As for the cube, you will have to give it more than one material slot in your 3D editing tool and UV map one of the slots to the desired surface. If you built the cube using the BSP tools in the Editor, then I don’t think there is a way to do that with just a single cube. You could try to compose the cube out of two cubes or simply use a sheet brush. I’m not an expert with BSP though - there may be better ways to accomplish this :slight_smile: