Sound clip container.
Sounds object requires URI of the sound file in one of the supported formats: AIFF
, AU
or WAV
. Sound object is immutable but its playback can be controlled with changing volume, balance, rate, fade in and out. Sounds are inherently asynchronous objects, you can have many sounds objects, all of them are independent of each other, and you can play them in parallel.
Sound is an asset. Just like other assets such as fonts, images, animations or videos they are not managed or governed by the CosPlay game engine unlike scenes and scene objects that are managed and governed by the game engine. Assets are typically created outside the game loop and managed by the developer, they can be freely shared between scenes or scene objects as any other standard Scala objects.
NOTE: game engine must be initialized before sounds object can be created.
Value parameters
- src
-
RFC-2396 URI as required by
java.net.URI
or 'resource' file. URI should point to a sound file in one of the supported format:AIFF
,AU
orWAV
. Only HTTP, FILE, and JAR URIs are supported. - tags
-
Optional set of organizational tags. Default is an empty set.
Attributes
- Note
-
See https://freesound.org/ for the excellent source of royalty free sounds and audio-fx.
- Example
-
See CPSoundExample class for the example of using sounds.
- Companion
- object
- Source
- CPSound.scala
- Graph
-
- Supertypes
Members list
Value members
Concrete methods
Adjusts the audio volume by given delta
.
Adjusts the audio volume by given delta
.
Value parameters
- delta
-
Negative or positive delta to adjust the volume.
Attributes
- Source
- CPSound.scala
Disposes this sound object. After this call this sound cannot be used.
Disposes this sound object. After this call this sound cannot be used.
Attributes
- Source
- CPSound.scala
Fades in the playback at the current mark.
Fades in the playback at the current mark.
Value parameters
- fadeInMs
-
Fade in duration in milliseconds.
Attributes
- Source
- CPSound.scala
Gets current audio balance. Audio balance is clamped to the range [-1.0, 1.0].
Gets current audio balance. Audio balance is clamped to the range [-1.0, 1.0].
Attributes
- Source
- CPSound.scala
Gets current playback time in milliseconds.
Gets current playback rate. Playback rate is clamped to the range [0.0, 8.0].
Gets current playback rate. Playback rate is clamped to the range [0.0, 8.0].
Attributes
- Source
- CPSound.scala
Gets media total duration in milliseconds.
Gets current audio volume. Audio volume range is [0.0, 1.0].
Tests whether or not the audio playback is on.
Starts the looping playback from the start of the media.
Starts the looping playback from the start of the media.
Value parameters
- endFun
-
Optional callback to call when end of media is reached. Default is a no-op function. This callback will not be called unless the media riches the end and not stopped before. Specifically, calling
stop()
function will NOT trigger this callback. - fadeInMs
-
Fade in duration in milliseconds.
Attributes
- Source
- CPSound.scala
Pauses current playback.
Starts the playback with specified fade in duration. If previously paused, then playback resumes where it was paused. If playback was stopped, playback starts from the start. When playback reaches the end the player will rewind back to the beginning and stops.
Starts the playback with specified fade in duration. If previously paused, then playback resumes where it was paused. If playback was stopped, playback starts from the start. When playback reaches the end the player will rewind back to the beginning and stops.
Value parameters
- endFun
-
Optional callback to call when end of media is reached. Default is a no-op function. This callback will not be called unless the media riches the end and not stopped before. Specifically, calling
stop()
method will NOT trigger this function. - fadeInMs
-
Fade in duration in milliseconds. Default is zero.
Attributes
- Source
- CPSound.scala
Stops the playback first, rewinds and then starts the playback with specified fade in duration. If previously paused or stopped, then playback resumes from the start. When playback reaches the end the player will rewind back to the beginning and stops.
Stops the playback first, rewinds and then starts the playback with specified fade in duration. If previously paused or stopped, then playback resumes from the start. When playback reaches the end the player will rewind back to the beginning and stops.
Value parameters
- fadeInMs
-
Fade in duration in milliseconds. Default is zero.
Attributes
- Source
- CPSound.scala
Rewinds the live media playback to the zero position. No effect if the playback is not playing.
Rewinds the live media playback to the zero position. No effect if the playback is not playing.
Attributes
- Source
- CPSound.scala
Sets start time of the playback to the given millisecond mark.
Sets start time of the playback to the given millisecond mark.
Value parameters
- ms
-
Millisecond mark to set the start position to.
Attributes
- Source
- CPSound.scala
Sets the audio balance. Its effect will be clamped to the range [-1.0, 1.0].
Sets the audio balance. Its effect will be clamped to the range [-1.0, 1.0].
Value parameters
- bal
-
Audio balance to set.
Attributes
- Source
- CPSound.scala
Sets current playback rate. Playback rate is clamped to the range [0.0, 8.0].
Sets current playback rate. Playback rate is clamped to the range [0.0, 8.0].
Value parameters
- rate
-
Playback rate to set.
Attributes
- Source
- CPSound.scala
Sets current audio volume. Audio volume range is [0.0, 1.0].
Sets current audio volume. Audio volume range is [0.0, 1.0].
Value parameters
- vol
-
Audio volume to set.
Attributes
- Source
- CPSound.scala
Stops the playback. Note that 'endFun' function will no be called when this method is called.
Stops the playback. Note that 'endFun' function will no be called when this method is called.
Value parameters
- fadeOutMs
-
Fade out duration in milliseconds. Default is zero.
Attributes
- Source
- CPSound.scala
Fades in stopped or pauses the playing audio.
Fades in stopped or pauses the playing audio.
Value parameters
- fadeInMs
-
Fade in duration in milliseconds. Default is zero.
Attributes
- Source
- CPSound.scala
Inherited methods
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Compares the receiver object (this
) with the argument object (that
) for equivalence.
Any implementation of this method should be an equivalence relation:
- It is reflexive: for any instance
x
of typeAny
,x.equals(x)
should returntrue
. - It is symmetric: for any instances
x
andy
of typeAny
,x.equals(y)
should returntrue
if and only ify.equals(x)
returnstrue
. - It is transitive: for any instances
x
,y
, andz
of typeAny
ifx.equals(y)
returnstrue
andy.equals(z)
returnstrue
, thenx.equals(z)
should returntrue
.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to override hashCode
to ensure that objects which are "equal" (o1.equals(o2)
returns true
) hash to the same scala.Int. (o1.hashCode.equals(o2.hashCode)
).
Value parameters
- that
-
the object to compare against this object for equality.
Attributes
- Returns
-
true
if the receiver object is equivalent to the argument;false
otherwise. - Definition Classes
-
CPGameObject -> Any
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Gets unique ID of this game object.
Gets unique ID of this game object.
Attributes
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Gets optional set of organizational tags. Note that by default the set of tags is empty.
Gets optional set of organizational tags. Note that by default the set of tags is empty.
Attributes
- See also
- Inherited from:
- CPGameObject
- Source
- CPGameObject.scala
Concrete fields
Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.
Gets the origin of this asset. Typically, this should be a URL, file name or class name for in-code assets like array images, animations or system font.
Attributes
- Source
- CPSound.scala