Html 在后台播放网页中的声音文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13402336/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 03:53:40  来源:igfitidea点击:

Play sound file in a web-page in the background

htmlfirefox

提问by Java Player

I want to play a sound file on my web-page in the back-ground(don't want Media player UI to appear), my web-site will run on Fire-Fox, i used the Embed element and set the Hidden attribute to be true <embed name="myMusic" src="Masgon.mp3" type="audio/midi" autostart="false" Hidden="true" loop="true"></embed>the problem is that no sound is played unless i removed the hidden attribute on this case the sound file is played and the media player UI appears but i don't want that.

我想在后台的网页上播放声音文件(不希望出现媒体播放器 UI),我的网站将在 Fire-Fox 上运行,我使用了 Embed 元素并设置了 Hidden 属性是真的<embed name="myMusic" src="Masgon.mp3" type="audio/midi" autostart="false" Hidden="true" loop="true"></embed>,问题是除非我在这种情况下删除隐藏属性,否则不会播放声音,播放声音文件并出现媒体播放器用户界面,但我不想要那样。

回答by topcat3

<audio src="/music/good_enough.mp3">
<p>If you are reading this, it is because your browser does not support the audio element.     </p>
</audio>

and if you want the controls

如果你想要控制

<audio src="/music/good_enough.mp3" controls>
<p>If you are reading this, it is because your browser does not support the audio element.</p>
</audio>

and also using embed

并且还使用嵌入

<embed src="/music/good_enough.mp3" width="180" height="90" loop="false" autostart="false" hidden="true" />

回答by Adrian

<audio src="/music/good_enough.mp3" autoplay>
<p>If you are reading this, it is because your browser does not support the audio element.     </p>
<embed src="/music/good_enough.mp3" width="180" height="90" hidden="true" />
</audio>

Works for me just fine.

对我来说很好用。

回答by Akash Adhikari

Though this might be too late to comment but here's the working code for problems such as yours.

虽然这可能为时已晚发表评论,但这里是诸如您的问题的工作代码。

<div id="player">
    <audio autoplay hidden>
     <source src="link/to/file/file.mp3" type="audio/mpeg">
                If you're reading this, audio isn't supported. 
    </audio>
</div>

回答by Arya Aryadipta Sur Tabs

<audio controls autoplay loop>
  <source src="path/your_song.mp3" type="audio/ogg">
  <embed src="path/your_song.mp3" autostart="true" loop="true" hidden="true"> 
</audio>

[ps. replace the "path/your_song.mp3" with the folder and the song title eg. "music/samplemusic.mp3" or "media/bgmusic.mp3" etc.

[ps。将“path/your_song.mp3”替换为文件夹和歌曲名称,例如。“music/samplemusic.mp3”或“media/bgmusic.mp3”等。

回答by jins

If you don't want to show controls then try this code

如果您不想显示控件,请尝试使用此代码

<audio  autoplay>
 <source src="song.ogg"  type="audio/ogg">
Your browser does not support the audio element.
</audio>

回答by Robin V.

With me the problem was solved by removing the typeattribute:

对我来说,通过删除type属性解决了问题:

<embed name="myMusic" loop="true" hidden="true" src="Music.mp3"></embed>

Cerntainly not the cleanest way.

当然不是最干净的方式。

If you're using HTML5: MP3 isn't supported by Firefox. Wav and Ogg are though. Here you can find an overview of which browser support which type of audio: http://www.w3schools.com/html/html5_audio.asp

如果您使用的是 HTML5:Firefox 不支持 MP3。Wav 和 Ogg 是虽然。在这里您可以找到哪种浏览器支持哪种音频类型的概述:http: //www.w3schools.com/html/html5_audio.asp