hammerspoon2-docs
    Preparing search index...

    Class HSSound

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

    Index

    Constructors

    Properties

    currentTime: number

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

    duration: number

    The total duration of the sound in seconds.

    identifier: string

    A unique identifier for this sound object.

    isPlaying: boolean

    Whether the sound is currently playing.

    loops: boolean

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

    name: string | null

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

    volume: number

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

    Methods

    • Stops playback and releases all resources held by this sound. After calling destroy() the sound object should not be used.

      Returns void

    • Pauses playback, preserving the current position.

      Returns HSSound

      This sound object, for chaining.

    • Starts playback from the current position.

      Returns HSSound

      This sound object, for chaining.

    • Removes the completion callback previously set with setCallback().

      Returns HSSound

      This sound object, for chaining.

    • Resumes playback from a paused position.

      Returns HSSound

      This sound object, for chaining.

    • 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.

      Parameters

      • callback: (sound: HSSound, didFinish: boolean) => void

        A function called when playback ends.

      Returns HSSound

      This sound object, for chaining.

    • Stops playback. The playback position is not reset.

      Returns HSSound

      This sound object, for chaining.