302 lines
9.3 KiB
HTML
302 lines
9.3 KiB
HTML
<!--#
|
|
layout("/mobile/platform.html"){
|
|
#-->
|
|
|
|
<script src="https://cdn-go.cn/cdn/vod-js-sdk-v6/latest/vod-js-sdk-v6.js"></script>
|
|
<link href="https://web.sdk.qcloud.com/player/tcplayer/release/v4.3.0/tcplayer.min.css" rel="stylesheet"/>
|
|
<!--如果需要在 Chrome 和 Firefox 等现代浏览器中通过 H5 播放 HLS 格式的视频,需要在 tcplayer.vx.x.x.min.js 之前引入 hls.min.x.xx.xm.js。-->
|
|
<script src="https://web.sdk.qcloud.com/player/tcplayer/release/v4.3.0/libs/hls.min.0.13.2m.js"></script>
|
|
<!--播放器脚本文件-->
|
|
<script src="https://web.sdk.qcloud.com/player/tcplayer/release/v4.3.0/tcplayer.v4.3.0.min.js"></script>
|
|
|
|
<style>
|
|
#app {
|
|
background: #FFFFFF;
|
|
}
|
|
|
|
.video-container {
|
|
height: 300px;
|
|
}
|
|
|
|
#player-container-id {
|
|
width: 100%;
|
|
height: 300px;
|
|
}
|
|
|
|
.van-tabs__wrap {
|
|
border-bottom: 1px solid #ebedf0;
|
|
}
|
|
|
|
.van-tabs__content {
|
|
}
|
|
|
|
.album-description img {
|
|
background-size: contain;
|
|
width: 100%;
|
|
height: auto;
|
|
margin: 0 auto;
|
|
display: block;
|
|
}
|
|
|
|
.video-list .van-cell__value {
|
|
width: 50px;
|
|
flex: unset;
|
|
}
|
|
|
|
.video-list .van-cell__title {
|
|
overflow: hidden;
|
|
white-space: nowrap;
|
|
text-overflow: ellipsis;
|
|
}
|
|
|
|
.descriptionCell .van-cell__title {
|
|
width: 100%;
|
|
}
|
|
|
|
.descriptionCell p {
|
|
word-wrap: break-word;
|
|
word-break: break-all;
|
|
}
|
|
|
|
|
|
</style>
|
|
|
|
<div id="app" v-cloak>
|
|
<van-nav-bar
|
|
title=""
|
|
left-arrow
|
|
placeholder
|
|
fixed
|
|
@click-left="window.history.back()"
|
|
></van-nav-bar>
|
|
|
|
<div class="video-container">
|
|
<video v-if="isPlay" id="player-container-id" preload="auto" playsinline
|
|
webkit-playsinline>
|
|
</video>
|
|
|
|
<van-image
|
|
v-else
|
|
style="width: 100%;height: 100%"
|
|
:src="FILE_DOMAIN+'/fileStreamPreview?id='+albumInfo.cover"
|
|
></van-image>
|
|
|
|
</div>
|
|
|
|
<van-tabs v-model="tabIndex" sticky>
|
|
<van-tab title="介绍">
|
|
<div style="height: 5px;background-color: #f6f7f9"></div>
|
|
|
|
<div style="padding: 16px">
|
|
{{albumInfo.title}}
|
|
</div>
|
|
|
|
<div style="height: 5px;background-color: #f6f7f9"></div>
|
|
|
|
<van-cell class="descriptionCell">
|
|
<template #title>
|
|
<div style="font-size: 14px">课程介绍</div>
|
|
</template>
|
|
<template #label>
|
|
<div class="album-description" v-html="albumInfo.description"></div>
|
|
</template>
|
|
</van-cell>
|
|
|
|
</van-tab>
|
|
<van-tab title="目录">
|
|
<div style="height: 5px;background-color: #f6f7f9"></div>
|
|
|
|
<van-cell-group class="video-list">
|
|
<van-cell v-for="(o,i) in videoList" @click="playVideo(o)">
|
|
<template #title>
|
|
<van-tag plain type="primary" style="margin-right: 10px">视频</van-tag>
|
|
<span style="margin-right: 10px">
|
|
{{i+1}}.
|
|
</span>
|
|
<span>
|
|
{{o.title}}
|
|
</span>
|
|
</template>
|
|
<template #label>
|
|
{{getWatchStatus(o)}}
|
|
</template>
|
|
<template>
|
|
<span v-if="o.id === currentVideo.id">
|
|
播放中
|
|
</span>
|
|
</template>
|
|
</van-cell>
|
|
</van-cell-group>
|
|
</van-tab>
|
|
<!-- <van-tab title="评价">-->
|
|
<!-- <div style="height: 5px;background-color: #f6f7f9"></div>-->
|
|
<!-- <van-cell title="我的评价">-->
|
|
<!-- <template>-->
|
|
<!-- <van-rate v-model="myComment.level" icon="like" void-icon="like-o"></van-rate>-->
|
|
<!-- </template>-->
|
|
<!-- </van-cell>-->
|
|
<!-- </van-tab>-->
|
|
</van-tabs>
|
|
|
|
</div>
|
|
|
|
<script>
|
|
|
|
let player = null
|
|
|
|
var vue = new Vue({
|
|
el: '#app',
|
|
mixins: [mobileMixins],
|
|
data() {
|
|
return {
|
|
typeName: null,
|
|
videoTypeList: [],
|
|
albumId: null,
|
|
albumInfo: {},
|
|
videoList: [],
|
|
tabIndex: 0,
|
|
currentVideo: {},
|
|
myComment: {},
|
|
watchRecordList: [],
|
|
lastTime: 0,
|
|
isPlay: false
|
|
|
|
}
|
|
},
|
|
methods: {
|
|
async getVideoInfo() {
|
|
const {data} = await $.get('/mobile/trainEducation/getVideoList', {albumId: this.albumId})
|
|
this.videoList = data
|
|
|
|
},
|
|
async getAlbumInfo() {
|
|
const {data} = await $.get('/mobile/trainEducation/getAlbumInfo', {id: this.albumId})
|
|
this.albumInfo = data
|
|
},
|
|
//播放视频
|
|
async playVideo(o) {
|
|
this.isPlay = true
|
|
this.currentVideo = o
|
|
|
|
this.$nextTick(()=>{
|
|
if (!player) {
|
|
player = TCPlayer('player-container-id', {})
|
|
}
|
|
player.src(o.mediaUrl)
|
|
})
|
|
|
|
|
|
// await this.addWatchRecord()
|
|
await this.getMyWatchRecord()
|
|
|
|
//接着上次继续看
|
|
const v = this.watchRecordList.find(v => v.videoId === o.id)
|
|
if (v) {
|
|
this.lastTime = v.watchDuration
|
|
setTimeout(() => {
|
|
player.currentTime(v.watchDuration)
|
|
})
|
|
} else {
|
|
player.currentTime(0)
|
|
await this.addWatchRecord()
|
|
await this.getMyWatchRecord()
|
|
}
|
|
|
|
// player.play()
|
|
this.playPause()
|
|
this.playEnd()
|
|
this.playTimeUpdate()
|
|
this.playSeeked()
|
|
},
|
|
|
|
//快进 快退
|
|
playSeeked() {
|
|
player.on('seeked', () => {
|
|
this.lastTime = player.currentTime()
|
|
this.addWatchRecord()
|
|
})
|
|
},
|
|
playTimeUpdate() {
|
|
this.lastTime = player.currentTime()
|
|
player.on('timeupdate', () => {
|
|
const nowTime = player.currentTime()
|
|
if (nowTime - this.lastTime > 5) {
|
|
this.lastTime = nowTime
|
|
this.addWatchRecord()
|
|
}
|
|
})
|
|
},
|
|
playPause() {
|
|
player.on('pause', () => {
|
|
this.addWatchRecord()
|
|
})
|
|
},
|
|
|
|
playEnd() {
|
|
player.on('ended', () => {
|
|
this.addWatchRecord()
|
|
this.getMyWatchRecord()
|
|
const currentIndex = this.videoList.findIndex(v => v.id === this.currentVideo.id)
|
|
const nextVideo = this.videoList[currentIndex + 1]
|
|
if (nextVideo) {
|
|
this.playVideo(nextVideo)
|
|
}
|
|
})
|
|
},
|
|
|
|
//播放记录
|
|
async addWatchRecord() {
|
|
// if (player.currentTime() < 2) {
|
|
// return
|
|
// }
|
|
const params = {
|
|
videoId: this.currentVideo.id,
|
|
currentTime: parseInt(player.currentTime()),
|
|
albumId: this.currentVideo.albumId
|
|
}
|
|
await $.post('/mobile/trainEducation/addWatchRecord', params)
|
|
},
|
|
//监听页面关闭 隐藏
|
|
watchPage() {
|
|
document.addEventListener('visibilitychange', () => {
|
|
if (document.visibilityState === 'hidden') {
|
|
if (player && this.currentVideo) {
|
|
this.addWatchRecord()
|
|
}
|
|
}
|
|
})
|
|
},
|
|
async getMyWatchRecord() {
|
|
const {data} = await $.get('/mobile/trainEducation/getMyWatchRecord')
|
|
this.watchRecordList = data
|
|
},
|
|
getWatchStatus(video) {
|
|
const v = this.watchRecordList.find(v => v.videoId === video.id)
|
|
if (!v) {
|
|
return '学习进度:还未开始学习'
|
|
}
|
|
if (v.videoId === this.currentVideo.id) {
|
|
return '学习进度:正在学习中'
|
|
}
|
|
const percentage = (parseInt((v.watchDuration / (video.fileDuration - 1)).toFixed(2) * 100)) + "%"
|
|
return "学习进度:" + percentage
|
|
}
|
|
},
|
|
created() {
|
|
this.watchPage()
|
|
const id = this.GetQueryString("id")
|
|
if (id) {
|
|
this.albumId = id
|
|
this.getAlbumInfo()
|
|
this.getVideoInfo()
|
|
this.getMyWatchRecord()
|
|
}
|
|
|
|
}
|
|
})
|
|
</script>
|
|
|
|
<!--#
|
|
}
|
|
#-->
|