CPSound

org.cosplay.CPSound
See theCPSound companion object
class CPSound(src: String, tags: Set[String]) extends CPGameObject, 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.

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

Members list

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.

Attributes

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.

Attributes

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.

Attributes

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

Attributes

Source
CPSound.scala
def getCurrentTime: Long

Gets current playback time in milliseconds.

Gets current playback time in milliseconds.

Attributes

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

Attributes

Source
CPSound.scala
def getTotalDuration: Long

Gets media total duration in milliseconds.

Gets media total duration in milliseconds.

Attributes

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

Attributes

Source
CPSound.scala
def isPlaying: Boolean

Tests whether or not the audio playback is on.

Tests whether or not the audio playback is on.

Attributes

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. 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
def pause(): Unit

Pauses current playback.

Pauses current playback.

Attributes

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

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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.

Attributes

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

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

Attributes

Source
CPSound.scala

Inherited methods

override def equals(obj: Any): Boolean

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 type Any, x.equals(x) should return true.
  • It is symmetric: for any instances x and y of type Any, x.equals(y) should return true if and only if y.equals(x) returns true.
  • It is transitive: for any instances x, y, and z of type Any if x.equals(y) returns true and y.equals(z) returns true, then x.equals(z) should return true.

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
def getId: String

Gets unique ID of this game object.

Gets unique ID of this game object.

Attributes

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.

Attributes

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.

Attributes

Source
CPSound.scala