Skip to content

Commit cdc5dd2

Browse files
committed
Add auto play
1 parent 16c2a5e commit cdc5dd2

2 files changed

Lines changed: 19 additions & 6 deletions

File tree

Source/RuntimeImageLoader/Private/RuntimeGifReader.cpp

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,13 @@
1010
DEFINE_LOG_CATEGORY(RuntimeGifReader);
1111

1212

13-
URuntimeGifReader* URuntimeGifReader::LoadGIF(const FString& GIFFilename, TEnumAsByte<enum TextureFilter> InFilterMode, bool bSynchronous)
13+
URuntimeGifReader* URuntimeGifReader::LoadGIF(const FString& GIFFilename, TEnumAsByte<enum TextureFilter> InFilterMode, bool bAutoPlay, bool bSynchronous)
1414
{
1515
FGifReadRequest Request;
1616
{
1717
Request.InputGif.ImageFilename = GIFFilename;
1818
Request.FilterMode = InFilterMode;
19+
Request.bAutoPlay = bAutoPlay;
1920
}
2021

2122
URuntimeGifReader* GifReader = NewObject<URuntimeGifReader>();
@@ -24,12 +25,13 @@ URuntimeGifReader* URuntimeGifReader::LoadGIF(const FString& GIFFilename, TEnumA
2425
return GifReader;
2526
}
2627

27-
URuntimeGifReader* URuntimeGifReader::LoadGIFFromBytes(TArray<uint8>& GifBytes, TEnumAsByte<enum TextureFilter> InFilterMode, bool bSynchronous)
28+
URuntimeGifReader* URuntimeGifReader::LoadGIFFromBytes(TArray<uint8>& GifBytes, TEnumAsByte<enum TextureFilter> InFilterMode, bool bAutoPlay, bool bSynchronous)
2829
{
2930
FGifReadRequest Request;
3031
{
3132
Request.InputGif.ImageBytes = MoveTemp(GifBytes);
3233
Request.FilterMode = InFilterMode;
34+
Request.bAutoPlay = bAutoPlay;
3335
}
3436

3537
URuntimeGifReader* GifReader = NewObject<URuntimeGifReader>();
@@ -161,8 +163,16 @@ void URuntimeGifReader::CreateTextureOnGameThread(int32 Width, int32 Height, con
161163
ReadResult.OutTexture->SRGB = true;
162164
ReadResult.OutTexture->UpdateResource();
163165

164-
// Auto-start playback
165-
ReadResult.OutTexture->PlayFromStart();
166+
// Auto-start playback if enabled
167+
if (Request.bAutoPlay)
168+
{
169+
ReadResult.OutTexture->PlayFromStart();
170+
UE_LOG(RuntimeGifReader, Log, TEXT("CreateTextureOnGameThread: Auto-play enabled, started playback"));
171+
}
172+
else
173+
{
174+
UE_LOG(RuntimeGifReader, Log, TEXT("CreateTextureOnGameThread: Auto-play disabled. Call Play() or PlayFromStart() on the texture to start playback."));
175+
}
166176

167177
UE_LOG(RuntimeGifReader, Log, TEXT("CreateTextureOnGameThread: Complete. Texture ready, bPlaying=%d"),
168178
ReadResult.OutTexture->IsPlaying());

Source/RuntimeImageLoader/Public/RuntimeGifReader.h

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ struct RUNTIMEIMAGELOADER_API FGifReadRequest
2121
{
2222
FInputImageDescription InputGif;
2323
TEnumAsByte<TextureFilter> FilterMode = TextureFilter::TF_Default;
24+
25+
/** If true, the GIF will automatically start playing after loading. Default is true. */
26+
bool bAutoPlay = true;
2427
};
2528

2629
USTRUCT()
@@ -44,10 +47,10 @@ class RUNTIMEIMAGELOADER_API URuntimeGifReader : public UBlueprintAsyncActionBas
4447
public:
4548
/** GIF */
4649
UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true"), Category = "Runtime Gif Reader")
47-
static URuntimeGifReader* LoadGIF(const FString& GIFFilename, TEnumAsByte<enum TextureFilter> InFilterMode = TextureFilter::TF_Trilinear, bool bSynchronous = false);
50+
static URuntimeGifReader* LoadGIF(const FString& GIFFilename, TEnumAsByte<enum TextureFilter> InFilterMode = TextureFilter::TF_Trilinear, bool bAutoPlay = true, bool bSynchronous = false);
4851

4952
UFUNCTION(BlueprintCallable, meta = (BlueprintInternalUseOnly = "true"), Category = "Runtime Gif Reader")
50-
static URuntimeGifReader* LoadGIFFromBytes(UPARAM(ref) TArray<uint8>& GifBytes, TEnumAsByte<enum TextureFilter> InFilterMode = TextureFilter::TF_Trilinear, bool bSynchronous = false);
53+
static URuntimeGifReader* LoadGIFFromBytes(UPARAM(ref) TArray<uint8>& GifBytes, TEnumAsByte<enum TextureFilter> InFilterMode = TextureFilter::TF_Trilinear, bool bAutoPlay = true, bool bSynchronous = false);
5154

5255
public:
5356
// Bind to these events when you want to use async API from C++

0 commit comments

Comments
 (0)