Download

What is the proper constructor for Play/Pause of a UMediaPlayer in C++

I tried
UMediaPlayer media = new UMediaPlayer() but the constructor doesn’t seem to work.

Hi! 4nof First read this https://docs.unrealengine.com/en-us/…jects/Creation

UMediaPlayer *media = NewObject<UMediaPlayer>();
media->Play();
media->Pause();

Hope this helps!


theMediaPlayer = NewObject<UMediaPlayer>()
too few arguments in function call
*theMediaPlayer = NewObject<UMediaPlayer>()
too few arguments in function call

theMediaPlayer
0x0000000000000000 <NULL>
    UObject: <struct at NULL>
    OnEndReached: {...}
    OnMediaClosed: {...}
    OnMediaOpened: {...}
    OnMediaOpenFailed: {...}
    OnPlaybackResumed: {...}
    OnPlaybackSuspended: {...}
    OnSeekCompleted: {...}
    OnTracksChanged: {...}
    CacheAhead: Ticks = ???
    CacheBehind: Ticks = ???
    CacheBehindGame: Ticks = ???
    NativeAudioOut: <Unable to read memory>
    PlayOnOpen: <Unable to read memory>
    Shuffle: <Unable to read memory>
    Loop: <Unable to read memory>
    Playlist: <Unable to read memory>
    PlaylistIndex: <Unable to read memory>
    TimeDelay: Ticks = ???
    HorizontalFieldOfView: <Unable to read memory>
    VerticalFieldOfView: <Unable to read memory>
    ViewRotation: {Pitch=??? Yaw=??? Roll=??? }
    MediaEvent: {...}
    PlayerFacade: {...}
    PlayerGuid: {A=??? B=??? C=??? ...}
    PlayOnNext: <Unable to read memory>
    AffectedByPIEHandling: <Unable to read memory>
    WasPlayingInPIE: <Unable to read memory>


This is from my immediate window.
I think that constructor/newObject factory needs some arguments added, I’m not sure what they are though

I tested in UE 4.18.3

Hi! in file <ProjectName>.Build.cs update ~line 11



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




// MyActor.h
#include "Runtime/MediaAssets/Public/MediaPlayer.h"
// ...
private:
    UMediaPlayer *mediaPlayer;
// ...

// MyActor.cpp
// ...
void AMyActor::BeginPlay()
{
    Super::BeginPlay();
    mediaPlayer = NewObject<UMediaPlayer>();
}


Work perfect for me. No crash.

That works. I sent it to blueprints and added a media player setting there, it works now . Thanks.

Ok! Never give up!