Commit 36e22dc8 by wangshuo

学习进度一部分

parent 18d56a56
...@@ -80,6 +80,8 @@ class Video extends Component { ...@@ -80,6 +80,8 @@ class Video extends Component {
recordSocket recordSocket
recordTimer recordTimer
isCurrentVideoFirstPlay = true
state = { state = {
title: '', title: '',
...@@ -341,21 +343,23 @@ class Video extends Component { ...@@ -341,21 +343,23 @@ class Video extends Component {
forceNew: true forceNew: true
}) })
// this.recordSocket = io(API.record) // this.recordSocket = io(API.record)
this.recordSocket.on('seek', time => { // this.recordSocket.on('seek', time => {
this.player.currentTime(time) // this.player.currentTime(time)
}) // })
// 开启定时器 每5秒发送一次学习记录 --删除
this.recordTimer = setInterval(() => { this.recordTimer = setInterval(() => {
this.sendRecord() this.sendRecord()
}, 5000) }, 5000)
} }
// 发送学习记录
sendRecord = () => { sendRecord = () => {
if (this.recordSocket && this.player) { if (this.recordSocket && this.player) {
this.recordSocket.emit('addRecord', this.recordUserInfo()) this.recordSocket.emit('addRecord', this.recordUserInfo())
} }
} }
// 返回学习记录的数据
recordUserInfo = () => { recordUserInfo = () => {
let {uid} = this.props.user.data let {uid} = this.props.user.data
return { return {
...@@ -500,6 +504,7 @@ class Video extends Component { ...@@ -500,6 +504,7 @@ class Video extends Component {
} }
// 初始化视频播放器
initializePlayer = () => { initializePlayer = () => {
window.HELP_IMPROVE_VIDEOJS = false; window.HELP_IMPROVE_VIDEOJS = false;
this.player = videojs(this.video, { this.player = videojs(this.video, {
...@@ -518,6 +523,22 @@ class Video extends Component { ...@@ -518,6 +523,22 @@ class Video extends Component {
this.player.on('ready', () => { this.player.on('ready', () => {
this.recordSocket.emit('load', this.recordUserInfo()) 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.player.on('ratechange', () => {
this.currentPlaybackRate = this.player.playbackRate() this.currentPlaybackRate = this.player.playbackRate()
this.sendWatchTime(this.watchSec, this.previousPlaybackRate) this.sendWatchTime(this.watchSec, this.previousPlaybackRate)
...@@ -558,6 +579,7 @@ class Video extends Component { ...@@ -558,6 +579,7 @@ class Video extends Component {
this.recordSocket = null this.recordSocket = null
} }
// 选择新的视频
selectVideo = index => { selectVideo = index => {
if (index === this.state.activeIndex) { if (index === this.state.activeIndex) {
return return
...@@ -625,7 +647,6 @@ class Video extends Component { ...@@ -625,7 +647,6 @@ class Video extends Component {
let _this = this; let _this = this;
this.setupWS(); this.setupWS();
this.setupTimer(); this.setupTimer();
console.log('playSetup');
let scheduleTime = setTimeout(function () { let scheduleTime = setTimeout(function () {
clearTimeout(scheduleTime); clearTimeout(scheduleTime);
scheduleTime = null; 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