HSSound
TypeAn object representing an audio sound that can be played, paused, and stopped.
Create instances using hs.sound.fromFile() or hs.sound.named().
Properties
name
string
The name of this sound. System sounds loaded by name return their name; file-based sounds return `null`.
currentTime
number
The current playback position in seconds. Assign a value to seek to that position.
Methods
play() -> HSSound
Starts playback from the current position.
Declaration
play() -> HSSound
Returns
HSSound
This sound object, for chaining.
Example
hs.sound.named("Basso").play()
pause() -> HSSound
Pauses playback, preserving the current position.
Declaration
pause() -> HSSound
Returns
HSSound
This sound object, for chaining.
Example
const s = hs.sound.named("Basso")
s.play()
s.pause()
resume() -> HSSound
Resumes playback from a paused position.
Declaration
resume() -> HSSound
Returns
HSSound
This sound object, for chaining.
Example
const s = hs.sound.named("Basso")
s.play()
s.pause()
s.resume()
stop() -> HSSound
Stops playback. The playback position is not reset.
Declaration
stop() -> HSSound
Returns
HSSound
This sound object, for chaining.
Example
const s = hs.sound.named("Basso")
s.play()
s.stop()
setCallback(callback) -> HSSound
Sets a function to be called when playback finishes.
The callback receives two arguments: the sound object and a boolean — `true` if the
sound completed naturally, `false` if it was stopped before finishing.
Declaration
setCallback(callback) -> HSSound
Parameters
| Name | Type | Description |
|---|---|---|
| callback | JSValue | A function called when playback ends. |
Returns
HSSound
This sound object, for chaining.
Example
hs.sound.named("Basso")
.setCallback((sound, didFinish) => {
console.log("Finished: " + didFinish)
})
.play()
removeCallback() -> HSSound
Removes the completion callback previously set with `setCallback()`.
Declaration
removeCallback() -> HSSound
Returns
HSSound
This sound object, for chaining.
Example
s.removeCallback()
destroy() -> None
Stops playback and releases all resources held by this sound.
After calling `destroy()` the sound object should not be used.
Declaration
destroy() -> None
Returns
None
Example
s.destroy()