简体   繁体   English

index.html 可以播放音频文件吗? 如果是这样,我如何实现它在后台自动播放?

[英]Can index.html play an audio file? If so, How can I implement it to auto play in the back ground?

Ive tried this in my code and cant seem to make it work.我已经在我的代码中尝试过这个,但似乎无法让它工作。

<body>
  <div id='container'>
    <canvas id='game' width='320' height='480'></canvas>
  </div>
  <p>HTML background music test</p>
     <embed src="music/alien-spaceship_daniel_simion.mp3" autostart="true">
  <script src='Scripts/engine.js'></script>
  <script src='Scripts/game.js'></script>
</body>

These sorts of embeds are discouraged these days, as they are not supported on all systems.现在不鼓励使用这些类型的嵌入,因为并非所有系统都支持它们。 Additionally, each plugin often had its own distinct API.此外,每个插件通常都有自己独特的 API。 You should use an <audio> tag instead.您应该改用<audio>标签。

<audio src="music/alien-spaceship_daniel_simion.mp3" controls autoplay />

Note however that autoplay doesn't typically work anymore, thanks to excessive abuse of the feature, and subsequent browser policies .但是请注意,由于过度滥用该功能以及随后的浏览器策略autoplay通常不再起作用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM