Advertisement
1xptolevitico69

Video ontimeupdate. Video currentTime/duration

Jun 4th, 2019
224
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 1.20 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <title></title>
  5. <meta charset="UTF-8">
  6. <meta name="viewport" content="width=device-width">
  7. <style>
  8.  
  9.    #vid {  width:700px;margin:auto;     }
  10.    #p {   font-size:40px;     }
  11.    #vid_ct {  font-size:30px;   }
  12.    *{  font-family:segoe script;font-weight:bold;text-align:center;     }
  13.    #p_ {    font-size:40px;margin-top:-35px;     }
  14.  
  15. </style>
  16. </head>
  17.  
  18.   <!-- We don't set any style to poster.The image(poster)must
  19.                 have the same ratio the video has.In this case 16/9.
  20.       For each 16px width 9px height.We don't set height to the video,
  21.    only width. Autoplay no longer runs.To start video needs a click. -->
  22.  
  23. <body>
  24.  
  25. <video id="vid" poster='video poster.png' controls>
  26.  <source src='D:\STUFF\Mp4\ACDC - Rock N Roll Train (from Live at River Plate).mp4' type='video/mp4'>
  27.  </video>
  28.  
  29. <p id='p'>Video currentTime = <span id='vid_ct'></span></p>
  30. <p id='p_'>Video duration = <span id='vid_d'></span></p>
  31.  
  32. <script>
  33.  
  34. onload=()=>{
  35. vid_ct.innerHTML = vid.currentTime;
  36. vid_d.innerHTML = vid.duration;
  37. }
  38.  
  39. vid.ontimeupdate=function(){
  40. vid_ct.innerHTML = vid.currentTime;
  41. if(vid.currentTime > 50){
  42. vid.pause();
  43. }
  44. }
  45.  
  46. </script>
  47. </body>
  48. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement