HTML5 Game - Audio Playback Rate

Introduction

The playbackrate is the speed at which the audio/video is played.

The original speed is 1.0 and the rate is the multiplication of the initial speed.

If the playbackrate is set to 0.5, you get the audio or video played in slow motion.

If the rate is set to 1.5, the audio or video would be fast-forwarded.

Demo

ResultView the demo in separate window

<!DOCTYPE html>
<html>
  <head>
    <title>Chapter 3 - Playback Rate</title>
  </head>/*from w w  w .j  a  v a2s.c  om*/

  <body>
    <audio controls playbackrate="0.05">
        <source src='http://java2s.com/style/demo/your.ogg' type='audio/ogg; codecs=vorbis'>
         <source src='http://java2s.com/style/demo/your.mp3' type='audio/mpeg'>
    </audio>
    <script>
      let ele = document.querySelector('audio');

function slowMotion()  {
  ele.playbackrate = 0.5;
}

function fastForward()  {
  ele.playbackrate = 1.5;
}
      </script>
  </body>
</html>

Related Topic