Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "GameFramework/Actor.h"
- #include "Components/AudioComponent.h"
- #include "AudioDecompress.h"
- #include "AudioDevice.h"
- #include "ActiveSound.h"
- #include "Audio.h"
- #include "Developer/TargetPlatform/Public/Interfaces/IAudioFormat.h"
- #include "MusicPlayerActor.generated.h"
- /**
- *
- */
- UCLASS()
- class AMusicPlayerActor : public AActor
- {
- GENERATED_UCLASS_BODY()
- //* Audio file name (OggVorbis) with path
- UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MusicPlayer)
- FString FileName;
- //* Play box collider
- TSubobjectPtr<UBoxComponent> Box_play;
- TSubobjectPtr<UPointLightComponent> light_play;
- //* Stop box collider
- TSubobjectPtr<UBoxComponent> Box_stop;
- TSubobjectPtr<UPointLightComponent> light_stop;
- //* Pause box collider
- TSubobjectPtr<UBoxComponent> Box_pause;
- TSubobjectPtr<UPointLightComponent> light_pause;
- //* manually constructed SoundWave
- USoundWave* sw;
- //* Game component used to play audio
- TSubobjectPtr<UAudioComponent> ac;
- //* loaded song file (binary, encoded)
- TArray < uint8 > rawFile;
- //* active sound object
- FActiveSound* activeSound;
- FAudioDevice* device;
- //* instance of USoundWave currently playing
- FWaveInstance* sw_instance;
- //* current sound audio source object
- FSoundSource* audioSource;
- //* If true the song was successfully loaded
- bool loaded;
- //* If true the song was manually paused by the user
- bool isPaused;
- UFUNCTION()
- void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION()
- void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION()
- void TriggerEnterPause(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION()
- void TriggerExitPause(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION()
- void TriggerEnterStop(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION()
- void TriggerExitStop(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
- UFUNCTION(BlueprintCallable, Category = "Player")
- void Load(FString NewFileName);
- UFUNCTION(BlueprintCallable, Category = "Player")
- void Stop();
- UFUNCTION(BlueprintCallable, Category = "Player")
- void Play();
- UFUNCTION(BlueprintCallable, Category = "Player")
- void Pause();
- private:
- /**
- * Print on screen Debug message.
- */
- void Debug(FString msg);
- /**
- * Read .ogg header file and refresh USoundWave metadata.
- * @param sw wave to put metadata
- * @param rawFile pointer to src file in memory
- * @return 0 if everything is ok
- * 1 if couldn't read metadata.
- */
- int fillSoundWaveInfo(USoundWave* sw, TArray<uint8>* rawFile);
- /**
- * Tries to find out FSoundSource object associated to the USoundWave.
- * @param sw wave, search key
- * @return 0 if wave found and correctly set
- * -1 if error: sound device not set
- * -2 if error: sound wave not found
- */
- int findSource(USoundWave* sw);
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement