Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to play sounds from imported source when run locally? #20

Open
newalphamedia opened this issue Dec 5, 2020 · 5 comments
Open

How to play sounds from imported source when run locally? #20

newalphamedia opened this issue Dec 5, 2020 · 5 comments

Comments

@newalphamedia
Copy link

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?

@VJAI
Copy link
Owner

VJAI commented Dec 5, 2020

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

@newalphamedia
Copy link
Author

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
Copy link
Author

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?

@VJAI
Copy link
Owner

VJAI commented Dec 6, 2020

I'll check this weekend and let you know

@VJAI
Copy link
Owner

VJAI commented Dec 7, 2020

Is it possible to share some code fiddle?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants