@needle-tools/engine
Version:
Needle Engine is a web-based runtime for 3D apps. It runs on your machine for development with great integrations into editors like Unity or Blender - and can be deployed onto any device! It is flexible, extensible and networking and XR are built-in
126 lines (125 loc) • 4.12 kB
TypeScript
import { PositionalAudio } from "three";
import { Behaviour } from "./Component.js";
/**
* The AudioRolloffMode enum describes different ways that audio can attenuate with distance.
*/
export declare enum AudioRolloffMode {
Logarithmic = 0,
Linear = 1,
Custom = 2
}
/** The AudioSource can be used to play audio in the scene.
* Use `clip` to set the audio file to play.
* @category Multimedia
* @group Components
*/
export declare class AudioSource extends Behaviour {
/** Check if the user has interacted with the page to allow audio playback.
* Internally calling {@link Application.userInteractionRegistered}
*/
static get userInteractionRegistered(): boolean;
/** Register a callback that is called when the user has interacted with the page to allow audio playback.
* Internally calling {@link Application.registerWaitForInteraction}
*/
static registerWaitForAllowAudio(cb: Function): void;
/**
* The audio clip to play. Can be a string (URL) or a MediaStream.
*/
clip: string | MediaStream;
/**
* If true, the audio source will start playing as soon as the scene starts.
* If false, you can call play() to start the audio.
* @default false
*/
playOnAwake: boolean;
/**
* If true, the audio source will start loading the audio clip as soon as the scene starts.
* If false, the audio clip will be loaded when play() is called.
* @default false
*/
preload: boolean;
/**
* When true, the audio will play in the background. This means it will continue playing if the browser tab is not focused/active or minimized
* @default true
*/
playInBackground: boolean;
/**
* If true, the audio is currently playing.
*/
get isPlaying(): boolean;
/** The duration of the audio clip in seconds. */
get duration(): number | undefined;
/** The current time of the audio clip in 0-1 range. */
get time01(): number;
set time01(val: number);
/**
* The current time of the audio clip in seconds.
*/
get time(): number;
set time(val: number);
/**
* If true, the audio source will loop the audio clip.
* If false, the audio clip will play once.
* @default false
*/
get loop(): boolean;
set loop(val: boolean);
/** Can be used to play the audio clip in 2D or 3D space.
* 2D Playback is currently not fully supported.
* 0 = 2D, 1 = 3D
* */
get spatialBlend(): number;
set spatialBlend(val: number);
get minDistance(): number;
set minDistance(val: number);
get maxDistance(): number;
set maxDistance(val: number);
private _spatialBlend;
private _minDistance;
private _maxDistance;
get volume(): number;
set volume(val: number);
private _volume;
set pitch(val: number);
get pitch(): number;
rollOffMode: AudioRolloffMode;
private _loop;
private sound;
private helper;
private wasPlaying;
private audioLoader;
private shouldPlay;
private _lastClipStartedLoading;
private _audioElement;
get Sound(): PositionalAudio | null;
get ShouldPlay(): boolean;
/** Get the audio context from the Sound */
get audioContext(): AudioContext | undefined;
/** @internal */
awake(): void;
/** @internal */
onEnable(): void;
/** @internal */
onDisable(): void;
private onVisibilityChanged;
private onApplicationMuteChanged;
private createAudio;
private __onAllowAudioCallback;
private applySpatialDistanceSettings;
private onNewClip;
/** Play a audioclip or mediastream */
play(clip?: string | MediaStream | undefined): void;
/**
* Pause the audio
*/
pause(): void;
/**
* Stop the audio and reset the time to 0
*/
stop(): void;
private _lastContextTime;
private _hasEnded;
private _needUpdateSpatialDistanceSettings;
/** @internal */
update(): void;
}