From 855472fe68dc683ba88765ac34b3715f00208cc7 Mon Sep 17 00:00:00 2001 From: buvta <12312540+buvta@users.noreply.github.com> Date: Tue, 29 Dec 2020 00:50:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dmp4=E5=81=9C=E6=AD=A2?= =?UTF-8?q?=E5=90=8E=E7=82=B9=E5=87=BB=E6=92=AD=E6=94=BE=E6=8C=89=E9=92=AE?= =?UTF-8?q?=E6=97=A0=E6=B3=95=E6=92=AD=E6=94=BE,=E5=B9=B6=E5=BC=95?= =?UTF-8?q?=E5=85=A5xgplayer-flv.js?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- package.json | 1 + src/components/Play.vue | 50 ++++++++++++++++++++--------------------- 2 files changed, 25 insertions(+), 26 deletions(-) diff --git a/package.json b/package.json index e2f57ad..bb00385 100644 --- a/package.json +++ b/package.json @@ -45,6 +45,7 @@ "vuedraggable": "^2.24.3", "vuex": "^3.6.0", "xgplayer": "^2.16.0", + "xgplayer-flv.js": "^2.1.2", "xgplayer-hls.js": "^2.3.0", "xgplayer-mp4": "^1.2.0" }, diff --git a/src/components/Play.vue b/src/components/Play.vue index 41dbb1f..cc0c23f 100644 --- a/src/components/Play.vue +++ b/src/components/Play.vue @@ -246,6 +246,7 @@ import { star, history, setting, shortcut, mini, channelList, sites } from '../l import zy from '../lib/site/tools' import Player from 'xgplayer' import HlsJsPlayer from 'xgplayer-hls.js' +import FlvJsPlayer from 'xgplayer-flv.js' import 'xgplayer-mp4' import mt from 'mousetrap' import Clickoutside from 'element-ui/src/utils/clickoutside' @@ -588,6 +589,25 @@ export default { document.querySelector('xg-btn-showhistory').style.display = 'none' document.querySelector('.xgplayer-playbackrate').style.display = 'none' }, + getPlayer (playerType) { + this.xg.src = '' + this.config.url = '' + this.xg.destroy() + this.xg = null + switch (playerType) { + case 'mp4': + this.xg = new Player(this.config) + break + case 'flv': + this.xg = new FlvJsPlayer(this.config) + break + default: + this.xg = new HlsJsPlayer(this.config) + } + this.playerInstall() + this.bindEvent() + this.playerType = playerType + }, playVideo (index = 0, time = 0) { this.isLive = false this.fetchPlaylist().then(async (playlistUrls) => { @@ -602,23 +622,9 @@ export default { return } if (url.endsWith('.mp4') && this.playerType !== 'mp4') { - this.xg.src = '' - this.config.url = '' - this.xg.destroy() - this.xg = null - this.xg = new Player(this.config) - this.playerInstall() - this.bindEvent() - this.playerType = 'mp4' + this.getPlayer('mp4') } else if (url.endsWith('.m3u8') && this.playerType !== 'hls') { - this.xg.src = '' - this.config.url = '' - this.xg.destroy() - this.xg = null - this.xg = new HlsJsPlayer(this.config) - this.playerInstall() - this.bindEvent() - this.playerType = 'hls' + this.getPlayer('hls') } this.xg.src = url const key = this.video.key + '@' + this.video.info.id @@ -694,7 +700,7 @@ export default { time: time, detail: this.video.detail } - history.add(doc) + await history.add(doc) this.updateStar() this.timerEvent() }, @@ -1484,21 +1490,13 @@ export default { } clearInterval(this.timer) this.video.key = '' - this.xg.src = '' - this.config.url = '' - this.xg.destroy() - this.xg = null this.name = '' this.isLive = false this.state.showChannelList = true this.state.showTimespanSetting = false this.right.list = [] this.getAllhistory() - setTimeout(() => { - this.xg = new HlsJsPlayer(this.config) - this.playerInstall() - this.bindEvent() - }, 100) + this.getPlayer(this.playerType) }, minMaxEvent () { win.on('minimize', () => {