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
| <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <meta http-equiv="X-UA-Compatible" content="ie=edge"> <title>Document</title> <link rel="stylesheet" href="plyr/plyr.css"> <script src="plyr/plyr.min.js"></script> <script src="https://cdn.rawgit.com/video-dev/hls.js/18bb552/dist/hls.min.js"></script> </head> <body> <div class="container"> <video controls crossorigin playsinline poster="https://bitdash-a.akamaihd.net/content/sintel/poster.png"></video> </div> <script src="https://cdn.rawgit.com/video-dev/hls.js/18bb552/dist/hls.min.js"></script> <script> document.addEventListener('DOMContentLoaded', () => { const source = 'https://bitdash-a.akamaihd.net/content/sintel/hls/playlist.m3u8'; const video = document.querySelector('video'); const player = new Plyr(video, { captions: {active: true, update: true, language: 'en'} });
if (!Hls.isSupported()) { video.src = source; } else { const hls = new Hls(); hls.loadSource(source); hls.attachMedia(video); window.hls = hls; player.on('languagechange', () => { setTimeout(() => hls.subtitleTrack = player.currentTrack, 50); }); } window.player = player; }); </script>
</body> </html>
|