Why can't I import the MediaPlayer.h in my class

I have a very simple class that extends the UUserWidget class. I have a MediaPlayer variable that I’m trying to reference in my C++ class. I’ve created the UPROPERTY with meta = (BindWidget) so that it will grab a reverence to it.

In my cpp file I have the following code.

#include “ELVideoWidget.h”
#include “MediaPlayer.h”
#include “Components/Button.h”

void UELVideoWidget::NativeConstruct() 
{
    Super::NativeConstruct();
     
    MediaPlayer->OpenFile(FString(TEXT("G:/My Drive/_Video/examplevideo.mp4")));
}

When I compile in the editor I get the following error.

Cannot open include file: "MediaPlayer.h' : No such file or director

I’ve also tried “Runtime/MediaAssets/Public/MediaPlayer.h” and other variations of this file path and I get the same results.

The issue was, that you need to include the MediaAssets module in your *.Build.cs file.

PublicDependencyModuleNames.AddRange(new string[] { "Core", "CoreUObject", "Engine", "InputCore", "MediaAssets" });

1 Like