xverse-components-utils
Version:
xverse components utils
105 lines (104 loc) • 3.29 kB
TypeScript
import { MediaManager, Video, Audio } from '@xverse/core';
import type { BaseAvatar } from 'xverse-components-avatar';
import type { BaseTTSReader } from 'xverse-components-utils-3d';
type ISoundEffectType = BaseTTSReader | Video | Audio | BaseAvatar;
interface ISoundManagerItem {
soundEffect?: ISoundEffectType;
muted: boolean;
active: boolean;
}
/**
* @description 管理所有的声音,如静音/开启静音之后,应该播放哪个声音;某个声音结束之后,应该播放哪一个声音
*/
declare class SoundManager {
private static instance;
isAllMuted: boolean | undefined;
separateControlIds: Set<string>;
onlyActiveSoundId: string | undefined;
onlyActiveVideoId: string | undefined;
soundRecord: Record<string, ISoundManagerItem>;
pausedSound: Record<string, ISoundManagerItem[]>;
pausedVideo: Record<string, ISoundManagerItem[]>;
_pauseWhenNoVisibleSounds: ISoundManagerItem[];
private constructor();
/**
* onClickHandle
* TODO:兜底逻辑需要优化
*/
private onClickHandle;
/**
*
* @param sound 判断盖声音当前是否是活跃的声音
*/
isActive(soundItem: ISoundManagerItem): boolean;
addSeparateControlId(id: string): void;
/**
* @param sound: ISoundEffectType
* @param isSeparateControl Boolean 是否单独控制
* @description 添加一个sound资源
*/
add(id: string, soundEffect: ISoundEffectType | undefined, isSeparateControl: boolean, muted?: boolean, active?: boolean): void;
/**
* 组件卸载时调用 将相关的状态重置
* @param id
*/
dispose(id: string): void;
get(id: string): ISoundManagerItem;
/**
* 从表单里删除
* 由于需要一直跟踪静音/非静音的状态 所以不删除
* @deprecated
* @param id
*/
delete(id: string): void;
/**
* @description 静音所有soundEffect
* @returns void
*/
muteAll(): void;
/**
* @description 开启所有soundEffect
* @returns void
*/
unmuteAll(): void;
/**
* @description 静音某些独立控制soundEffect
* @returns void
*/
mute(ids: string[] | string): void;
private _muteSingle;
/**
* @description 开启某些独立控制soundEffect
* @returns void
*/
unmute(ids: string[] | string): void;
private _unmuteSingle;
/**
* @description 获取所有管理的声音的状态
* @returns
*/
getMuted(ids: string[]): boolean;
pause(ids: string[] | string): void;
private _pauseSingle;
play(ids: string[] | string): void;
private _playSingle;
pauseAll(): void;
resumeAll(): void;
/**
* 音视频切后台的时候暂停
*/
pauseWhenNoVisible(): void;
/**
* 音视频切回前台的时候播放
*/
playWhenVisible(): void;
setOnlyActiveSound(id: string): void;
backOnlyActiveSoundEnd(id: string): void;
setOnlyActiveVideo(id: string): void;
backOnlyActiveVideoEnd(id: string): void;
setActiveStatus(id: string): void;
setUnActiveStatus(id: string): void;
static getInstance(): SoundManager;
}
export declare const soundManager: () => SoundManager;
export { Audio, Video, MediaManager };