Constructor
new Audio(options)
Create a new Audio with the specified options.
Parameters:
Name | Type | Description |
---|---|---|
options |
object | The options object for the Asset - see below |
Example
const { Asset } = require('tenkai')
var asset = new Asset({
src: 'music/maintitle.mp3', // Source file
type: 'audio/mpeg', // MIME type of the asset file
startTime: 0, // Start offset in ms (optional)
endTime: 1040, // End offset in ms (optional)
loop: true // Loop the audio continuously (optional, default false)
})
Methods
fadeIn(duration, callback)
Fade in the audio over the given duration then call the optional callback
Parameters:
Name | Type | Default | Description |
---|---|---|---|
duration |
integer | 1000 | Fade duration in ms |
callback |
function | The callback function to invoke when the fade has completed |
fadeOut(duration, callback)
Fade out the audio over the given duration then call the optional callback
Parameters:
Name | Type | Default | Description |
---|---|---|---|
duration |
integer | 1000 | Fade duration in ms |
callback |
function | The callback function to invoke when the fade has completed |
load(callback)
Load the Audio asynchronously from its src and optionally trigger the supplied callback when available.
Parameters:
Name | Type | Description |
---|---|---|
callback |
function | The callback function to invoke when the asset has been loaded |
Example
audio.load((err, au) => {
console.log("Audio "+au.name+" Loaded")
})
pause()
Pause the audio at the current position.
play()
Play the audio from the current position.
playRange(start, end, start)
Play the audio from the start time index to the end time index and optionally loop.
Parameters:
Name | Type | Default | Description |
---|---|---|---|
start |
float | null | The start offset in ms (optional) |
end |
float | null | The end offset in ms (optional) |
start |
boolean | Loop the audio (optional) |
stop()
Stop the audio and reset it to the beginning