我想在后台播放我的网页上的声音文件(不希望出现媒体播放器 UI),我的网站将在 Fire-Fox 上运行,我使用了嵌入元素并设置了隐藏属性为 true
<embed name="myMusic" src="Masgon.mp3" type="audio/midi"
autostart="false" Hidden="true" loop="true"></embed>
问题是,除非我删除隐藏属性,否则不会播放声音,在这种情况下,声音文件会播放并且媒体播放器 UI 会出现,但我不希望这样。
<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>
如果你想要控制
<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>
并且还使用嵌入
<embed src="/music/good_enough.mp3" width="180" height="90" loop="false" autostart="false" hidden="true" />
<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>
对我来说效果很好。
虽然现在发表评论可能为时已晚,但这是针对像您这样的问题的工作代码。
<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>
<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。将“path/your_song.mp3”替换为文件夹和歌曲标题,例如。 “music/samplemusic.mp3”或“media/bgmusic.mp3”等
对我来说,通过删除
type
属性解决了问题:
<embed name="myMusic" loop="true" hidden="true" src="Music.mp3"></embed>
当然不是最干净的方法。
如果您使用的是 HTML5: Firefox 不支持 MP3。 Wav 和 Ogg 是。 您可以在这里找到哪些浏览器支持哪种类型的音频的概述: http://www.w3schools.com/html/html5_audio.asp
如果您不想显示控件,请尝试此代码
<audio autoplay>
<source src="song.ogg" type="audio/ogg">
Your browser does not support the audio element.
</audio>
如果你想要正常的:
<audio src="sus.mp3">
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>`
如果您希望它在加载时自动启动:(chrome 不支持)
<audio src="sus.mp3" autostart="true">
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>
如果你想要控制
<audio src="sus.mp3" autostart="true" controls>
<script>alert("Your browser doesn't support the Audio tag!")</script>
</audio>
非常有帮助,很好的一个如此简单的解决方案