Difference between revisions of "Oolite JavaScript Reference: Sound"

From Elite Wiki
m
m (replaced "function")
 
(5 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
<small>'''Prototype:''' <code>Object</code></small><br />
 
<small>'''Prototype:''' <code>Object</code></small><br />
<small>'''Subtypes:''' none
+
<small>'''Subtypes:''' none</small>
  
{{Oolite-class-added|1.71}}
+
The '''Sound''' class represents sound files. A <code>Sound</code> can be played through a <code>[[Oolite JavaScript Reference: SoundSource|SoundSource]]</code>.  <code>Sound</code> also provides methods to start and stop music.
 
 
The '''Sound''' class represents sound files. A <code>Sound</code> can be played through a <code>[[Oolite JavaScript Reference: SoundSource|SoundSource]]</code>.  <code>Sound</code> also provides functions to start and stop music.
 
  
 
== Properties ==
 
== Properties ==
Line 10: Line 8:
 
  '''name''' : String (read-only)
 
  '''name''' : String (read-only)
 
The file name of the sound file.
 
The file name of the sound file.
 +
 +
=== <code>musicSoundSource</code> ===
 +
{{oolite-prop-added|1.85}}
 +
'''musicSoundSource''' : [[Oolite JavaScript Reference: SoundSource|Music source source]] object
 +
 +
Returns the [[Oolite JavaScript Reference: SoundSource|Music source source]] object for this sound/music file.
  
 
== Static methods ==
 
== Static methods ==
Line 17: Line 21:
  
 
=== <code>playMusic</code> ===
 
=== <code>playMusic</code> ===
  function '''playMusic'''(soundFile : String [, loop: Boolean])
+
  function '''playMusic'''(soundFile : String [, loop: Boolean [, volumeGain: Float])
 
Play the specified music file, optionally looped. This may have no effect depending on the player’s music settings.
 
Play the specified music file, optionally looped. This may have no effect depending on the player’s music settings.
 +
 +
The optional <code>volumeGain</code> parameter (added in Oolite 1.85) must be between 0.0 and 1.0 (where 1.0 is the loudest possible setting, and the default), and is relative to the master gain value.
  
 
=== <code>stopMusic</code> ===
 
=== <code>stopMusic</code> ===
Line 24: Line 30:
 
Stop music. If a name is specified, the music will only be stopped if that’s the name of the currently playing music. For example, if you start some music with <code>Sound.playMusic("myoxp-exciting-music.ogg")</code> and later want to stop it, call <code>Sound.stopMusic("myoxp-exciting-music.ogg")</code> to avoid stopping any other music that may have taken over in the meanwhile.
 
Stop music. If a name is specified, the music will only be stopped if that’s the name of the currently playing music. For example, if you start some music with <code>Sound.playMusic("myoxp-exciting-music.ogg")</code> and later want to stop it, call <code>Sound.stopMusic("myoxp-exciting-music.ogg")</code> to avoid stopping any other music that may have taken over in the meanwhile.
  
[[Category:Oolite scripting]]
+
[[Category:Oolite JavaScript Reference]]

Latest revision as of 15:21, 28 October 2022

Prototype: Object
Subtypes: none

The Sound class represents sound files. A Sound can be played through a SoundSource. Sound also provides methods to start and stop music.

Properties

name

name : String (read-only)

The file name of the sound file.

musicSoundSource

This property was added in Oolite test release 1.85.

musicSoundSource : Music source source object

Returns the Music source source object for this sound/music file.

Static methods

load

function load(soundFile : String)

Loads a sound file, and returns the resulting Sound object. soundFile may be either a file name or a customsounds.plist key in square brackets.

playMusic

function playMusic(soundFile : String [, loop: Boolean [, volumeGain: Float])

Play the specified music file, optionally looped. This may have no effect depending on the player’s music settings.

The optional volumeGain parameter (added in Oolite 1.85) must be between 0.0 and 1.0 (where 1.0 is the loudest possible setting, and the default), and is relative to the master gain value.

stopMusic

function stopMusic([soundFile : String])

Stop music. If a name is specified, the music will only be stopped if that’s the name of the currently playing music. For example, if you start some music with Sound.playMusic("myoxp-exciting-music.ogg") and later want to stop it, call Sound.stopMusic("myoxp-exciting-music.ogg") to avoid stopping any other music that may have taken over in the meanwhile.