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);