Constructor
new Sound(path)
| Name | Type | Description |
|---|---|---|
path | String | The path to the sound file |
let mySound = new gameify.audio.Sound("my-sound.mp3");Members
(readonly) loaded
If the sound has loaded yet
(readonly) path
The sound path. Modifying this will not do anything.
Methods
changePath(path)
Change and load a new image path. Resets the image's crop
| Name | Type | Description |
|---|---|---|
path | string | The new image path |
fromJSON(data, ref) → {gameify.Image}
Creates a object from JSON data
| Name | Type | Description |
|---|---|---|
data | Object | | Serialized object data (from object.toJSON) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- gameify.
Image
getCalculatedVolume() → {Number}
Get the calculated volume of the sound (after audioManager volume is applied)
The calculated volume of the sound, between 0 and 1
- Type:
- Number
getCurrentTime() → {Number}
Get the current seek time of the sound
The current seek time, in seconds
- Type:
- Number
getDuration() → {Number}
Get the duration of the audio (in seconds)
The duration of the sound in seconds
- Type:
- Number
getLoop() → {Boolean}
Check if the sound is set to loop
If the sound is set to loop
- Type:
- Boolean
getVolume() → {Number}
Get the volume of the sound. Note that this volume is mixed with the audioManager's volume to get the actual volume. Use getCalculatedVolume() to get the actual volume the sound will be played at.
- See
- {gameify.audio.Sound.getCalculatedVolume}
The volume of the sound, between 0 and 1
- Type:
- Number
isPlaying() → {Boolean}
Check if the sound currently is playing
- Type:
- Boolean
onLoad(callback)
Set a function to be run when the sound is loaded (Can be played through w/o buffering)
| Name | Type | Description |
|---|---|---|
callback | function | The function to be called when the sound is loaded. |
pause()
Pause the sound
play()
Play the sound. Please be aware some browsers block autoplay by default.
seek(time)
Seek to a specific point in the audio
| Name | Type | Description |
|---|---|---|
time | Number | The time to seek to, in seconds |
seekRelative(time)
Seek a percentage of the way through the audio
| Name | Type | Description |
|---|---|---|
time | Number | Where to seek to, from 0 to 1 |
setLoop(loop)
Choose whether the sound should loop or not (default is not looping)
| Name | Type | Description |
|---|---|---|
loop | Boolean | If the sound should loop |
setVolume(volume)
Sets the volume of the sound
| Name | Type | Description |
|---|---|---|
volume | Number | The desired volume level, a number between 0 and 1. |
stop()
Stop the sound (resets the seek time)
toJSON(keyopt, ref) → {Object}
Convert the object to JSON
| Name | Type | Attributes | Description |
|---|---|---|---|
key | string | <optional> | Key object is stored under (unused, here for consistency with e.g. Date.toJSON, etc.) |
ref | function | A function that returns a name for other objects, so they can be restored later |
- Type:
- Object