Commit 36e22dc8 by wangshuo

学习进度一部分

parent 18d56a56
......@@ -80,6 +80,8 @@ class Video extends Component {
recordSocket
recordTimer
isCurrentVideoFirstPlay = true
state = {
title: '',
......@@ -341,21 +343,23 @@ class Video extends Component {
forceNew: true
})
// this.recordSocket = io(API.record)
this.recordSocket.on('seek', time => {
this.player.currentTime(time)
})
// this.recordSocket.on('seek', time => {
// this.player.currentTime(time)
// })
// 开启定时器 每5秒发送一次学习记录 --删除
this.recordTimer = setInterval(() => {
this.sendRecord()
}, 5000)
}
// 发送学习记录
sendRecord = () => {
if (this.recordSocket && this.player) {
this.recordSocket.emit('addRecord', this.recordUserInfo())
}
}
// 返回学习记录的数据
recordUserInfo = () => {
let {uid} = this.props.user.data
return {
......@@ -500,6 +504,7 @@ class Video extends Component {
}
// 初始化视频播放器
initializePlayer = () => {
window.HELP_IMPROVE_VIDEOJS = false;
this.player = videojs(this.video, {
......@@ -518,6 +523,22 @@ class Video extends Component {
this.player.on('ready', () => {
this.recordSocket.emit('load', this.recordUserInfo())
})
this.player.on('play', () => {
// 当视频播放时 看是否是第一次播放(初次进入页面 刷新页面 切换视频 都是第一次播放 需要获取上次的播放时间)
if(this.isCurrentVideoFirstPlay) {
this.ws.send(JSON.stringify({
mtype: 'recent_learn',
uid: this.props.user.data.uid,
token: this.token,
platform: 5,
video_id: videoList[activeIndex]['id'],
course_id: this.state.courseId,
v_course_id: vCourseId,
}))
// 当某些原因导致视频暂停时(用户暂停 网络不好等) 再播放时不需要发送
this.isCurrentVideoFirstPlay = false;
}
})
this.player.on('ratechange', () => {
this.currentPlaybackRate = this.player.playbackRate()
this.sendWatchTime(this.watchSec, this.previousPlaybackRate)
......@@ -558,6 +579,7 @@ class Video extends Component {
this.recordSocket = null
}
// 选择新的视频
selectVideo = index => {
if (index === this.state.activeIndex) {
return
......@@ -625,7 +647,6 @@ class Video extends Component {
let _this = this;
this.setupWS();
this.setupTimer();
console.log('playSetup');
let scheduleTime = setTimeout(function () {
clearTimeout(scheduleTime);
scheduleTime = null;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment