javascript - How to play/pause sound and the sound play from the begininng of the sound? -
i want user able click on al link , sound start play if user click again on link stops , if again play sound strat beginning , nod whrere stop before. code simple toggle if sound:
var partone = document.getelementbyid("part1"); function playpart1() { return partone.paused ? partone.play() : partone.pause(); };
<p> <a class="textaudio" onclick="playpart1()"> lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit </a> </p> <audio id="part1" src="http://www.sousound.com/music/healing/healing_01.mp3" preload="auto"></audio>
you can use currenttime. make current time 0 -
var partone = document.getelementbyid("part1"); function playpart1() { partone.currenttime = 0 return partone.paused ? partone.play() : partone.pause(); };
<p> <a class="textaudio" onclick="playpart1()"> lorem ipsum dolor sit amet, consectetur adipiscing elit, sed eiusmod tempor incididunt ut labore et dolore magna aliqua. ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. duis aute irure dolor in reprehenderit </a> </p> <audio id="part1" src="http://www.sousound.com/music/healing/healing_01.mp3" preload="auto"></audio>
Comments
Post a Comment