jQuery to autoplay HTML5 audio

Ok, so let me tell you where I'm at. The audio file displays and loads. you can click play to play it. The jQuery isn't autoplaying the material. I'm having to load in the file based on the href of the link. Code is below. Trying to get this to autoplay.

            $('.voiceLink a', resbox).click(function(e){
                e.preventDefault();
                var link = $(this).prop('href'),
                    audio = $('.audioControl', el.parent());

                audio.find('source').prop('src', link);
                audio.parent().css('display','inline-block');
                audio.find('audio').load();
                setTimeout(audio.find('audio').play(), 100);

                $(window).scrollTop();
            });

resbox = The wrapper box.

The HTML Element:

<div class="audioHide" style="display: none;">
                <div class="audioControl" style="position:relative; top:10px; left:50px; display:inline-block;">
                    <audio controls><source src="#" type="audio/mpeg">
                        Not Supported
                    </audio>
                </div>
                </div>

Example Link:

<a target="_blank" href="http://relatientsounds.s3-website-us-east-1.amazonaws.com/recordings/2456266.mp3">2456266</a>

Edit

try this

audio.find('source').prop('src', link);
audio.parent().css('display','inline-block');
audio.find('audio').load();
//this line
audio.find('audio')[0].play();

Demo http://jsfiddle.net/m25kfy57/1/

链接地址: http://www.djcxy.com/p/71146.html

上一篇: 自动播放上的html5音频播放器无法正常工作

下一篇: jQuery自动播放HTML5音频