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
The name of this sound. System sounds loaded by name return their name; file-based sounds return null.
currentTime
The current playback position in seconds. Assign a value to seek to that position.
Methods
play() -> HSSound
Starts playback from the current position.
play() -> HSSound
hs.sound.named("Basso").play()
pause() -> HSSound
Pauses playback, preserving the current position.
pause() -> HSSound
const s = hs.sound.named("Basso")
s.play()
s.pause()
resume() -> HSSound
Resumes playback from a paused position.
resume() -> HSSound
const s = hs.sound.named("Basso")
s.play()
s.pause()
s.resume()
stop() -> HSSound
Stops playback. The playback position is not reset.
stop() -> HSSound
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.
setCallback(callback) -> HSSound
| Name | Type | Description |
|---|---|---|
| callback | JSValue | A function called when playback ends. |
hs.sound.named("Basso")
.setCallback((sound, didFinish) => {
console.log("Finished: " + didFinish)
})
.play()
removeCallback() -> HSSound
Removes the completion callback previously set with setCallback().
removeCallback() -> HSSound
s.removeCallback()
destroy() -> None
Stops playback and releases all resources held by this sound.
After calling destroy() the sound object should not be used.
destroy() -> None
s.destroy()