View Issue Details

IDProjectCategoryView StatusLast Update
0002416NoesisGUIUnrealpublic2022-09-14 19:30
Reporterjsantos Assigned Tohcpizzi  
PrioritynormalSeveritymajorReproducibilityalways
Status resolvedResolutionfixed 
Product Version3.1.5 
Target Version3.1.6Fixed in Version3.1.6 
Summary0002416: Video issues in Unreal Engine 5
DescriptionPlaying video in Unreal Engine 5 renders black content on consoles.

Also, it seems video looping is failing in all platforms.
TagsNo tags attached.
PlatformAny

Activities

sfernandez

sfernandez

2022-09-14 19:29

manager   ~0008071

Fixed in revisions 11603 and 11604, find patch attached below.

sfernandez

sfernandez

2022-09-14 19:30

manager   ~0008072

Issue-2416.patch (5,993 bytes)   
Index: Native/Src/Packages/App/MediaElement/Src/MediaElement.cpp
===================================================================
--- Native/Src/Packages/App/MediaElement/Src/MediaElement.cpp	(revision 11602)
+++ Native/Src/Packages/App/MediaElement/Src/MediaElement.cpp	(revision 11604)
@@ -454,13 +454,6 @@
 
         if (mPlayer != nullptr)
         {
-            mPlayer->SetVolume(GetVolume());
-            mPlayer->SetBalance(GetBalance());
-            mPlayer->SetIsMuted(GetIsMuted());
-            mPlayer->SetScrubbingEnabled(GetScrubbingEnabled());
-            mPlayer->SetPosition(mPosition.GetSeconds());
-            mPlayer->SetSpeedRatio(mSpeedRatio);
-
             mPlayer->BufferingStarted() += MakeDelegate(this, &MediaElement::OnBufferingStarted);
             mPlayer->BufferingEnded() += MakeDelegate(this, &MediaElement::OnBufferingEnded);
             mPlayer->MediaOpened() += MakeDelegate(this, &MediaElement::OnMediaOpened);
@@ -529,6 +522,13 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 void MediaElement::OnMediaOpened()
 {
+    mPlayer->SetVolume(GetVolume());
+    mPlayer->SetBalance(GetBalance());
+    mPlayer->SetIsMuted(GetIsMuted());
+    mPlayer->SetScrubbingEnabled(GetScrubbingEnabled());
+    mPlayer->SetPosition(mPosition.GetSeconds());
+    mPlayer->SetSpeedRatio(mSpeedRatio);
+
     mTextureSource.Reset(mPlayer->GetTextureSource());
     if (mTextureSource != nullptr)
     {
Index: Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.cpp
===================================================================
--- Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.cpp	(revision 11602)
+++ Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.cpp	(revision 11604)
@@ -39,12 +39,10 @@
 ////////////////////////////////////////////////////////////////////////////////////////////////////
 NoesisMediaPlayer::NoesisMediaPlayer(NoesisApp::MediaElement* Owner, const Noesis::Uri& Uri, void*):
 	MediaPlayer(nullptr), MediaTexture(nullptr), MediaTextureRHI(nullptr), SoundComponent(nullptr),
-	TextureSource(*new Noesis::TextureSource()), View(nullptr), Volume(0.5f),
+	TextureSource(*new Noesis::TextureSource()), View(nullptr), Volume(0.5f), Position(0.0),
 	Opened(false), Ended(false), KeepPlaying(false), IsBuffering(false)
 {
 	MediaPlayer = NewObject<UMediaPlayer>(GetTransientPackage(), NAME_None, RF_Transient | RF_Public);
-	// Enable looping so texture resource is not discarded when media ends
-	MediaPlayer->SetLooping(true);
 	MediaPlayer->AddToRoot();
 
 	MediaTexture = NewObject<UMediaTexture>(GetTransientPackage(), NAME_None, RF_Transient | RF_Public);
@@ -219,7 +217,6 @@
 void NoesisMediaPlayer::Play()
 {
 	KeepPlaying = true;
-	MediaPlayer->Play();
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -226,7 +223,6 @@
 void NoesisMediaPlayer::Pause()
 {
 	KeepPlaying = false;
-	MediaPlayer->Pause();
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
@@ -233,7 +229,6 @@
 void NoesisMediaPlayer::Stop()
 {
 	KeepPlaying = false;
-	MediaPlayer->Pause();
 	MediaPlayer->Rewind();
 }
 
@@ -244,16 +239,6 @@
 }
 
 ////////////////////////////////////////////////////////////////////////////////////////////////////
-void NoesisMediaPlayer::CheckKeepPlaying()
-{
-	if (!KeepPlaying)
-	{
-		Stop();
-	}
-	KeepPlaying = false;
-}
-
-////////////////////////////////////////////////////////////////////////////////////////////////////
 static FRHITexture* GetMediaTextureRHI(UMediaTexture* MediaTexture)
 {
 #if UE_VERSION_OLDER_THAN(4, 27, 0)
@@ -277,23 +262,40 @@
 		TextureSource->SetTexture(FNoesisRenderDevice::CreateTexture(MediaTexture));
 	}
 
+	// Raise MediaOpened when texture is correctly created
 	if (Opened && MediaTexture->GetWidth() > 2 && MediaTexture->GetHeight() > 2)
 	{
-		MediaPlayer->SetRate(Rate);
-		MediaPlayer->Seek(FTimespan::FromSeconds(Position));
+		// Some platforms need looping to be enabled in order to work correctly:
+		// Windows: The texture resource is discarded when the media ends.
+		// PS4/5: sceAvPlayerStop is called when the media ends, leaving the player in an unrecoverable state.
+		// Some platforms need looping to be disabled in order to work correctly:
+		// Switch: It never sends the PlaybackEndReached if set to looping.
+		bool NeedsLooping = FCStringAnsi::Strcmp(FPlatformProperties::IniPlatformName(), "Switch") != 0;
 
+		// Set here instead of constructor because some implementations ignore it if MediaOpened is not called
+		MediaPlayer->SetLooping(NeedsLooping);
+
 		mMediaOpened();
-
 		Opened = false;
-		CheckKeepPlaying();
 	}
 
+	// Raise MediaEnded
 	if (Ended)
 	{
+		mMediaEnded();
 		Ended = false;
-		CheckKeepPlaying();
 	}
 
+	// Check if we need to continue playing or player has been paused/stopped
+	if (KeepPlaying)
+	{
+		MediaPlayer->Play();
+	}
+	else
+	{
+		MediaPlayer->Pause();
+	}
+
 	if (SoundComponent != nullptr)
 	{
 		SoundComponent->UpdatePlayer();
@@ -332,7 +334,6 @@
 		case EMediaEvent::PlaybackEndReached:
 		{
 			Ended = true;
-			mMediaEnded();
 			break;
 		}
 		case EMediaEvent::PlaybackResumed:
Index: Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.h
===================================================================
--- Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.h	(revision 11602)
+++ Unreal/Plugins/NoesisGUI/Source/NoesisRuntime/Private/NoesisMediaPlayer.h	(revision 11604)
@@ -55,7 +55,6 @@
 	Noesis::ImageSource* GetTextureSource() const override;
 
 private:
-	void CheckKeepPlaying();
 	void OnRendering(Noesis::IView* View);
 	void OnMediaEvent(EMediaEvent Event);
 
Issue-2416.patch (5,993 bytes)   

Issue History

Date Modified Username Field Change
2022-09-12 16:17 jsantos New Issue
2022-09-12 16:17 jsantos Assigned To => hcpizzi
2022-09-12 16:17 jsantos Status new => assigned
2022-09-12 16:17 jsantos Target Version => 3.1.6
2022-09-12 16:19 jsantos Description Updated
2022-09-14 19:29 sfernandez Status assigned => resolved
2022-09-14 19:29 sfernandez Resolution open => fixed
2022-09-14 19:29 sfernandez Fixed in Version => 3.1.6
2022-09-14 19:29 sfernandez Note Added: 0008071
2022-09-14 19:30 sfernandez Note Added: 0008072
2022-09-14 19:30 sfernandez File Added: Issue-2416.patch