HTML5 Game - Manipulating the Audio Stream

Description

Manipulating the Audio Stream

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>
<audio>
    <source src="http://java2s.com/style/demo/your.ogg">
    <source src="http://java2s.com/style/demo/your.mp3">
</audio>/*w w  w. jav a  2s.  com*/
<button title="Play at 30 seconds" onclick="playAt(30);">30 seconds</button>
<button title="Stop Audio" onclick="stopAudio();">Stop Audio</button>
<script>
    function playAt(seconds){
        let audio = document.getElementsByTagName("audio")[0];
        audio.currentTime = seconds;
        audio.play();
    }
    function stopAudio(){
        let audio = document.getElementsByTagName("audio")[0];
        audio.currentTime = 0;
        audio.pause();
    }
</script>
</body>
</html>

Related Topic