C++ UMediaPlayer

I found others posting about this issue but no responses.

I want to use UMediaPlayer in C++. I am trying to do the following:

   static ConstructorHelpers::FClassFinder<UMediaPlayer> videoPlayerObject(TEXT("/Game/Movies"));

	UMediaPlayer* theMediaPlayer = videoPlayerObject.Class.GetDefaultObject();

I also included “MediaAssets” in the build.cs file

I am unable to call any of the functions from UMediaPlayer on theMediaPlayer variable.

You have to create an instance of the UMediaPlayer class:

auto NewMediaPlayer = NewObject<UMediaPlayer>(InParent, InClass, InName, Flags);

Make sure to stored it in a UPROPERTY field, so it doesn’t get garbage collected right away.

Read more about UObjects in the documentation.

Is your module’s *.Build.cs file missing a dependency to the MediaAssets module? What are the errors when compiling?

I tried using New Object like so:

static ConstructorHelpers::FClassFinder<UMediaPlayer> videoPlayerObject(TEXT("/Game/Movies"));


UMediaPlayer* theMediaPlayer = NewObject<UMediaPlayer>();

But same result, UMediaPlayer is still underlined in red an I cannot get any intellisense when doing “theMediaPlayer->”. I am also including it at the top of my cpp “#include “Runtime/MediaAssets/Public/MediaPlayer.h””

No I have it added in my Build.cs file. I am not getting errors when compiling.

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

Then I don’t understand question. What exactly is the problem? Does it crash at runtime? Are there any errors? What result are you expecting, and how does it differ from what you’re seeing?

Take a look at the following screenshot:

As you can see, UMediaPlayer is underlined in red and is not recognized. When I type “theMediaPlayer->” no functions are displayed. I cannot call any functions from UMediaPlayer on the pointer.

It’s almost like i am missing an include or a reference but I am including UMediaPlayer at the top and I have the MediaAssets reference in the build.cs.

Why is the question marked as answered? Its still not working :(. Please see above comment.

Is there a tooltip when you hover over the wiggly lines? What does it say?

Yeah, the site automatically marks it whenever someone posts an answer. It shows as unanswered in my browser right now.

“Identifier UMediaPlayer is not defined”

When I scroll over the red line, it says “Identifier UMediaPlayer is not defined”

Try to change your include to just

#include "MediaPlayer.h"

Intellisense might be getting confused with the relative paths. Since we changed our include logic to “include what you use” in 4.14, we don’t add the full relative path to the module anymore; only the relative path inside the module, for example:

#include "CoreTypes.h"
#include "Collections/Array.h"

Dam, that did not work either, it makes sense though. I tried doing what this person said by putting in:

PublicIncludePaths.AddRange(new string[] { "MediaAssets/Public"});

But I am still getting the error along with “Cannot open source file MediaPlayer.h”.

The include that I had originaly was

#include "Runtime/MediaAssets/Public/MediaPlayer.h"

The following should work:

PublicDependencyModuleNames.AddRange(
    new string[] {
        "MediaAssets",
    }
);

#include "MediaPlayer.h"

That didn’t do it but I found something interesting.

Even though I am getting errors saying UMediaPlayer is undefined, everything compiles and actually works!

I was able to do the following:

theMediaPlayer->Pause()

And it worked, it paused the video. But like I said, I still see the red lines and Intellisense does not work nor does syntax highlighting (acting like its undefined). But at least it functions and works programmatically :D.

I’ve never seen this behavior before and I wonder why its happening. I cleaned my cache and the rest too. Thanks again for the help!

Yeah, Intellisense doesn’t work very well. Most of us have it turned off. We use VAX instead.