import { ILoaderPlugin , ILoaderResource , LoaderResource } from '@pixi/loaders' ; import { getInstance } from './instance' ; import { resolveUrl } from './utils/resolveUrl' ; import { extensions } from './utils/supported' ; /**
 * Sound middleware installation utilities for PIXI.Loader
 */ class SoundLoader implements ILoaderPlugin { /** Install the middleware */ public static add ( ) { SoundLoader . setLegacy ( getInstance ( ) . useLegacy ) ; } param legacy static setLegacy ( legacy ) { const exts = extensions ; if ( ! legacy ) { exts . forEach ( ( ext ) => { LoaderResource . setExtensionXhrType ( ext , LoaderResource . XHR_RESPONSE_TYPE . BUFFER ) ; LoaderResource . setExtensionLoadType ( ext , LoaderResource . LOAD_TYPE . XHR ) ; } ) ; } else { exts . forEach ( ( ext ) => { LoaderResource . setExtensionXhrType ( ext , LoaderResource . XHR_RESPONSE_TYPE . DEFAULT ) ; LoaderResource . setExtensionLoadType ( ext , LoaderResource . LOAD_TYPE . AUDIO ) ; } ) ; } } /** Handle the preprocessing of file paths */ public static pre ( resource , next ) { resolveUrl ( resource ) ; next ( ) ; } /** Actual resource-loader middleware for sound class */ public static use ( resource , next ) { if ( resource . data && extensions . indexOf ( resource . extension ) > - 1 ) { ( resource as any ) . sound = getInstance ( ) . add ( resource . name , { loaded : next , preload : true , url : resource . url , source : resource . data , } ) ; } else { next ( ) ; } } } export { SoundLoader } ;