| | |
| | | import AudioPlayer from '@/app/components/base/audio-btn/audio' |
| | | declare global { |
| | | // eslint-disable-next-line ts/consistent-type-definitions |
| | | // eslint-disable-next-line @typescript-eslint/consistent-type-definitions |
| | | interface AudioPlayerManager { |
| | | instance: AudioPlayerManager |
| | | } |
| | |
| | | private audioPlayers: AudioPlayer | null = null |
| | | private msgId: string | undefined |
| | | |
| | | private constructor() { |
| | | } |
| | | |
| | | public static getInstance(): AudioPlayerManager { |
| | | if (!AudioPlayerManager.instance) { |
| | | AudioPlayerManager.instance = new AudioPlayerManager() |
| | |
| | | return AudioPlayerManager.instance |
| | | } |
| | | |
| | | public getAudioPlayer(url: string, isPublic: boolean, id: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => void) | null): AudioPlayer { |
| | | public getAudioPlayer(url: string, isPublic: boolean, id: string | undefined, msgContent: string | null | undefined, voice: string | undefined, callback: ((event: string) => {}) | null): AudioPlayer { |
| | | if (this.msgId && this.msgId === id && this.audioPlayers) { |
| | | this.audioPlayers.setCallback(callback) |
| | | return this.audioPlayers |
| | |
| | | this.audioPlayers.cacheBuffers = [] |
| | | this.audioPlayers.sourceBuffer?.abort() |
| | | } |
| | | catch { |
| | | catch (e) { |
| | | } |
| | | } |
| | | |