import { Observable } from "@babylonjs/core/Misc/observable"; import type { Nullable } from "@babylonjs/core/types"; import type { IAudioPlayer } from "./IAudioPlayer"; /** * Disposeable object interface */ export interface IDisposeObservable { /** * On dispose observable * * This observable is notified when the object is disposed */ readonly onDisposeObservable: Observable; } /** * Stream audio player * * This class is used to play the audio from the stream * * It is suitable for playing long sounds because it plays even if all of the audio is not loaded * * Wrapper of `HTMLAudioElement` which handles audio playback permission issues gracefully */ export declare class StreamAudioPlayer implements IAudioPlayer { /** * On load error observable * * This observable is notified when the audio load is failed */ readonly onLoadErrorObservable: Observable; /** * On duration changed observable * * This observable is notified when the audio duration is changed */ readonly onDurationChangedObservable: Observable; /** * On mute state changed observable * * This observable is notified when the mute state is changed */ readonly onPlaybackRateChangedObservable: Observable; /** * On mute state changed observable * * This observable is notified when the mute state is changed */ readonly onMuteStateChangedObservable: Observable; /** * On play observable * * This observable is notified when the player is played */ readonly onPlayObservable: Observable; /** * On pause observable * * This observable is notified when the player is paused */ readonly onPauseObservable: Observable; /** * On seek observable * * This observable is notified when the player is seeked */ readonly onSeekObservable: Observable; private readonly _audio; private _duration; private _playbackRate; private _isVirtualPlay; private _virtualStartTime; private _virtualPaused; private _virtualPauseCurrentTime; private _metadataLoaded; private readonly _bindedDispose; private readonly _disposeObservableObject; /** * Create a stream audio player * * In general disposeObservable should be `Scene` of Babylon.js * * @param disposeObservable Objects that limit the lifetime of this instance */ constructor(disposeObservable: Nullable); private readonly _onDurationChanged; private readonly _onLoadError; private readonly _onPlay; private readonly _onPause; private _ignoreSeekedEventOnce; private readonly _onSeek; /** * Audio duration (in seconds) */ get duration(): number; /** * Current time (in seconds) * * This property may be slow to update */ get currentTime(): number; set currentTime(value: number); /** @internal */ _setCurrentTimeWithoutNotify(value: number): void; /** * Volume (0.0 to 1.0) */ get volume(): number; set volume(value: number); /** * Whether the audio is muted */ get muted(): boolean; /** * Mute the audio */ mute(): void; /** * Unmute the audio * * Unmute is possible failed if user interaction is not performed * @returns Whether the audio is unmuted */ unmute(): Promise; /** * Playback rate (0.07 to 16.0) */ get playbackRate(): number; set playbackRate(value: number); /** @internal */ _setPlaybackRateWithoutNotify(value: number): void; /** * Determines whether or not the browser should adjust the pitch of the audio to compensate for changes to the playback rate made by setting */ get preservesPitch(): boolean; set preservesPitch(value: boolean); /** * Whether the player is paused */ get paused(): boolean; /** * Audio source URL */ get source(): string; set source(value: string); /** * Whether the audio metadata(durations) is loaded */ get metadataLoaded(): boolean; private _virtualPlay; private _playRequestBlocking; /** * Play the audio from the current position * * If context don't have permission to play the audio, play audio in a mute state */ play(): Promise; /** * Pause the audio */ pause(): void; /** * Dispose the player */ dispose(): void; }