musquito icon indicating copy to clipboard operation
musquito copied to clipboard

How to play sounds from imported source when run locally?

Open newalphamedia opened this issue 4 years ago • 5 comments
trafficstars

I import sound files like so: const soundFiles = require.context('./assets/sounds', true, /\.(aac)$/i);

This creates some urls which I can pass to musquito to play, however it won't work when run locally, because of permission errors. It does work when I create an audio object passing the path, e.g. "new Audio(soundFiles[...])".

Is there a way to make musquito compatible?

newalphamedia avatar Dec 05 '20 03:12 newalphamedia

Can u please post the error? Also, did you try passing stream option as true? http://musquitojs.com/#streaming

VJAI avatar Dec 05 '20 05:12 VJAI

Access to XMLHttpRequest at 'file:///G:/vue/my-project/dist/media/track.c92bb697.aac' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, chrome-untrusted, https.

I've tried stream: true and also stream: false, same error occurs.

This below method works on imported sound files just fine without the above error:

var audioInstance = new Audio(importedSoundFilePath...);
audioInstance.volume = this.soundVolume/100;
audioInstance.play();

newalphamedia avatar Dec 05 '20 05:12 newalphamedia

I managed to get Howler library to work. I had to enable the "autoplay" option, otherwise it wouldn't though... not sure what's the reason behind this but it's likely the same with your library?

newalphamedia avatar Dec 05 '20 12:12 newalphamedia

I'll check this weekend and let you know

VJAI avatar Dec 06 '20 02:12 VJAI

Is it possible to share some code fiddle?

VJAI avatar Dec 07 '20 08:12 VJAI