CPSound

class CPSound(src: String, tags: Set[String]) extends CPGameObject with CPAsset

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 or WAV. Only HTTP, FILE, and JAR URIs are supported.

tags

Optional set of organizational tags. Default is an empty set.

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
trait CPAsset
class Object
trait Matchable
class Any

Value members

Concrete methods

def adjustVolume(delta: Float): Unit

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.

Source:
CPSound.scala
def dispose(): Unit

Disposes this sound object. After this call this sound cannot be used.

Disposes this sound object. After this call this sound cannot be used.

Source:
CPSound.scala
def fadeIn(fadeInMs: Long): Unit

Fades in the playback at the current mark.

Fades in the playback at the current mark.

Value parameters:
fadeInMs

Fade in duration in milliseconds.

Source:
CPSound.scala
def getBalance: Double

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].

Source:
CPSound.scala
def getCurrentTime: Long

Gets current playback time in milliseconds.

Gets current playback time in milliseconds.

Source:
CPSound.scala
def getRate: Double

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].

Source:
CPSound.scala

Gets media total duration in milliseconds.

Gets media total duration in milliseconds.

Source:
CPSound.scala
def getVolume: Double

Gets current audio volume. Audio volume range is [0.0, 1.0].

Gets current audio volume. Audio volume range is [0.0, 1.0].

Source:
CPSound.scala
def isPlaying: Boolean

Tests whether or not the audio playback is on.

Tests whether or not the audio playback is on.

Source:
CPSound.scala
def loop(fadeInMs: Long, endFun: CPSound => Unit): Unit

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.

fadeInMs

Fade in duration in milliseconds.

Source:
CPSound.scala
def pause(): Unit

Pauses current playback.

Pauses current playback.

Source:
CPSound.scala
def play(fadeInMs: Long, endFun: CPSound => Unit): Unit

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.

fadeInMs

Fade in duration in milliseconds. Default is zero.

Source:
CPSound.scala
def replay(fadeInMs: Long): Unit

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.

Source:
CPSound.scala
def rewind(): Unit

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.

Source:
CPSound.scala
def seek(ms: Long): Unit

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.

Source:
CPSound.scala
def setBalance(bal: Double): Unit

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.

Source:
CPSound.scala
def setRate(rate: Double): Unit

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.

Source:
CPSound.scala
def setVolume(vol: Double): Unit

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.

Source:
CPSound.scala
def stop(fadeOutMs: Long): Unit

Stops the playback.

Stops the playback.

Value parameters:
fadeOutMs

Fade out duration in milliseconds. Default is zero.

Source:
CPSound.scala
def toggle(fadeInMs: Long): Unit

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.

Source:
CPSound.scala

Inherited methods

override def equals(obj: Any): Boolean
Definition Classes
Inherited from:
CPGameObject
Source:
CPGameObject.scala
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Inherited from:
CPGameObject
Source:
CPGameObject.scala
def getTags: Set[String]

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.

See also:
Inherited from:
CPGameObject
Source:
CPGameObject.scala

Concrete fields

override val getOrigin: String

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.

Source:
CPSound.scala