Gorilla.Audio.Manager
Unit Gorilla.Audio.Manager.pasClasses
- EGorillaAudioException = class ( TObject )
- TGorillaAudioManager = class ( TThread )
Records
- record TCacheAudioEntry
- record TQueueAudioEntry
Enumerations
- enum TGorillaAudioAction = ( Cache, Play, Stop, Pause ) ;
- enum TGorillaAudioMode = ( Once, Loop ) ;
Constants
TGorillaAudioAction
Defines a state of audio file handling.
The action defines what the audio manager should do with the specific audio file.TGorillaAudioAction.Cache - start caching
TGorillaAudioAction.Play - start playback
TGorillaAudioAction.Stop - stop playback
TGorillaAudioAction.Pause - pause playback or restart playback
TGorillaAudioMode
Defines the kind of playback used for a specific audio file.
The mode defines the kind of playback used for this audio file.TGorillaAudioMode.Once - audio file is played only once
TGorillaAudioMode.Loop - audio file played in a loop
TQueueAudioEntry
EGorillaAudioException
Ancestors
Members
Fields
- private FMessage :
string
- private FHelpContext :
Integer
- private FInnerException :
Exception
- private FStackInfo :
Pointer
- private FAcquireInnerException :
Boolean
- public GetExceptionStackInfoProc :
- public GetStackInfoStringProc :
- public CleanUpStackInfoProc :
Methods
- public constructor Create ( const Msg : string ) ;
- public constructor CreateFmt ( const Msg : string; const Args : array of TVarRec ) ;
- public constructor CreateRes ( Ident : NativeUInt ) ;
- public constructor CreateRes ( ResStringRec : PResStringRec ) ;
- public constructor CreateResFmt ( Ident : NativeUInt; const Args : array of TVarRec ) ;
- public constructor CreateResFmt ( ResStringRec : PResStringRec; const Args : array of TVarRec ) ;
- public constructor CreateHelp ( const Msg : string; AHelpContext : Integer ) ;
- public constructor CreateFmtHelp ( const Msg : string; const Args : array of TVarRec; AHelpContext : Integer ) ;
- public constructor CreateResHelp ( Ident : NativeUInt; AHelpContext : Integer ) ;
- public constructor CreateResHelp ( ResStringRec : PResStringRec; AHelpContext : Integer ) ;
- public constructor CreateResFmtHelp ( ResStringRec : PResStringRec; const Args : array of TVarRec; AHelpContext : Integer ) ;
- public constructor CreateResFmtHelp ( Ident : NativeUInt; const Args : array of TVarRec; AHelpContext : Integer ) ;
- public destructor Destroy ( ) ;
- class private procedure Create@ ( ) ; class constructor noself;
- class private procedure Destroy@ ( ) ; class destructor noself;
- protected procedure SetInnerException ( ) ;
- protected procedure SetStackInfo ( AStackInfo : Pointer ) ;
- protected function GetStackTrace ( ) : string ;
- protected procedure RaisingException ( P : PExceptionRecord ) ; virtual;
- public function GetBaseException ( ) : Exception ; virtual;
- public function ToString ( ) : string ; override;
- public procedure RaiseOuterException ( E : Exception ) ; static;
- public procedure ThrowOuterException ( E : Exception ) ; static;
Properties
TGorillaAudioManager
Audio management component encapsulated inside of a thread. This component was not built for performance only for easy usage. The component contains a mediaplayer for each audio file to allow multiple playback and independet audio handling (volume).
Remarks
By using the AudioManager the startup can slow down immense. Because when queueing audio files the media file component loads up the file completely to memory and creates an separate thread.Ancestors
Members
Fields
- private FLoopCheckInterval :
Integer
- private FQueueTimeout :
Integer
- private FLatestLoopCheck :
Int64
- private FQueueEvent :
TEvent
- private FThreadLock :
TCriticalSection
- private TemplateMediaPlayer :
TMediaPlayer
- protected FQueue :
TQueue<Gorilla.Audio.Manager.TQueueAudioEntry>
- protected FCaching :
Boolean
- protected FCache :
TGorillaAudioCache
- protected FMute :
Boolean
Methods
- public constructor Create ( ) ;
- public destructor Destroy ( ) ;
- private procedure SetLoopCheckInterval
(
AValue :
Integer
)
;
Sets threadsafe the internal FLoopCheckInterval field.
- private procedure SetQueueTimeout
(
AValue :
Integer
)
;
Sets threadsafe the internal FQueueTimeout field.
- protected procedure Execute
(
)
;
override;
General queue execution thread. The method will handle queue actions, like caching, playback, stopping and pausing audio files. It also checks audio files for looping to restart their playback.
- protected procedure AddToQueue
(
const
AId :
Integer; const
AAction :
TGorillaAudioAction; const
AFilename :
string; const
AMode :
TGorillaAudioMode
=
Once
; const
AVolume :
Single
=
0.75
)
;
virtual;
Creates a TQueueAudioEntry structure and adds it to the audio queue. The method will automatically call the SetQueueEvent() method.
- protected function GetMediaPlayer
(
const
AId :
Integer; const
AFilename :
string
=
; const
AMode :
TGorillaAudioMode
=
Once
; const
AVolume :
Single
=
0.75
)
: TMediaPlayer
;
virtual;
The method tries to find an existing media player component in cache. If it cannot find a cached entry with the submitted id, the method will create a new media player component and automatically cache the audio file.
- protected procedure HandleLoopedAudio
(
)
;
virtual;
Iterates through all cached audio files and checks if a specific audio entry is finished. If it's marked for looped playback, the method will reset CurrentTime of media player and automatically start the playback again.
- protected procedure SetQueueEvent
(
)
;
virtual;
Sets the queue event to active and lets the execution method know, that a new audio file was queued.
- protected procedure ResetQueueEvent
(
)
;
virtual;
Resets the queue event to start again: waiting for a queue event.
- protected procedure SetMute
(
AValue :
Boolean
)
;
virtual;
Mutes all audio files at once.
- protected procedure InitializeTemplatePlayer
(
)
;
class;
To use the TMediaPlayer component inside of a thread, the first media player needs to be created inside of the main thread and once an audio file needs to be played in main thread too.
- protected procedure FinalizeTemplatePlayer
(
)
;
class;
Destroys the template media player component.
- public procedure BeginCaching
(
)
;
Use BeginCaching() before adding any audio files to cache. This will boost loadup performance.
- public procedure EndCaching
(
)
;
Complete a started caching process (started by BeginCaching()) to let the audio manager know that your done.
- public function AudioAlreadyCached
(
const
AId :
Integer
)
: Boolean
;
Checks if a audio file was already cached.
- public procedure Add
(
const
AId :
Integer; const
AFilename :
string; const
AVolume :
Single
=
0.75
)
;
Cache an audio file from file with a submitted id, filename and an optional volume.
- public procedure Play
(
const
AId :
Integer; const
AMode :
TGorillaAudioMode
=
Once
; const
AVolume :
Single
=
0.75
)
;
Plays a cached audio file identified by its id.
- public procedure Stop
(
const
AId :
Integer
)
;
Stops playback of a cached audio file identified by its id.
- public procedure Pause
(
const
AId :
Integer
)
;
Pauses playback of a cached audio file identified by its id.
- public procedure PauseAll
(
)
;
Pauses all playing audio files.
- public procedure StopAll
(
)
;
Stops all currently played audio files.
Properties
- public LoopCheckInterval : Integer
The loop check interval defines the time the audio manager checks if an audio file is finished and about to be started again.
read FLoopCheckInterval
write SetLoopCheckInterval - public QueueTimeout : Integer
The audio manager is event based. The executor thread will wait for a queue event. This timeout value defines how long it will wait for.
read FQueueTimeout
write SetQueueTimeout - public Mute : Boolean