From b0aa1dc28a56e89897c57e16f2a08bb33391db8b Mon Sep 17 00:00:00 2001 From: buvta <12312540+buvta@users.noreply.github.com> Date: Sat, 5 Dec 2020 19:10:05 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=86=E9=A2=91=E5=A4=9A=E9=9B=86=E6=97=B6?= =?UTF-8?q?=E5=8F=AF=E9=80=9A=E8=BF=87=E5=BF=AB=E6=8D=B7=E9=94=AE=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E8=B7=B3=E8=BF=87=E7=89=87=E5=A4=B4=E7=89=87=E5=B0=BE?= =?UTF-8?q?=EF=BC=8C=E4=BF=9D=E5=AD=98=E5=9C=A8=E7=9B=B8=E5=BA=94=E7=9A=84?= =?UTF-8?q?=E5=8E=86=E5=8F=B2=E8=AE=B0=E5=BD=95=E4=B8=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/components/Play.vue | 86 +++++++++++++++++++++++++++++---------- src/lib/dexie/initData.js | 15 +++++++ 2 files changed, 80 insertions(+), 21 deletions(-) diff --git a/src/components/Play.vue b/src/components/Play.vue index a06d442..f00c13e 100644 --- a/src/components/Play.vue +++ b/src/components/Play.vue @@ -459,15 +459,21 @@ export default { this.playChannel(this.video.iptv) } else { this.channelListShow = false - const index = this.video.info.index | 0 + const index = this.video.info.index || 0 + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + const key = this.video.key + '@' + this.video.info.id var time = this.video.info.time - if (!time) { - // 如果video.info.time没有设定的话,从历史中读取时间进度 - const db = await history.find({ site: this.video.key, ids: this.video.info.id }) - if (db) { - if (db.index === index) { - time = db.time - } + if (db) { + if (!time && db.index === index) { // 如果video.info.time没有设定的话,从历史中读取时间进度 + time = db.time + } + if (!VIDEO_DETAIL_CACHE[key]) VIDEO_DETAIL_CACHE[key] = {} + this.xg.removeAllProgressDot() + if (db.startPosition) { + VIDEO_DETAIL_CACHE[key].startPosition = db.startPosition + } + if (db.endPosition) { + VIDEO_DETAIL_CACHE[key].endPosition = db.endPosition } } this.playVideo(index, time) @@ -514,21 +520,21 @@ export default { open(onlineUrl) } else { this.xg.src = m3u8Arr[index] - if (time !== 0) { - this.xg.play() - this.xg.once('playing', () => { - this.xg.currentTime = time - }) - } else { - this.xg.play() - } + const key = this.video.key + '@' + this.video.info.id + const startTime = VIDEO_DETAIL_CACHE[key].startPosition || 0 + this.xg.play() + this.xg.once('playing', () => { + this.xg.currentTime = time > startTime ? time : startTime + if (VIDEO_DETAIL_CACHE[key].startPosition) this.xg.addProgressDot(VIDEO_DETAIL_CACHE[key].startPosition, '片头') + if (VIDEO_DETAIL_CACHE[key].endPosition) this.xg.addProgressDot(this.xg.duration - VIDEO_DETAIL_CACHE[key].endPosition, '片尾') + }) this.videoPlaying() this.xg.once('ended', () => { if (m3u8Arr.length > 1 && (m3u8Arr.length - 1 > index)) { this.video.info.time = 0 this.video.info.index++ } - this.xg.off('ended') + if (!VIDEO_DETAIL_CACHE[key].endPosition) this.xg.off('ended') }) } }) @@ -536,7 +542,7 @@ export default { fetchM3u8List () { return new Promise((resolve) => { const cacheKey = this.video.key + '@' + this.video.info.id - if (VIDEO_DETAIL_CACHE[cacheKey]) { + if (VIDEO_DETAIL_CACHE[cacheKey] && VIDEO_DETAIL_CACHE[cacheKey].list) { this.name = VIDEO_DETAIL_CACHE[cacheKey].name resolve(VIDEO_DETAIL_CACHE[cacheKey].list) } @@ -559,10 +565,10 @@ export default { } } - VIDEO_DETAIL_CACHE[cacheKey] = { + VIDEO_DETAIL_CACHE[cacheKey] = Object.assign(VIDEO_DETAIL_CACHE[cacheKey] || {}, { list: m3u8Arr, name: res.name - } + }) resolve(m3u8Arr) }) }) @@ -603,6 +609,20 @@ export default { this.checkStar() this.checkTop() }, + async setProgressDotEvent (position, timespan, text) { + const key = this.video.key + '@' + this.video.info.id + const db = await history.find({ site: this.video.key, ids: this.video.info.id }) + if (db && this.xg && VIDEO_DETAIL_CACHE[key].list.length > 1) { + const positionTime = position === 'endPosition' ? this.xg.duration - timespan : timespan + if (db[position]) this.xg.removeProgressDot(position === 'endPosition' ? this.xg.duration - db[position] : db[position]) + this.xg.addProgressDot(positionTime, text) + const doc = { ...db } + doc[position] = timespan + delete doc.id + history.update(db.id, doc) + VIDEO_DETAIL_CACHE[key][position] = timespan + } + }, timerEvent () { this.timer = setInterval(async () => { const endTime = this.xg.duration @@ -971,7 +991,7 @@ export default { } }) }, - shortcutEvent (e) { + async shortcutEvent (e) { if (e === 'playAndPause') { if (this.xg) { if (this.xg.paused) { @@ -1063,6 +1083,20 @@ export default { } return false } + if (e === 'startPosition') { + this.setProgressDotEvent('startPosition', this.xg.currentTime, '片头') + return false + } + if (e === 'endPosition') { + this.setProgressDotEvent('endPosition', this.xg.duration - this.xg.currentTime, '片尾') + return false + } + if (e === 'clearPosition') { + await this.setProgressDotEvent('startPosition', 0) + await this.setProgressDotEvent('endPosition', 0) + this.xg.removeAllProgressDot() + return false + } if (e === 'opacityUp') { const num = win.getOpacity() if (num > 0.1) { @@ -1239,6 +1273,16 @@ export default { setting.find().then(res => { res.volume = this.config.volume; setting.update(res) }) }) + this.xg.on('timeupdate', () => { + const key = this.video.key + '@' + this.video.info.id + if (VIDEO_DETAIL_CACHE[key] && VIDEO_DETAIL_CACHE[key].endPosition) { + const time = this.xg.duration - VIDEO_DETAIL_CACHE[key].endPosition - this.xg.currentTime + if (time > 0 && time < 0.3) { + this.xg.emit('ended') + } + } + }) + this.xg.on('playNextOne', () => { this.nextEvent() }) diff --git a/src/lib/dexie/initData.js b/src/lib/dexie/initData.js index f7532d8..ed2b8d5 100644 --- a/src/lib/dexie/initData.js +++ b/src/lib/dexie/initData.js @@ -91,6 +91,21 @@ const localKey = [ desc: '跳到视频结束位置', key: 'end' }, + { + name: 'startPosition', + desc: '标记片头', + key: 'ctrl+home' + }, + { + name: 'endPosition', + desc: '标记片尾', + key: 'ctrl+end' + }, + { + name: 'clearPosition', + desc: '清除标记', + key: 'ctrl+del' + }, { name: 'opacityUp', desc: '透明度调高',