Script API - v26.60.30
    Preparing search index...

    Class SoundInstance

    Represents a handle to a sound that has been played. The handle is required to control the sound while it is playing (for example, to call stop, setVolume, setPitch, fade, or seekTo). Infinitely-looping sounds (started with loop: -1) stop automatically when the last SoundInstance reference is dropped; retain the handle for as long as the sound should keep playing.

    export class SoundInstance {
    private constructor();
    readonly durationInfo?: SoundDurationInfo;
    readonly id: string;
    readonly recipient?: Player;
    readonly soundEventId: string;
    fade(duration: number, targetVolume: number): void;
    pause(): void;
    resume(): void;
    seekTo(seconds: number): void;
    setPitch(pitch: number): void;
    setVolume(volume: number): void;
    stop(): void;
    }
    Index
    durationInfo?: SoundDurationInfo

    Gets duration and playback information for this sound.

    This property can't be read in early-execution mode.

    id: string

    Unique identifier of this sound instance.

    This property can't be read in early-execution mode.

    recipient?: Player

    Gets the player this sound was played for.

    This property can't be read in early-execution mode.

    soundEventId: string

    Gets the identifier of the sound event this instance was started with.

    This property can't be read in early-execution mode.

    • Rc

      Parameters

      • duration: number

        Duration of the fade in seconds. Must be non-negative. Minimum value: 0

      • targetVolume: number

        Volume multiplier to fade to, relative to the selected sound variant's volume. Must be non-negative. Minimum value: 0

      Returns void

      Fades this sound instance from its current volume multiplier to the target multiplier over the specified duration. Volume multipliers are relative to the selected sound variant's volume. To fade in from silence, call setVolume(0.0) first; to fade out, pass a target volume of 0.0.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

    • Rc

      Returns void

      Pauses this sound.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

    • Rc

      Returns void

      Resumes this sound after a pause.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

    • Rc

      Parameters

      • seconds: number

        Position to seek to in seconds. Must be non-negative. Bounds: [0, 107374184]

      Returns void

      Sets the playback position of this sound instance.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      Throws if seconds is negative, or if the sound has a known duration and seconds is greater than that duration.

      minecraftcommon.ArgumentOutOfBoundsError

      This function can't be called in early-execution mode.

    • Rc

      Parameters

      • pitch: number

        Pitch multiplier between 0.01 and 10.0. A value of 1.0 is normal pitch. Bounds: [0.009999999776482582, 10]

      Returns void

      Sets the pitch of this sound instance.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

    • Rc

      Parameters

      • volume: number

        Volume multiplier between 0.0 and 10.0. A value of 1.0 uses the selected sound variant's volume. Bounds: [0, 10]

      Returns void

      Sets the volume multiplier of this sound instance relative to the volume of the selected sound variant.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.

    • Returns void

      Stops this sound instance from playing.

      no-restricted-execution - This function can't be called in restricted-execution mode.

      This function can't be called in early-execution mode.