macos – Sound file does not play utilizing JavaScript and HTMLAudioElement

0
1

e080

e080
e080 e080 e080

e080 I am making an attempt e080 to play a 5-second lengthy e080 sound in JavaScript utilizing HTMLAudioElement, e080 an audio subclass of e080 HTMLMediaElement e080 , which ought to be e080 easy:

e080

 e080 
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
     e080 <meta http-equiv="Content material-Sort" content material="textual  e080 content/html; charset=UTF-8" />
</head>

<physique>
    e080  <script>
     e080 var a = new Audio("sound.mp3");
  e080    a.load();
   e080   a.autoplay = true;
  e080    a.loops =  e080 false;
    a.muted  e080 = false;
     e080 a.quantity = 1.0;
    e080  a.pause = false;
   e080   a.controls = true;
  e080    a.onended =  e080 perform(){ window.console.log("Ended play"); };
   e080   window.console.log("Will play; error  e080 = " + a.error +  e080 "; ended = " +  e080 a.ended);
    a.play();
  e080    window.console.log("Did play;  e080  error = " +  e080 a.error + "; ended =  e080 " + a.ended);

    e080  perform timed_out() {
   e080       e080  window.console.log("Timed out; error =  e080 " + a.error + ";  e080 ended = " + a.ended);
  e080    };
   e080   setTimeout(timed_out, 10000);
   e080   </script>
</physique>
</html>

e080

e080 Though the JavaScript console reveals e080 “Will play; error = null; e080 ended = false”, “Did play; e080 error = null; ended e080 = false”, no sound is e080 heard, no “Ended play” message e080 seems, and after ten seconds e080 it reveals “After ten seconds: e080 error = null; ended = e080 false”. The one different console e080 message says that favicon.ico was e080 not discovered, which is smart e080 as a result of there e080 is not one.

e080

e080 I am utilizing Safari 15.5 e080 on an Apple Silicon MacBook e080 Professional operating macOS 12.4.

e080

e080 I’ve:

e080

    e080

  • e080 Tried it with and with e080 out every of the settings e080 which ought to be defaults: e080 a.load(); a.autoplay = true; e080 a.loops = false; a.muted = e080 false; a.quantity = 1.0; a.pause e080 = false; a.controls = true;
  • e080

  • e080 Tried internet hosting this on e080 a public web site I e080 management and on an online e080 server on the native LAN.
  • e080

  • e080 Set Safari >> Settings for e080 [domain or IP address of e080 the web server] >> Permit e080 All Auto-Play. (With out that e080 set, there’s an error about e080 consumer interplay being required that e080 reveals up within the Javascript e080 console.)
  • e080

  • e080 Flushed the cache and reloaded e080 the web page.
  • e080

  • e080 Verified that the sound.mp3 file e080 is obtainable (an error message e080 is logged whether it is e080 lacking).
  • e080

  • e080 Verified that the sound.mp3 file e080 performs correctly when double-clicked (i.e., e080 it performs in Apple’s Music e080 app).
  • e080

e080

e080 Thanks prematurely for any strategies.

e080

e080

LEAVE A REPLY

Please enter your comment!
Please enter your name here