1xptolevitico69

Audio/Video Onload

Dec 7th, 2019
175
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 2.39 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <title></title>
  5. <meta charset="utf-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9.  
  10.  
  11. #box {  
  12. position:absolute;
  13. top:10px;
  14. left:200px;  
  15. }
  16.  
  17. #box_audio {  
  18. position:absolute;
  19. top:100px;
  20. left:200px;
  21. display:none;  
  22. }
  23.  
  24. #play_audio {
  25. float:right;
  26. display:none;
  27. width:80px;
  28. height:80px;
  29. border-radius:50%;
  30. color:white;
  31. background-color:navy;
  32. outline:none;
  33. font-family:arial;
  34. font-weight:900;
  35. border:none;
  36. font-size:15px;
  37. cursor:pointer;  
  38. }
  39.  
  40. #pcent {  
  41. text-align:center;
  42. font-family:arial;
  43. font-size:40px;  
  44. }
  45.  
  46. #time {
  47. width:0;
  48. height:10px;
  49. background-color:red;
  50. display:inline-block;
  51. outline:none;
  52. border:none;
  53. position:absolute;
  54. top:300px;
  55. left:0px;  
  56. }
  57.  
  58. #timeline {
  59. width:0;
  60. height:10px;
  61. background-color:black;
  62. display:inline-block;
  63. outline:none;
  64. border:none;
  65. position:absolute;
  66. top:300px;
  67. left:0px;  
  68. }
  69.  
  70. .audio {  
  71. text-align:center;
  72. font-family:arial;
  73. font-size:90px;
  74. color:navy;  
  75. }
  76.  
  77.  
  78. </style>
  79. </head>
  80. <body>
  81.  
  82.  
  83. <div id='box'>
  84. <video id='video' autoplay muted controls>
  85. <source src='https://neanderthal-emergen.000webhostapp.com/video.mp4' type='video/mp4'>
  86. </video>
  87.  
  88. </div>
  89.  
  90.  
  91. <div id='box_audio'>
  92. <h1 class='audio'>Audio Mode</h1>
  93. <h1 id='pcent'></h1>
  94. <hr id='time'><br>
  95. <hr id='timeline'>
  96. </div>
  97.  
  98. <button onclick='hide_video()' id='play_audio'>Audio</button>
  99.  
  100.  
  101. <script>
  102.  
  103. i=0;
  104.  
  105.         // 100/video.duration ( 74.838 ) = 1.336    
  106.    //  video.onloadedmetadata = function() {  alert(video.duration);   }
  107.  
  108. video.style.width=74.838*13+'px';
  109. box_audio.style.width=74.838*13+'px';
  110.  
  111. onload=function(){
  112. video.play();
  113. time.style.width=74.838*13+'px';
  114. play_audio.style.display='block';
  115. }
  116.  
  117. video.ontimeupdate=function(){
  118. pcent.innerHTML=video.currentTime*1.336+'%';  
  119. timeline.style.width=video.currentTime*13+'px';
  120. if(video.currentTime>74.837){
  121. pcent.innerHTML='100%';
  122. video.pause();
  123. }
  124. }
  125.  
  126.  
  127. time.onclick=function(event){
  128.  var x = event.clientX-200;
  129.  video.currentTime=x/13;
  130. }
  131.  
  132. timeline.onclick=function(event){
  133.  var x = event.clientX-200;
  134.  video.currentTime=x/13;
  135. }
  136.  
  137. function hide_video() {
  138. if(i==0){i=1;
  139. video.style.display='none';
  140. play_audio.innerHTML='Video';
  141. box_audio.style.display='block';
  142. }else if(i=1){i=0;
  143. video.style.display='block';
  144. play_audio.innerHTML='Audio';
  145. box_audio.style.display='none';
  146. }
  147. }
  148.  
  149.  
  150. </script>
  151. </body>
  152. </html>
Add Comment
Please, Sign In to add comment