Advertisement
Guest User

Unreal Engine MusicPlayerActor.h

a guest
Jul 16th, 2014
911
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.09 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "GameFramework/Actor.h"
  4. #include "Components/AudioComponent.h"
  5. #include "AudioDecompress.h"
  6. #include "AudioDevice.h"
  7. #include "ActiveSound.h"
  8. #include "Audio.h"
  9. #include "Developer/TargetPlatform/Public/Interfaces/IAudioFormat.h"
  10.  
  11. #include "MusicPlayerActor.generated.h"
  12.  
  13. /**
  14. *
  15. */
  16. UCLASS()
  17. class AMusicPlayerActor : public AActor
  18. {
  19.     GENERATED_UCLASS_BODY()
  20.  
  21.     //* Audio file name (OggVorbis) with path
  22.     UPROPERTY(EditAnywhere, BlueprintReadWrite, Category = MusicPlayer)
  23.         FString FileName;
  24.  
  25.     //* Play box collider
  26.     TSubobjectPtr<UBoxComponent> Box_play;
  27.     TSubobjectPtr<UPointLightComponent> light_play;
  28.     //* Stop box collider
  29.     TSubobjectPtr<UBoxComponent> Box_stop;
  30.     TSubobjectPtr<UPointLightComponent> light_stop;
  31.     //* Pause box collider
  32.     TSubobjectPtr<UBoxComponent> Box_pause;
  33.     TSubobjectPtr<UPointLightComponent> light_pause;
  34.  
  35.     //* manually constructed SoundWave
  36.     USoundWave* sw;
  37.     //* Game component used to play audio
  38.     TSubobjectPtr<UAudioComponent> ac;
  39.     //* loaded song file (binary, encoded)
  40.     TArray < uint8 > rawFile;
  41.  
  42.     //* active sound object
  43.     FActiveSound* activeSound;
  44.     FAudioDevice* device;
  45.     //* instance of USoundWave currently playing
  46.     FWaveInstance* sw_instance;
  47.     //* current sound audio source object
  48.     FSoundSource* audioSource;
  49.  
  50.     //* If true the song was successfully loaded
  51.     bool loaded;
  52.     //* If true the song was manually paused by the user
  53.     bool isPaused;
  54.  
  55.     UFUNCTION()
  56.         void TriggerEnter(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  57.     UFUNCTION()
  58.         void TriggerExit(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  59.     UFUNCTION()
  60.         void TriggerEnterPause(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  61.     UFUNCTION()
  62.         void TriggerExitPause(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  63.     UFUNCTION()
  64.         void TriggerEnterStop(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  65.     UFUNCTION()
  66.         void TriggerExitStop(class AActor* OtherActor, class UPrimitiveComponent* OtherComp, int32 OtherBodyIndex);
  67.  
  68.     UFUNCTION(BlueprintCallable, Category = "Player")
  69.         void Load(FString NewFileName);
  70.     UFUNCTION(BlueprintCallable, Category = "Player")
  71.         void Stop();
  72.     UFUNCTION(BlueprintCallable, Category = "Player")
  73.         void Play();
  74.     UFUNCTION(BlueprintCallable, Category = "Player")
  75.         void Pause();
  76.  
  77. private:
  78.  
  79.     /**
  80.     * Print on screen Debug message.
  81.     */
  82.     void Debug(FString msg);
  83.  
  84.     /**
  85.     * Read .ogg header file and refresh USoundWave metadata.
  86.     * @param sw     wave to put metadata
  87.     * @param rawFile    pointer to src file in memory
  88.     * @return 0 if everything is ok
  89.     *         1 if couldn't read metadata.
  90.     */
  91.     int fillSoundWaveInfo(USoundWave* sw, TArray<uint8>* rawFile);
  92.  
  93.     /**
  94.     * Tries to find out FSoundSource object associated to the USoundWave.
  95.     * @param sw     wave, search key
  96.     * @return 0 if wave found and correctly set
  97.     *        -1 if error: sound device not set
  98.     *        -2 if error: sound wave not found
  99.     */
  100.     int findSource(USoundWave* sw);
  101.  
  102. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement