Plyr轻量级H5 Web播放器 - Demo JS
- const source = 'https://xxx.com/2023/index.M3U8';//视频地址
- const video = document.querySelector('video');
- const player = new Plyr(video, {
- autoplay: false,
- volume: 1,
- ratio: '16:9',
- preload: 'auto',
- speed: {
- selected: 1,
- options: [0.5, 1, 1.5, 2]
- },
- fullscreen: {
- enabled: true,
- fallback: true,
- iosNative: true,
- },
- captions: {
- active: true,
- update: false,
- language: 'auto'
- },
- i18n: {
- restart: '重播',
- play: '播放',
- pause: '暂停',
- volume: '音量',
- mute: '静音',
- pip: '画中画',
- normal: '默认',
- quality: '画质',
- download: '下载',
- enterFullscreen: '全屏',
- exitFullscreen: '关闭全屏',
- captions: 'Captions',
- settings: '设置',
- speed: '倍速',
- loop: '循环播放',
- },
- });
- if(source.indexOf('.M3U8')>-1){
- 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;
复制代码
|