Skip to content

Instantly share code, notes, and snippets.

@zr0n
Created February 13, 2025 20:28
Show Gist options
  • Save zr0n/346de8c00d17c64264af9de77470d3b6 to your computer and use it in GitHub Desktop.
Save zr0n/346de8c00d17c64264af9de77470d3b6 to your computer and use it in GitHub Desktop.
Play And Pause Cosm Test.cpp
IMPLEMENT_SIMPLE_AUTOMATION_TEST(FCxEnvPropVideoPlayAndPauseTest, "Plugins.CXProRuntimeCore.VideoCore.EnvPropVideo.Play", EAutomationTestFlags::EditorContext | EAutomationTestFlags::ProductFilter)
bool FCxEnvPropVideoPlayAndPauseTest::RunTest(const FString& Parameters)
{
// Test setting the environment property for Volume
{
UWorld* World = nullptr;
UTestGameInstance* GameInstance = nullptr;
CXTestHelper::InitWorldAndGameInstance(World, GameInstance);
if (!TestEqual("World should be valid", !!World, true))
{
return false;
}
if (!TestEqual("Game Instance should be valid", !!GameInstance, true))
{
return false;
}
// Preparing the scene
AEnvPropActor* EnvPropActor = CXTestHelper::InitEnvPropActor(World);
if (!TestEqual("EnvPropActor should be valid", !!EnvPropActor, true))
{
return false;
}
UEnvPropVideo* EnvPropVideo = CXTestHelper::InitEnvPropVideo(EnvPropActor);
if (!TestEqual("EnvPropVideo should be valid", !!EnvPropVideo, true))
{
return false;
}
// Setup video url
auto EnvPropSystem = World->GetGameInstance()->GetSubsystem<UEnvironmentPropertiesSubsystem>();
FString RelativeVideoPath = TEXT("Content/Assets/Videos/CXRC_VideoColorTest_4k_60fps.mp4");
FString AbsoluteVideoPath = FPaths::ConvertRelativePathToFull(FPaths::ProjectDir(), RelativeVideoPath);
FString DataJson = FString::Printf(TEXT("{\"Video::Immersive.MediaPath\": \"%s\", \"Video::Immersive.MediaType\": \"VideoOnDemand\"}"), *AbsoluteVideoPath);
EnvPropSystem->LoadDataFromJson(DataJson);
EnvPropVideo->DataUpdated("Video", "Immersive");
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(1.0f));
while (EnvPropVideo->VideoDelegate->GetMediaPlayerState().State != "Playing")
{
if (EnvPropVideo->VideoDelegate->GetMediaPlayerState().State == "Error")
{
UE_LOG(LogClass, Error, TEXT("Error opening the media file"));
return false;
}
UE_LOG(LogClass, Error, TEXT("Waiting media to load."));
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(1.f));
}
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(3.0f));
// Wait for 3 seconds and check if video is playing
UE_LOG(LogClass, Error, TEXT("PlaybackTime 1: %.2f"), EnvPropVideo->VideoDelegate->GetMediaPlayerState().PlaybackTime.GetTotalSeconds());
if (!TestTrue("The video should be playing for a minimum duration", EnvPropVideo->VideoDelegate->GetMediaPlayerState().PlaybackTime >= .1f))
{
return false;
}
const FTimespan PreviousPlaybackTime = EnvPropVideo->VideoDelegate->GetMediaPlayerState().PlaybackTime;
// Pause Video
EnvPropVideo->VideoDelegate->SetPauseVideo(true);
ADD_LATENT_AUTOMATION_COMMAND(FWaitLatentCommand(3.0f));
UE_LOG(LogClass, Error, TEXT("PlaybackTime 2: %.2f"), EnvPropVideo->VideoDelegate->GetMediaPlayerState().PlaybackTime.GetTotalSeconds());
// Wait for 3 seconds and check if video is still paused
if (!TestTrue("The video should be paused for 3 seconds", EnvPropVideo->VideoDelegate->GetMediaPlayerState().PlaybackTime.GetTotalSeconds() == PreviousPlaybackTime.GetTotalSeconds()))
{
return false;
}
// Cleanup
GameInstance->Shutdown();
}
return true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment