Skip to main content
Inspiring
December 9, 2018
Answered

Why doesn't it work in browser Chrome

  • December 9, 2018
  • 1 reply
  • 1735 views

This code works in browser Microsoft Edge but not in browser Chrome with version 71.0.3578.80

<!DOCTYPE html>

<html>

<head>

<script src="https://code.createjs.com/1.0.0/createjs.min.js"></script>

</head>

<body onload="init()">

<script>

var src = "fransk1.mp3";  // set up our source

var soundInstance;      // the sound instance we create

function init() {

createjs.Sound.on("fileload", handleLoad, this); // add an event listener for when load is completed

createjs.Sound.registerSound(src);  // register sound, which will preload automatically

}

function handleLoad(evt) {

startPlayback();

}

function startPlayback(evt) {

if (soundInstance) {

return;

}

soundInstance = createjs.Sound.play(src);

}

</script>

</body>

</html>

In console in Chrome show this

createjs.min.js:18 [Deprecation] Synchronous XMLHttpRequest on the main thread is deprecated because of its detrimental effects to the end user's experience. For more help, check https://xhr.spec.whatwg.org/.

c._isFileXHRSupported @ createjs.min.js:18

createjs.min.js:18 Access to XMLHttpRequest at 'file:///C:/Users/%C3%84garen/Documents/HTML5%20canvas/SoundJS-1.0.0/SoundJS-1.0.0/examples/WebAudioPluginTest.fail' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

c._isFileXHRSupported @ createjs.min.js:18

createjs.min.js:18 Uncaught (in promise) DOMException

What is causing the sound to not work in Chrome with this link: https://p5js.org/examples/sound-preload-soundfile.html

will work the sound in Chrome and why is it so. It must have a different code set in order for it to work Chrome.

    This topic has been closed for replies.
    Correct answer kglad

    then add your code to animate:

    1. var src = "fransk1.mp3"// set up our source 
    2. var soundInstance;      // the sound instance we create
    3. init();
    4. function init() { 
    5. createjs.Sound.on("fileload", handleLoad, this); // add an event listener for when load is completed 
    6. createjs.Sound.registerSound(src);  // register sound, which will preload automatically 
    7. function handleLoad(evt) { 
    8. startPlayback(); 
    9. function startPlayback(evt) { 
    10. if (soundInstance) { 
    11. return
    12. soundInstance = createjs.Sound.play(src); 
    13. }

    1 reply

    kglad
    Community Expert
    Community Expert
    December 9, 2018

    because there's no user interaction triggering the play. 

    peorAuthor
    Inspiring
    December 10, 2018

    Okay but why does this link work https://p5js.org/examples/sound-preload-soundfile.html and not code.createjs.com They should fix that i like listening to music with mp3 files in the Chrome browser.

    Legend
    December 10, 2018

    peor  wrote

    i like listening to music with mp3 files in the Chrome browser.

    Why, does it sound different from using a media player?