Procházet zdrojové kódy

1.firefox 中不能实时监听 dplayer 的 progress 事件, 但在 chrome 中不存在这个问题
2.firefox 中可以正常显示弹幕, 但弹幕在 chrome 中不能正常显示

reghao před 2 roky
rodič
revize
c510568136
1 změnil soubory, kde provedl 16 přidání a 18 odebrání
  1. 16 18
      src/components/VideoPlayer.vue

+ 16 - 18
src/components/VideoPlayer.vue

@@ -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', () => {