// Oleg Petruny staff

#pragma once

#include "CoreMinimal.h"
#include "Sound/SoundBase.h"
#include "UObject/Object.h"
#include "AsyncLibrary.h"
#include "AudioDevice.h"
#include "Kismet/GameplayStatics.h"
#include "AudioPlayerAsync.generated.h"

UCLASS(Blueprintable, BlueprintType)
class LOST_EDGE_API UAudioPlayerAsync : public UObject {
	GENERATED_BODY()

private:
	USoundBase *Sound;
	float volume;
	float pitch;
	float startTime;
	FDateTime startStamp;
	UAsyncLibrary *asyncer;

public:
	UAudioPlayerAsync() {
		//PlayerWork.BindRaw();
	}
	UAudioPlayerAsync(USoundBase *Sound, float startTime, UAsyncLibrary *asyncer) {
		this->Sound = Sound;
		this->startTime = startTime;
		this->asyncer = asyncer;
	}
	
	UFUNCTION(BlueprintNativeEvent, Category = "Audio Player")
		void workAsync();

	UFUNCTION(BlueprintCallable, Category = "Audio Player")
	static void CreateAudioPlayerAsync(USoundBase *Sound, FCallbackDelegate EndCallback, UAudioPlayerAsync *&playerReference, float volume = 1.0f, float pitch = 1.0f, float startTime = 0.0f, int loops = 1);
	UFUNCTION(BlueprintCallable, Category = "Audio Player")
	void StartAudioPlayerAsync();
	UFUNCTION(BlueprintCallable, Category = "Audio Player")
	void StopAudioPlayerAsync();
	UFUNCTION(BlueprintPure, Category = "Audio Player")
	float GetActualPlayTimeAsync();

};
