I’m working on a MediaPlayer Widget to play videos in UMG. Playing videos works fine, but
// Fill out your copyright notice in the Description page of Project Settings.
#pragma once
#include "Blueprint/UserWidget.h"
#include "Components/Image.h"
#include "Components/SizeBox.h"
#include "CoreMinimal.h"
#include "Math/UnrealMathUtility.h"
// Media Assets
#include "FileMediaSource.h"
#include "MediaPlayer.h"
#include "MediaTexture.h"
// clang-format off
#include "MediaWidget.generated.h"
UCLASS()
class MYLIBRARY_API UMediaWidget : public UUserWidget
{
GENERATED_BODY()
public:
UMediaWidget(const FObjectInitializer& Object);
UFUNCTION(BlueprintCallable)
void setFilePath(FString filepath);
UFUNCTION(BlueprintCallable)
void playVideo();
UFUNCTION(BlueprintCallable)
void pauseVideo();
UFUNCTION(BlueprintCallable)
void togglePlayVideo();
UFUNCTION(BlueprintCallable)
void stopVideo();
UFUNCTION(BlueprintCallable)
void setLooping(bool isLooping);
protected:
void NativeConstruct();
void createMediaPlayer(FString FilePath);
UMediaTexture* createMediaTexture(UMediaPlayer * mMediaPlayer);
void createImageFromMediaTexture(UMediaTexture* mediaTexture);
UMaterial* mSourceMaterial;
bool mIsMediaPlaying = false;
UPROPERTY(BlueprintReadWrite);
UMediaPlayer* mMediaPlayer;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
UImage* mMediaImage;
UPROPERTY(EditAnywhere, BlueprintReadWrite, meta = (BindWidget))
USizeBox* mMediaSizeBox;
};
When I try set the looping:
void UMediaWidget::setLooping(bool isLooping) {
if (mMediaPlayer != nullptr) {
mMediaPlayer->SetLooping(isLooping);
} else {
UE_LOG(LogTemp, Warning, TEXT("mMediaPlayer is null"));
}
}
the video doesn’t loop in UMG, it only plays once. This seems pretty simple, so I’m not sure what the issue is – does anyone know of the issue here? Do I need to set looping on the UMediaSource
isntead?