|
@@ -20,6 +20,8 @@ export default {
|
|
|
},
|
|
},
|
|
|
data() {
|
|
data() {
|
|
|
return {
|
|
return {
|
|
|
|
|
+ wsClient: null,
|
|
|
|
|
+ intervalEvent: null,
|
|
|
flvjs,
|
|
flvjs,
|
|
|
DPlayer,
|
|
DPlayer,
|
|
|
danmaku: {
|
|
danmaku: {
|
|
@@ -43,12 +45,12 @@ export default {
|
|
|
getVideoUrl(videoId) {
|
|
getVideoUrl(videoId) {
|
|
|
videoUrl(videoId).then(res => {
|
|
videoUrl(videoId).then(res => {
|
|
|
if (res.code === 0) {
|
|
if (res.code === 0) {
|
|
|
- var event = false
|
|
|
|
|
|
|
+ var sendEvent = false
|
|
|
if (this.userToken != null) {
|
|
if (this.userToken != null) {
|
|
|
const wsUrl = 'ws:' + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + this.userToken
|
|
const wsUrl = 'ws:' + process.env.VUE_APP_SERVER_URL + '/ws/progress?token=' + this.userToken
|
|
|
this.wsClient = new SocketInstance(wsUrl)
|
|
this.wsClient = new SocketInstance(wsUrl)
|
|
|
this.wsClient.connect()
|
|
this.wsClient.connect()
|
|
|
- event = true
|
|
|
|
|
|
|
+ sendEvent = true
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
const urlType = res.data.type
|
|
const urlType = res.data.type
|
|
@@ -57,10 +59,10 @@ export default {
|
|
|
for (const url of urls) {
|
|
for (const url of urls) {
|
|
|
url.type = 'normal'
|
|
url.type = 'normal'
|
|
|
}
|
|
}
|
|
|
- this.initMp4Player(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, event)
|
|
|
|
|
|
|
+ this.initMp4Player(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, sendEvent)
|
|
|
} else if (urlType === 'flv') {
|
|
} else if (urlType === 'flv') {
|
|
|
const urls = res.data.urls
|
|
const urls = res.data.urls
|
|
|
- this.initFlvPlayer(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, event)
|
|
|
|
|
|
|
+ this.initFlvPlayer(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, sendEvent)
|
|
|
} else {
|
|
} else {
|
|
|
this.$notify.error({
|
|
this.$notify.error({
|
|
|
message: '视频 url 类型不合法',
|
|
message: '视频 url 类型不合法',
|
|
@@ -86,7 +88,7 @@ export default {
|
|
|
danmakuConfig() {
|
|
danmakuConfig() {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
},
|
|
},
|
|
|
- initMp4Player(userId, videoId, coverUrl, urls, pos, event) {
|
|
|
|
|
|
|
+ initMp4Player(userId, videoId, coverUrl, urls, pos, sendEvent) {
|
|
|
const player = new DPlayer({
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
@@ -115,35 +117,44 @@ export default {
|
|
|
// 跳转到上次看到的位置
|
|
// 跳转到上次看到的位置
|
|
|
player.seek(pos)
|
|
player.seek(pos)
|
|
|
|
|
|
|
|
|
|
+ var ended = false
|
|
|
/* 事件绑定 */
|
|
/* 事件绑定 */
|
|
|
- player.on('progress', function() {
|
|
|
|
|
- if (event) {
|
|
|
|
|
- const payload = {}
|
|
|
|
|
- payload.mediaId = videoId
|
|
|
|
|
- payload.mediaType = 1
|
|
|
|
|
- payload.currentTime = player.video.currentTime
|
|
|
|
|
- payload.ended = false
|
|
|
|
|
-
|
|
|
|
|
- const jsonData = {}
|
|
|
|
|
- jsonData.event = 'progress'
|
|
|
|
|
- jsonData.payload = JSON.stringify(payload)
|
|
|
|
|
- this.wsClient.send(jsonData)
|
|
|
|
|
|
|
+ const that = this
|
|
|
|
|
+ player.on('play', function() {
|
|
|
|
|
+ if (sendEvent) {
|
|
|
|
|
+ clearInterval(that.intervalEvent)
|
|
|
|
|
+ that.intervalEvent = setInterval(() => {
|
|
|
|
|
+ if (!ended) {
|
|
|
|
|
+ const payload = {}
|
|
|
|
|
+ payload.mediaId = videoId
|
|
|
|
|
+ payload.mediaType = 1
|
|
|
|
|
+ payload.currentTime = player.video.currentTime
|
|
|
|
|
+ payload.ended = ended
|
|
|
|
|
+
|
|
|
|
|
+ const jsonData = {}
|
|
|
|
|
+ jsonData.event = 'media_progress'
|
|
|
|
|
+ jsonData.payload = JSON.stringify(payload)
|
|
|
|
|
+
|
|
|
|
|
+ that.wsClient.send(jsonData)
|
|
|
|
|
+ }
|
|
|
|
|
+ }, 5000)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
player.on('ended', () => {
|
|
player.on('ended', () => {
|
|
|
- if (event) {
|
|
|
|
|
|
|
+ clearInterval(that.intervalEvent)
|
|
|
|
|
+ ended = true
|
|
|
|
|
+ if (sendEvent) {
|
|
|
const payload = {}
|
|
const payload = {}
|
|
|
payload.mediaId = videoId
|
|
payload.mediaId = videoId
|
|
|
payload.mediaType = 1
|
|
payload.mediaType = 1
|
|
|
payload.currentTime = player.video.currentTime
|
|
payload.currentTime = player.video.currentTime
|
|
|
- payload.ended = true
|
|
|
|
|
|
|
+ payload.ended = ended
|
|
|
|
|
|
|
|
const jsonData = {}
|
|
const jsonData = {}
|
|
|
- jsonData.event = 'progress'
|
|
|
|
|
|
|
+ jsonData.event = 'media_progress'
|
|
|
jsonData.payload = JSON.stringify(payload)
|
|
jsonData.payload = JSON.stringify(payload)
|
|
|
- console.log(jsonData)
|
|
|
|
|
- this.wsClient.send(jsonData)
|
|
|
|
|
|
|
+
|
|
|
|
|
+ that.wsClient.send(jsonData)
|
|
|
}
|
|
}
|
|
|
})
|
|
})
|
|
|
|
|
|
|
@@ -151,7 +162,7 @@ export default {
|
|
|
console.log('声音改变')
|
|
console.log('声音改变')
|
|
|
})
|
|
})
|
|
|
},
|
|
},
|
|
|
- initFlvPlayer(userId, videoId, coverUrl, urls, pos, event) {
|
|
|
|
|
|
|
+ initFlvPlayer(userId, videoId, coverUrl, urls, pos, sendEvent) {
|
|
|
const player = new DPlayer({
|
|
const player = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
container: document.getElementById('dplayer'),
|
|
|
lang: 'zh-cn',
|
|
lang: 'zh-cn',
|
|
@@ -180,38 +191,9 @@ export default {
|
|
|
|
|
|
|
|
// 跳转到上次看到的位置
|
|
// 跳转到上次看到的位置
|
|
|
player.seek(pos)
|
|
player.seek(pos)
|
|
|
-
|
|
|
|
|
/* 事件绑定 */
|
|
/* 事件绑定 */
|
|
|
- player.on('progress', function() {
|
|
|
|
|
- if (event) {
|
|
|
|
|
- const payload = {}
|
|
|
|
|
- payload.mediaId = videoId
|
|
|
|
|
- payload.mediaType = 1
|
|
|
|
|
- payload.currentTime = player.video.currentTime
|
|
|
|
|
- payload.ended = false
|
|
|
|
|
-
|
|
|
|
|
- const jsonData = {}
|
|
|
|
|
- jsonData.event = 'progress'
|
|
|
|
|
- jsonData.payload = JSON.stringify(payload)
|
|
|
|
|
- this.wsClient.send(jsonData)
|
|
|
|
|
- }
|
|
|
|
|
- })
|
|
|
|
|
-
|
|
|
|
|
player.on('ended', () => {
|
|
player.on('ended', () => {
|
|
|
- if (event) {
|
|
|
|
|
- const payload = {}
|
|
|
|
|
- payload.mediaId = videoId
|
|
|
|
|
- payload.mediaType = 1
|
|
|
|
|
- payload.currentTime = player.video.currentTime
|
|
|
|
|
- payload.ended = true
|
|
|
|
|
-
|
|
|
|
|
- const jsonData = {}
|
|
|
|
|
- jsonData.event = 'progress'
|
|
|
|
|
- jsonData.payload = JSON.stringify(payload)
|
|
|
|
|
- this.wsClient.send(jsonData)
|
|
|
|
|
- }
|
|
|
|
|
})
|
|
})
|
|
|
-
|
|
|
|
|
player.on('volumechange', () => {
|
|
player.on('volumechange', () => {
|
|
|
console.log('声音改变')
|
|
console.log('声音改变')
|
|
|
})
|
|
})
|