1xptolevitico69

Audio autoplay

Dec 3rd, 2021 (edited)
873
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <!DOCTYPE html>
  2. <html lang="en">
  3.  
  4. <head>
  5.   <meta charset="UTF-8">
  6.   <meta http-equiv="X-UA-Compatible" content="IE=edge">
  7.   <meta name="viewport" content="width=device-width, initial-scale=1.0">
  8.   <title>Audio autoplay</title>
  9.   <style>
  10.     #audio {
  11.       width: 80%;
  12.       border: 5px solid;
  13.       height: 30px;
  14.       background-color: rgba(128, 128, 128, 0.1);
  15.     }
  16.  
  17.     #bt {
  18.       display: block;
  19.       font-size: 20px;
  20.       font-family: verdana;
  21.       width: 150px;
  22.       border: none;
  23.       outline: none;
  24.       color: white;
  25.       background-color: red;
  26.       padding: 5px 0;
  27.     }
  28.  
  29.      a {
  30.       text-decoration: none;
  31.       font-size: 20px;
  32.       font-family: verdana;
  33.       color: white;
  34.       background-color: red;
  35.       padding: 5px 20px;
  36.       line-height: 50px;
  37.     }
  38.  
  39.  
  40.  
  41.  
  42.   </style>
  43. </head>
  44.  
  45. <body>
  46.  
  47.   <center>
  48.     <video autoplay muted controls id='audio'></video>
  49.     <button id='bt'>Unmute</button>
  50.     <a href='https://www.youtube.com/channel/UCI875fP1d6RdkZje7R-9ieQ'>YouTube Channel</a>
  51.   </center>
  52.  
  53.   <script>
  54.     arr = [
  55.       'https://nicebeats.netlify.app/audio.mp3',
  56.       '0.3',
  57.       '0.95',
  58.       '3.5'
  59.     ];
  60.  
  61.     audio.src = arr[0];
  62.     audio.volume = arr[1];
  63.     audio.playbackRate = arr[2];
  64.     audio.currentTime = arr[3];
  65.  
  66.     audio.onended = function() {
  67.       audio.currentTime = arr[3];
  68.       audio.play();
  69.     }
  70.  
  71.     def = 0;
  72.     audio.ontimeupdate = function() {
  73.       if (def == 0) {
  74.         audio.muted = true;
  75.       } else if (def == 1) {
  76.         audio.muted = false;
  77.       }
  78.     }
  79.  
  80.     bt.onclick = () => {
  81.       if (def == 0) {
  82.         def = 1;
  83.         bt.innerHTML = 'Mute';
  84.       } else if (def == 1) {
  85.         def = 0;
  86.         bt.innerHTML = 'Unmute';
  87.       }
  88.     }
  89.   </script>
  90. </body>
  91.  
  92. </html>
RAW Paste Data