Class TCastlePlayingSound
Unit
Declaration
type TCastlePlayingSound = class(TComponent)
Description
Controls a sound playback. You can pass an instance of it to TSoundEngine.Play or TCastleSoundSource.Play. It allows to control sound playback before you start playing (like OnStop) and after (like Offset).
You can reuse the same instance of TCastlePlayingSound
for playback many times, but you can start new playback only if the previous one finished. IOW, you can pass to TSoundEngine.Play or TCastleSoundSource.Play only instances when Playing is False
. If you don't want to wait, just create a new instance of TCastlePlayingSound
– they are designed to be lightweight, you can create them during runtime.
Destroying this class always stops the associated sound playback. Note that it is a TComponent descendant, so you can make it automatically destroyed when some owner TComponent is destroyed.
You can make your own descendants of this class, to associate any additional information with the playback of the sound.
Hierarchy
- TObject
- TPersistent
- TComponent
- TCastlePlayingSound
Overview
Methods
procedure DoStop; virtual; |
|
constructor Create(AOwner: TComponent); override; |
|
destructor Destroy; override; |
|
function Playing: Boolean; |
|
procedure Stop; |
Properties
property Sound: TCastleSound read FSound write SetSound; |
|
property OnStop: TNotifyEvent read FOnStop write SetOnStop; |
|
property FreeOnStop: Boolean read FFreeOnStop write SetFreeOnStop default false; |
|
property Loop: Boolean read FLoop write SetLoop default false; |
|
property Volume: Single read FVolume write SetVolume default 1.0; |
|
property Pitch: Single read FPitch write SetPitch default 1.0; |
|
property Priority: Single read FPriority write SetPriority default 1.0; |
|
property Offset: Single read GetOffset write SetOffset; |
|
property InitialOffset: Single read FInitialOffset write FInitialOffset; |
Description
Methods
procedure DoStop; virtual; |
|
Do the necessary job after source stopped, due to any reason. In this class it handles OnStop and FreeOnStop. If you override this: Since FreeOnStop may free the instance, you should add your code before calling inherited. |
constructor Create(AOwner: TComponent); override; |
|
This item has no description. |
destructor Destroy; override; |
|
This item has no description. |
function Playing: Boolean; |
|
Is the sound playing now. Using TSoundEngine.Play or TCastleSoundSource.Play makes it |
procedure Stop; |
|
Stop playing now. Note that you can also free the TCastlePlayingSound instance, it will always automatically stop the playback. Calling this on a sound that is not playing is allowed, and ignored. |
Properties
property Sound: TCastleSound read FSound write SetSound; |
|
Associated sound used for playing. You have to set it before playing. Cannot be changed while playing. |
property OnStop: TNotifyEvent read FOnStop write SetOnStop; |
|
If provided, we will call this event when sound stops playing. Note that in some cases the sound cannot be played at all. For example when TCastleSound is not loaded (no TCastleSound.URL provided, or invalid TCastleSound.URL provided) or when there are no free sound sources (these are limited in sound backends; the new sound may "steal" some sound source but only if the TCastleSound.Priority is high enough). Then TSoundEngine.Play or TCastleSoundSource.Play call the If the object owning the notification method may be destroyed before TCastlePlayingSound is destroyed, be sure to set this callback to You can only set this when sound is not playing (as otherwise it would be an easy source of bugs – sometimes TSoundEngine.Play wants to immediately stop sound playback). |
property FreeOnStop: Boolean read FFreeOnStop write SetFreeOnStop default false; |
|
Automatically free when the playback finishes. If the playback is not yet started, it will wait for it to start, and then finish. You can only set this when sound is not playing (as otherwise it would be an easy source of bugs – sometimes TSoundEngine.Play wants to immediately stop sound playback). |
property Loop: Boolean read FLoop write SetLoop default false; |
|
Is the playback looping. You can change this on a playing or stopped sound. |
property Volume: Single read FVolume write SetVolume default 1.0; |
|
Volume (how loud the playing sound is). The effective sound volume is a multiplication of TCastleSound.Volume, TCastlePlayingSound.Volume and TCastleSoundSource.Volume (if the sound is played through TCastleSoundSource). It is also affected by spatial calculations (if the sound is played through TCastleSoundSource with TCastleSoundSource.Spatial = Any value > 0 is allowed. |
property Pitch: Single read FPitch write SetPitch default 1.0; |
|
Sound playing speed. The effective sound pitch is a multiplication of TCastleSound.Pitch, TCastlePlayingSound.Pitch and TCastleSoundSource.Pitch (if the sound is played through TCastleSoundSource). Any value > 0 is allowed. |
property Priority: Single read FPriority write SetPriority default 1.0; |
|
How important is the sound, between 0.0 (least important) to 1.0 (most important). The effective priority is a multiplication of TCastleSound.Priority, TCastlePlayingSound.Priority and TCastleSoundSource.Priority (if the sound is played through TCastleSoundSource). |
property Offset: Single read GetOffset write SetOffset; |
|
Playback time of this sound, expressed in seconds. This value will loop back to zero for looping sound sources. Setting this to something larger than the sound duration (which you can read from TCastleSound.Duration) is ignored. This offset refers to the sound like it had a Pitch equal 1.0 (when the sound is not slowed down or sped up). So this offset will vary from 0 to the TCastleSound.Duration, regardless of the initial/current TCastleSound.Pitch value. The actual seconds passed since the sound started playing may be different, if you change the TCastleSound.Pitch to something else than 1.0. Using this on a sound that is not playing is allowed. Getting this value always returns zero in this case, and setting it is ignored. Note: you can adjust InitialOffset to determine the offset for starting new sound. It is deliberately a separate property from current Offset, otherwise it would be too easy to accidentally start playing in the middle when you wanted to play from the start. |
Generated by PasDoc 0.16.0-snapshot.