admin管理员组文章数量:1401184
I have been trying to get this JavaScript to repeat the audio once it has finished, I have had a look around and I am inexperienced with JavaScript, although I have made attempts tweaking and researching I have had no luck so far.
I would be very grateful for any help and tips
Many thanks- Grant
<!-- Script inside body -->
<!-- Audio Player -->
<script>
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'music/audio.mp3');
audioElement.setAttribute('play', 'autoplay');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
audioElement.loop();
}, true);
$('.play').click(function() {
audioElement.play();
});
$('.pause').click(function() {
audioElement.pause();
});
});
</script>
<div class="play">Play</div>
<div class="pause">Stop</div>
I have been trying to get this JavaScript to repeat the audio once it has finished, I have had a look around and I am inexperienced with JavaScript, although I have made attempts tweaking and researching I have had no luck so far.
I would be very grateful for any help and tips
Many thanks- Grant
<!-- Script inside body -->
<!-- Audio Player -->
<script>
$(document).ready(function() {
var audioElement = document.createElement('audio');
audioElement.setAttribute('src', 'music/audio.mp3');
audioElement.setAttribute('play', 'autoplay');
//audioElement.load()
$.get();
audioElement.addEventListener("load", function() {
audioElement.play();
audioElement.loop();
}, true);
$('.play').click(function() {
audioElement.play();
});
$('.pause').click(function() {
audioElement.pause();
});
});
</script>
<div class="play">Play</div>
<div class="pause">Stop</div>
Share
Improve this question
asked Jul 26, 2013 at 20:18
GrantGrant
331 silver badge3 bronze badges
2 Answers
Reset to default 5Set loop property for repeat track:
audioElement.loop = true
Some browser doesn't support the loop propperty/attribute to audio. In this, you can add event listener instead like:
var myAudio = document.createElement('audio');
myAudio.setAttribute('src', 'test.mp3');
myAudio.play()
myAudio.addEventListener('ended', function() {
this.currentTime = 0;
this.play();
}, false);
本文标签: htmlJavascript Repeating AudioStack Overflow
版权声明:本文标题:html - Javascript Repeating Audio - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744271267a2598194.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论