Skip to content

Commit

Permalink
Fix: Let preferUrl respect supported formats (#255)
Browse files Browse the repository at this point in the history
  • Loading branch information
zOadT committed Oct 19, 2023
1 parent db09fb0 commit 9f36f77
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/Sound.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { HTMLAudioMedia } from './htmlaudio/HTMLAudioMedia';
import { getInstance } from './instance';
import { IMedia, IMediaContext, IMediaInstance } from './interfaces';
import { SoundSprite, SoundSpriteData, SoundSprites } from './SoundSprite';
import { extensions } from './utils/supported';
import { extensions, supported } from './utils/supported';
import { WebAudioMedia } from './webaudio/WebAudioMedia';

/**
Expand Down Expand Up @@ -322,11 +322,17 @@ class Sound
*/
private preferUrl(urls: string[]): string
{
const [{ url }] = urls
const [file] = urls
.map((url) => ({ url, ext: utils.path.extname(url).slice(1) }))
.filter(({ ext }) => supported[ext])
.sort((a, b) => extensions.indexOf(a.ext) - extensions.indexOf(b.ext));

return url;
if (!file)
{
throw new Error('No supported file type found');
}

return file.url;
}

/** Instance of the media context. */
Expand Down

0 comments on commit 9f36f77

Please sign in to comment.