1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111
| <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>树莓派-Live</title> <link href="https://unpkg.com/video.js/dist/video-js.min.css" rel="stylesheet"> <script src="https://unpkg.com/video.js/dist/video.min.js"></script> <style> #roomVideo { margin: 0 auto; width: 600px; height: 400px; } </style> </head> <body> <video-js id="roomVideo" controls class="video-js vjs-default-skin vjs-big-play-centered" x-webkit-airplay="allow" poster="" webkit-playsinline playsinline x5-video-player-type="h5" x5-video-player-fullscreen="true" preload="auto"> <source src="https://live.bfsdfs.com/live/stream.m3u8" type="application/x-mpegURL"> <p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p> </video-js> <script> var vid = document.getElementById('roomVideo'); var player = videojs(vid, { bigPlayButton: true, textTrackDisplay: true, posterImage: true, errorDisplay: true, controlBar: true }, function () { console.log(this) this.on('loadedmetadata', function () { console.log('loadedmetadata'); startVideo(); })
this.on('ended', function () { console.log('ended') }) this.on('firstplay', function () { console.log('firstplay') }) this.on('loadstart', function () { console.log('loadstart') }) this.on('loadeddata', function () { console.log('loadeddata') }) this.on('seeking', function () { console.log('seeking') }) this.on('seeked', function () { console.log('seeked') }) this.on('waiting', function () { console.log('waiting') }) this.on('pause', function () { console.log('pause') }) this.on('play', function () { console.log('play') }) }); var isVideoBreak; function startVideo() { player.play(); var lastTime = -1, tryTimes = 0; clearInterval(isVideoBreak); isVideoBreak = setInterval(function () { var currentTime = player.currentTime(); console.log('currentTime' + currentTime + 'lastTime' + lastTime); if (currentTime == lastTime) { player.currentTime(currentTime + 10000); player.play(); if (++tryTimes > 5) { alert('您的网速有点慢,刷新下试试'); tryTimes = 0; } } else { lastTime = currentTime; tryTimes = 0; } }, 3000) } </script> </body> </html>
|