|
|
@@ -41,9 +41,11 @@ export default {
|
|
|
getVideoUrl(videoId) {
|
|
|
videoUrl(videoId).then(res => {
|
|
|
if (res.code === 0) {
|
|
|
+ var event = false
|
|
|
const token = getAccessToken()
|
|
|
if (token != null) {
|
|
|
SocketInstance.connect()
|
|
|
+ event = true
|
|
|
}
|
|
|
|
|
|
const urlType = res.data.type
|
|
|
@@ -52,7 +54,7 @@ export default {
|
|
|
for (const url of urls) {
|
|
|
url.type = 'normal'
|
|
|
}
|
|
|
- this.initMp4Player(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime)
|
|
|
+ this.initMp4Player(this.videoProp.userId, videoId, this.videoProp.coverUrl, urls, res.data.currentTime, event)
|
|
|
} else if (urlType === 'flv') {
|
|
|
const urls = res.data.urls
|
|
|
const url = urls[0].url
|
|
|
@@ -82,7 +84,7 @@ export default {
|
|
|
danmakuConfig() {
|
|
|
// TODO 获取弹幕配置,将 videoUrl 作为本函数的回调
|
|
|
},
|
|
|
- initMp4Player(userId, videoId, coverUrl, urls, pos) {
|
|
|
+ initMp4Player(userId, videoId, coverUrl, urls, pos, event) {
|
|
|
const player = new DPlayer({
|
|
|
container: document.querySelector('#dplayer'),
|
|
|
lang: 'zh-cn',
|
|
|
@@ -115,25 +117,21 @@ export default {
|
|
|
|
|
|
/* 事件绑定 */
|
|
|
player.on('progress', function() {
|
|
|
- const jsonData = {}
|
|
|
- jsonData.videoId = videoId
|
|
|
- jsonData.currentTime = player.video.currentTime
|
|
|
- SocketInstance.send(jsonData)
|
|
|
+ if (event) {
|
|
|
+ const jsonData = {}
|
|
|
+ jsonData.videoId = videoId
|
|
|
+ jsonData.currentTime = player.video.currentTime
|
|
|
+ SocketInstance.send(jsonData)
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
player.on('ended', () => {
|
|
|
- const jsonData = {}
|
|
|
- jsonData.videoId = videoId
|
|
|
- jsonData.currentTime = player.video.currentTime
|
|
|
- SocketInstance.send(jsonData)
|
|
|
-
|
|
|
- /* const path = this.$route.path
|
|
|
- const nextPath = '/video/gz5RYkw1zn'
|
|
|
- if (path !== nextPath) {
|
|
|
- this.$router.push(nextPath)
|
|
|
- } else {
|
|
|
- console.log('视频播放完成')
|
|
|
- }*/
|
|
|
+ if (event) {
|
|
|
+ const jsonData = {}
|
|
|
+ jsonData.videoId = videoId
|
|
|
+ jsonData.currentTime = player.video.currentTime
|
|
|
+ SocketInstance.send(jsonData)
|
|
|
+ }
|
|
|
})
|
|
|
|
|
|
player.on('volumechange', () => {
|