提交 d1e6044b authored 作者: 王鹏飞's avatar 王鹏飞

feat:增加连续播放功能

上级 b4d7d3e0
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
:video="chatperResources.video" :video="chatperResources.video"
@timeupdate="onTimeupdate" @timeupdate="onTimeupdate"
@ready="onReady" @ready="onReady"
@ended="onEnded"
ref="videoPlayer" ref="videoPlayer"
></video-player> ></video-player>
</div> </div>
...@@ -31,6 +32,7 @@ ...@@ -31,6 +32,7 @@
{{ $t('viewerPlayer.showPPT') }} {{ $t('viewerPlayer.showPPT') }}
</em> </em>
<em :class="skipClass" @click="toggleSkip">{{ $t('viewerPlayer.skipTitle') }}</em> <em :class="skipClass" @click="toggleSkip">{{ $t('viewerPlayer.skipTitle') }}</em>
<em :class="autoNextClass" @click="toggleAutoNext">{{ $t('viewerPlayer.autoNextTitle') }}</em>
</div> </div>
</div> </div>
</template> </template>
...@@ -48,6 +50,7 @@ export default { ...@@ -48,6 +50,7 @@ export default {
name: 'ChapterPlayer', name: 'ChapterPlayer',
components: { videoPlayer, pptPlayer }, components: { videoPlayer, pptPlayer },
props: { props: {
data: { type: Object },
// 当前章节 // 当前章节
chapter: { type: Object }, chapter: { type: Object },
// 是否是PPT播放跳转 // 是否是PPT播放跳转
...@@ -58,10 +61,13 @@ export default { ...@@ -58,10 +61,13 @@ export default {
data() { data() {
// 是否跳过片头 // 是否跳过片头
const isSkip = window.localStorage.getItem('isSkip') === 'true' const isSkip = window.localStorage.getItem('isSkip') === 'true'
// 是否连续播放
const isAutoNext = window.localStorage.getItem('isAutoNext') === 'true'
return { return {
videoVisible: true, videoVisible: true,
pptVisible: false, pptVisible: false,
isSkip, isSkip,
isAutoNext,
skipTime: 6, skipTime: 6,
chatperResources: null, chatperResources: null,
throttled: null, throttled: null,
...@@ -116,6 +122,27 @@ export default { ...@@ -116,6 +122,27 @@ export default {
'player-button-skip': !this.isSkip, 'player-button-skip': !this.isSkip,
'player-button-skip__active': this.isSkip 'player-button-skip__active': this.isSkip
} }
},
autoNextClass() {
return {
'player-button': true,
'player-button-skip': !this.isAutoNext,
'player-button-skip__active': this.isAutoNext
}
},
// 扁平章节数据
flatChapters() {
const chapters = this.data.chapters || []
return chapters.reduce((result, item) => {
return result.concat(item.children)
}, [])
},
nextChapter() {
const index = this.flatChapters.findIndex(item => item.id === this.chapter.id)
if (index !== -1) {
return this.flatChapters[index + 1]
}
return null
} }
}, },
methods: { methods: {
...@@ -129,6 +156,11 @@ export default { ...@@ -129,6 +156,11 @@ export default {
this.isSkip = !this.isSkip this.isSkip = !this.isSkip
window.localStorage.setItem('isSkip', this.isSkip) window.localStorage.setItem('isSkip', this.isSkip)
}, },
// 连续播放
toggleAutoNext() {
this.isAutoNext = !this.isAutoNext
window.localStorage.setItem('isAutoNext', this.isAutoNext)
},
// 关闭PPT // 关闭PPT
onPPTClose() { onPPTClose() {
this.pptVisible = false this.pptVisible = false
...@@ -150,6 +182,12 @@ export default { ...@@ -150,6 +182,12 @@ export default {
this.player.seek(this.progress.cpt) this.player.seek(this.progress.cpt)
} }
}, },
// 播放结束
onEnded() {
if (this.isAutoNext && this.nextChapter) {
this.$router.push({ name: 'viewerCourseChapter', params: { id: this.nextChapter.id } })
}
},
// 当前播放时间更新 // 当前播放时间更新
onTimeupdate(time) { onTimeupdate(time) {
time = Math.floor(time) time = Math.floor(time)
......
...@@ -62,6 +62,9 @@ export default { ...@@ -62,6 +62,9 @@ export default {
window.localStorage.setItem('videoRetry', 3) window.localStorage.setItem('videoRetry', 3)
} }
}) })
player.on('ended', function (event) {
_this.$emit('ended', event)
})
player.on('error', function (event) { player.on('error', function (event) {
_this.$emit('error', event) _this.$emit('error', event)
if (_this.videoRetry) { if (_this.videoRetry) {
......
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
downloadPPT: 'Download PPT', downloadPPT: 'Download PPT',
showPPT: 'Show PPT synchronously', showPPT: 'Show PPT synchronously',
skipTitle: 'Always skip titles', skipTitle: 'Always skip titles',
autoNextTitle: 'Continuous play',
pptSyncPlay: 'PPT synchronized video playback', pptSyncPlay: 'PPT synchronized video playback',
pptFullscreen: 'Zoom in PPT', pptFullscreen: 'Zoom in PPT',
pptPosition: 'Switch the video to the current PPT page', pptPosition: 'Switch the video to the current PPT page',
......
...@@ -16,6 +16,7 @@ export default { ...@@ -16,6 +16,7 @@ export default {
downloadPPT: '下载PPT', downloadPPT: '下载PPT',
showPPT: '同步显示PPT', showPPT: '同步显示PPT',
skipTitle: '始终跳过片头', skipTitle: '始终跳过片头',
autoNextTitle: '连续播放',
pptSyncPlay: 'PPT同步视频播放', pptSyncPlay: 'PPT同步视频播放',
pptFullscreen: '放大PPT', pptFullscreen: '放大PPT',
pptPosition: '切换视频到当前PPT页', pptPosition: '切换视频到当前PPT页',
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论