Playing sound on my website

2019-02-22 22:10发布

问题:

I use a code to play background music on my website..

<embed src="1.wav" autostart="true" loop="true"
width="2" height="0">
</embed>

But this code does not play infinite looped music.. Once the sound track gets over it does no repeat.. What should i do to repeat the music again and again..

回答1:

The HTML5 solution is the Audio tag http://www.w3schools.com/tags/tag_audio.asp

This is the older solution: http://drayblog.gotdns.com/index.php/2009/05/13/html-embed-an-audio-clip-and-repeat-loop-it/

<EMBED SRC="/audio/media.mp3" AUTOSTART="true" HIDDEN="True" LOOP="True"/>
<NOEMBED>
    <object type="audio/mp3" data="http://www.domain.com/audio/media.mp3"><param name="src" value="http://www.domain.com/audio/media.mp3"></param><param name="autostart" value="true"></param><param name="hidden" value="True"></param><param name="loop" value="true"></param>
    </object>
</NOEMBED>


回答2:

This is what I have found to work the best... Just replace the 'yoursounds' with the actual file name of your chosing.

<audio autoplay loop controls>
    <source src="yoursound.ogg">
    <source src="yoursound.mp3">
</audio>


回答3:

Instead of loop='true' try with loop='infinite' as below

<embed src="1.wav" autostart="true" loop="infinite"
width="2" height="0">
</embed>


回答4:

Try jPlayer. It's an html5 media player that will fallback on flash. Here's an example from one of the demos:

$("#jquery_jplayer_1").jPlayer({
    ready: function () {
        $(this).jPlayer("setMedia", {
            m4a:"http://www.jplayer.org/audio/m4a/TSP-01-Cro_magnon_man.m4a",
            oga:"http://www.jplayer.org/audio/ogg/TSP-01-Cro_magnon_man.ogg"
        });
    },
    swfPath: "../js",
    solution: "flash, html",
    supplied: "m4a, oga",
    wmode: "window"
});

<div id="jquery_jplayer_1" class="jp-jplayer"></div>

http://jplayer.org/latest/demo-01-solution-flash-html/



回答5:

Try using the audio tag instead:

<audio autoplay loop>
    <source src="sound.ogg">
    <source src="sound.mp3"> 
</audio>

You need to use both mp3 and ogg files to be able to play your sound correctly in all browsers. Firefox for instance does not support mp3 files. Also using .wav is on websites is severely frowned upon due to its size.



回答6:

<audio hidden="true" autoplay loop controls>
    <source src="source.mp3">
</audio>

it will works fine as you want...



标签: html embed