API Docs

An object representing an audio sound that can be played, paused, and stopped. Create instances using hs.sound.fromFile() or hs.sound.named().

Properties

identifier

string
A unique identifier for this sound object.

name

string
The name of this sound. System sounds loaded by name return their name; file-based sounds return `null`.

duration

number
The total duration of the sound in seconds.

currentTime

number
The current playback position in seconds. Assign a value to seek to that position.

volume

number
The playback volume, from `0.0` (silent) to `1.0` (full volume).

loops

boolean
Whether the sound loops when it reaches the end. Defaults to `false`.

isPlaying

boolean
Whether the sound is currently playing.

Methods

play() -> HSSound

Starts playback from the current position.
play() -> HSSound
HSSound
This sound object, for chaining.
hs.sound.named("Basso").play()

pause() -> HSSound

Pauses playback, preserving the current position.
pause() -> HSSound
HSSound
This sound object, for chaining.
const s = hs.sound.named("Basso")
s.play()
s.pause()

resume() -> HSSound

Resumes playback from a paused position.
resume() -> HSSound
HSSound
This sound object, for chaining.
const s = hs.sound.named("Basso")
s.play()
s.pause()
s.resume()

stop() -> HSSound

Stops playback. The playback position is not reset.
stop() -> HSSound
HSSound
This sound object, for chaining.
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.
HSSound
This sound object, for chaining.
hs.sound.named("Basso")
    .setCallback((sound, didFinish) => {
        console.log("Finished: " + didFinish)
    })
    .play()

removeCallback() -> HSSound

Removes the completion callback previously set with `setCallback()`.
removeCallback() -> HSSound
HSSound
This sound object, for chaining.
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
None
s.destroy()