image.png
    image.png
    image.png
    image.png

    使用DOM控制:

    1. <!DOCTYPE html>
    2. <html lang="en">
    3. <head>
    4. <meta charset="UTF-8">
    5. <meta name="viewport" content="width=device-width, initial-scale=1.0">
    6. <meta http-equiv="X-UA-Compatible" content="ie=edge">
    7. <title>Document</title>
    8. </head>
    9. <body>
    10. <div style="text-align: center;">
    11. <button onclick="playPause()">Play/Pause</button>
    12. <button onclick="makeBig()">Large</button>
    13. <button onclick="makeNormal()">Medium</button>
    14. <button onclick="makeSmall()">Small</button>
    15. <BR/>
    16. <div id="duration">
    17. </div>
    18. <video id="video1" width="420" style="margin-top:15px;">
    19. <source src="http://www.w3school.com.cn/example/html5/mov_bbb.mp4" type="video/mp4"/>
    20. <source src="http://www.w3school.com.cn/example/html5/mov_bbb.ogg" type="video/ogg"/>
    21. Your browser does not support html video label.
    22. </video>
    23. </div>
    24. <script>
    25. var myVideo = document.getElementById("video1");
    26. function playPause(){
    27. if (myVideo.paused){
    28. myVideo.play();
    29. }
    30. else {
    31. myVideo.pause();
    32. }
    33. }
    34. function makeBig(){
    35. myVideo.width = 560;
    36. }
    37. function makeNormal(){
    38. myVideo.width = 420;
    39. }
    40. function makeSmall(){
    41. myVideo.width = 320;
    42. }
    43. myVideo.addEventListener('loadedmetadata', function(){
    44. var length = myVideo.duration;
    45. var duration = document.getElementById('duration');
    46. duration.innerHTML = "The video's duration is " + length;
    47. });
    48. myVideo.addEventListener('play', function(e){
    49. console.log("Video is starting to play.");
    50. });
    51. // myVideo.addEventListener("loadstart",function(e){}); //客户端开始请求数据
    52. // myVideo.addEventListener("progress",function(e){}); //客户端正在请求数据
    53. // myVideo.addEventListener("suspend",function(e){}); //延迟下载
    54. // myVideo.addEventListener("abort",function(e){}); //客户端主动终止下载(不是因为错误引起)
    55. // myVideo.addEventListener("loadstart",function(e){}); //客户端开始请求数据
    56. // myVideo.addEventListener("progress",function(e){}); //客户端正在请求数据
    57. // myVideo.addEventListener("suspend",function(e){}); //延迟下载
    58. // myVideo.addEventListener("abort",function(e){}); //客户端主动终止下载(不是因为错误引起),
    59. // myVideo.addEventListener("error",function(e){}); //请求数据时遇到错误
    60. // myVideo.addEventListener("stalled",function(e){}); //网速失速
    61. // myVideo.addEventListener("play",function(e){}); //play()和autoplay开始播放时触发
    62. // myVideo.addEventListener("pause",function(e){}); //pause()触发
    63. // myVideo.addEventListener("loadedmetadata",function(e){}); //成功获取资源长度
    64. // myVideo.addEventListener("loadeddata",function(e){}); //
    65. // myVideo.addEventListener("waiting",function(e){}); //等待数据,并非错误
    66. // myVideo.addEventListener("playing",function(e){}); //开始回放
    67. // myVideo.addEventListener("canplay",function(e){}); //可以播放,但中途可能因为加载而暂停
    68. // myVideo.addEventListener("canplaythrough",function(e){}); //可以播放,歌曲全部加载完毕
    69. // myVideo.addEventListener("seeking",function(e){}); //寻找中
    70. // myVideo.addEventListener("seeked",function(e){}); //寻找完毕
    71. // myVideo.addEventListener("timeupdate",function(e){}); //播放时间改变
    72. // myVideo.addEventListener("ended",function(e){}); //播放结束
    73. // myVideo.addEventListener("ratechange",function(e){}); //播放速率改变
    74. // myVideo.addEventListener("durationchange",function(e){}); //资源长度改变
    75. // myVideo.addEventListener("volumechange",function(e){}); //音量改变
    76. </script>
    77. </body>
    78. </html>