import { AudioGroupInterface } from "../interface/AudioGroupInterface" ; import { AudioInterface } from "../interface/AudioInterface" ; import { HTMLAudioGroup } from "./HTMLAudioGroup" ; export class HTMLAudioGroupManager { private mGroupMap : Map < string , AudioGroupInterface > = new Map ( ) ; private constructor ( ) { } protected static instance : HTMLAudioGroupManager ; public static getInstance ( ) { if ( ! this . instance ) { this . instance = new HTMLAudioGroupManager ( ) ; } return this . instance ; } param groupName public getGroup ( groupName ) { let group = this . mGroupMap . get ( groupName ) ; if ( ! group ) { group = new HTMLAudioGroup ( ) ; group . name = groupName ; this . mGroupMap . set ( groupName , group ) ; } return group ; } param audio public addAudio ( audio ) { this . getGroup ( audio . group ) . addAudio ( audio ) ; } param audio public remove ( audio ) { if ( audio . group == undefined ) { return ; } this . getGroup ( audio . group ) . remove ( audio ) ; } param groupName public getAudios ( groupName ? ) { if ( groupName ) { return this . getGroup ( groupName ) . getAudios ( ) ; } let arr = new Array ( ) ; this . mGroupMap . forEach ( g => { g . getAudios ( ) . forEach ( a => { if ( ! arr . includes ( a ) ) { arr . push ( a ) ; } } ) ; } ) ; return arr ; } param groupName public getAlias ( groupName ? ) { if ( groupName ) { return this . getGroup ( groupName ) . getAlias ( ) ; } let arr = new Array ( ) ; this . mGroupMap . forEach ( g => { g . getAlias ( ) . forEach ( a => { if ( ! arr . includes ( a ) ) { arr . push ( a ) ; } } ) ; } ) ; return arr ; } param alias param groupName public hasAlias ( alias , groupName ? ) { if ( groupName ) { return this . getGroup ( groupName ) . hasAlias ( alias ) ; } let isExist = false ; this . mGroupMap . forEach ( g => { if ( g . hasAlias ( alias ) ) { isExist = true ; } } ) ; return isExist ; } }