Advertisement
Guest User

Untitled

a guest
Feb 1st, 2019
232
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. // index.html
  2.  
  3. <!doctype html>
  4. <html>
  5. <body>
  6. <script>
  7. /**
  8. * La version propre, inactive
  9. */
  10. function play(videoId)
  11. {
  12. /*
  13. Ici, réinitialisation du squelette pour montrer que ça charge
  14. */
  15. var videosSrcs = [
  16. '',
  17. 'https://www.w3schools.com/html/mov_bbb.mp4',
  18. 'https://sample-videos.com/video123/mp4/360/big_buck_bunny_360p_1mb.mp4',
  19. 'http://techslides.com/demos/sample-videos/small.mp4'
  20. ];
  21. var iframe = document.getElementById('myIframe');
  22. var iframeDocument = iframe.contentDocument || iframe.contentWindow.document
  23. iframeDocument.getElementById('myVideo').src = videosSrcs[videoId];
  24. iframeDocument.getElementById('myVideo').play()
  25. /*
  26. Et là, tu as le temps de faire toutes les modifs que tu veux sur le reste de l'iframe.
  27. */
  28. }
  29.  
  30. /**
  31. * La version crade, mais qui fonctionne et ne demande quasiment pas de taf
  32. */
  33. function playQnD(videoId)
  34. {
  35. var iframe = document.getElementById('myIframe');
  36.  
  37. var request = new XMLHttpRequest();
  38. request.open('GET', './videos/' + videoId + '.html', false);
  39. request.send(null);
  40.  
  41. if (request.status === 200)
  42. {
  43. var iframe = document.getElementById('myIframe');
  44. var iframeDocument = iframe.contentDocument || iframe.contentWindow.document
  45.  
  46. iframeDocument.open();
  47. iframeDocument.write(request.responseText);
  48. iframeDocument.close();
  49.  
  50. iframeDocument.getElementById('myVideo').play()
  51. }
  52. }
  53.  
  54.  
  55. </script>
  56. <button onclick="playQnD(1);">Play 1</button>
  57. <button onclick="playQnD(2);">Play 2</button>
  58. <button onclick="playQnD(3);">Play 3</button>
  59. <iframe src="about:blank" id="myIframe" style="width:1000px; height:500px;"></iframe>
  60. </body>
  61. </html>
  62.  
  63.  
  64.  
  65. // Trois fichiers dans un sous-dossier "videos", pour tester
  66.  
  67. // videos/1.html
  68. <!doctype html>
  69. <html>
  70. <body>
  71. <video id="myVideo" src="https://www.w3schools.com/html/mov_bbb.mp4"></video>
  72. <button onclick="document.getElementById('myVideo').play()">Play</button>
  73. </body>
  74. <script>
  75. console.log('1.html loaded');
  76. </script>
  77. </html>
  78.  
  79.  
  80.  
  81. // videos/2.html
  82. <!doctype html>
  83. <html>
  84. <body>
  85. <video id="myVideo" src="https://sample-videos.com/video123/mp4/360/big_buck_bunny_360p_1mb.mp4"></video>
  86. <button onclick="document.getElementById('myVideo').play()">Play</button>
  87. </body>
  88. <script>
  89. console.log('2.html loaded');
  90. </script>
  91. </html>
  92.  
  93.  
  94.  
  95. // videos/3.html
  96. <!doctype html>
  97. <html>
  98. <body>
  99. <video id="myVideo" src="http://techslides.com/demos/sample-videos/small.mp4"></video>
  100. <button onclick="document.getElementById('myVideo').play()">Play</button>
  101. </body>
  102. <script>
  103. console.log('3.html loaded');
  104. </script>
  105. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement