فهرست منبع

媒体音频播放时长统计

jwyu 2 سال پیش
والد
کامیت
f81395aa49

+ 10 - 0
api/common.js

@@ -67,4 +67,14 @@ export const apiGetTagTree = params=>{
  */
 export const apiUserBindPermission=()=>{
     return httpGet('/company/permission/bind',{})
+}
+
+/**
+ * 更新媒体播放记录时长
+ * @param id 日志ID
+ * @param stop_seconds 访问时长
+ * @param source 来源:1-问答社区; 2-语音播报; 3-视频社区; 4-路演视频
+ */
+export const apiViewLogUpdate=params=>{
+    return httpPost('/public/view_log/update',params)
 }

+ 16 - 1
components/audioBox/audioBox.vue

@@ -54,6 +54,7 @@
 </template>
 
 <script>
+import {apiViewLogUpdate} from '@/api/common'
 export default {
     filters:{
         formatVoiceTime(e){
@@ -120,6 +121,7 @@ export default {
             const curAudio=this.$store.state.audio.list[this.$store.state.audio.index]
             setTimeout(() => {
                 if(this.globalBgMusic.src!=curAudio.url){
+                    this.handleUpdateAudioPlayTime()
                     this.globalBgMusic.src=curAudio.url 
                     this.globalBgMusic.title=curAudio.title
                 }
@@ -141,16 +143,18 @@ export default {
             })
             this.globalBgMusic.onPause(()=>{
                 console.log('音频暂停');
+                this.handleUpdateAudioPlayTime()
                 this.play=false
                 this.$store.commit('audio/updateAudioPause',true)
             })
             this.globalBgMusic.onStop(()=>{
                 console.log('音频停止');
+                this.handleUpdateAudioPlayTime()
                 this.$store.commit('audio/removeAudio')
             })
             this.globalBgMusic.onEnded(()=>{
                 console.log('音频onEnded');
-
+                this.handleUpdateAudioPlayTime()
                 const index=this.$store.state.audio.index 
                 if(index==this.$store.state.audio.list.length-1){
                     this.$store.commit('audio/removeAudio')
@@ -212,6 +216,17 @@ export default {
             }
         },
 
+        // 记录音频播放 时长
+        handleUpdateAudioPlayTime(){
+            if(!this.$store.state.audio.recordId||this.$store.state.audio.curTime==0) return
+            apiViewLogUpdate({
+                id:this.$store.state.audio.recordId,
+                stop_seconds:parseInt(this.$store.state.audio.curTime),
+                source:this.$store.state.audio.lastType
+            }).then(res=>{
+                console.log('音频播放时间记录成功');
+            })
+        }
     },
 }
 </script>

+ 1 - 0
mixin/questionMixin.js

@@ -405,6 +405,7 @@ export default {
                 }).then((res)=>{
                     if(res.code===200){
                       console.log('音频id为'+audioItem.community_question_audio_id+'点击次数+1')  
+                      this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:1})
                     }
                 })
             }

+ 30 - 1
pages-roadShow/video/search.vue

@@ -38,6 +38,8 @@
                     enable-play-gesture
                     :id="item.road_video_id"
                     @ended="handleVideoEnd"
+                    @pause="handleVideoPause"
+                    @timeupdate="handleTimeUpdate"
                     v-if="item.road_video_id==curVideoId"
                 ></video>
                 <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
@@ -51,6 +53,7 @@
 <script>
 import searchBox from '@/components/searchBox/searchBox.vue'
 import {apiRoadShowVideoList,apiRoadShowVideoPlayLog} from '@/api/roadShow'
+import {apiViewLogUpdate} from '@/api/common'
 export default {
     components: {
         searchBox
@@ -65,7 +68,9 @@ export default {
             pageSize:10,
 
             curVideoId:0,
-            curVideoIns:null
+            curVideoIns:null,
+            curVideoTime:0,
+            videoRecordId:0,
         }
     },
     onReachBottom() {
@@ -130,6 +135,7 @@ export default {
             apiRoadShowVideoPlayLog({video_id:Number(item.road_video_id)}).then(res=>{
                 if(res.code===200){
                     console.log('视频埋点成功');
+                    this.videoRecordId=res.data
                 }
             })
         },
@@ -142,6 +148,29 @@ export default {
                 this.curVideoId=0
                 this.curVideoIns=null
             }, 200);
+        },
+
+        //时长变化
+        handleTimeUpdate(e){
+            // console.log(this.curVideoId,e.detail.currentTime);
+            this.curVideoTime=e.detail.currentTime
+        },
+
+        handleVideoPause(){
+            // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
+            this.handleUpdateVideoPlayTime()
+        },
+
+        // 更新播放时长
+        handleUpdateVideoPlayTime(){
+            if(!this.videoRecordId) return
+            apiViewLogUpdate({
+                id:this.videoRecordId,
+                stop_seconds:parseInt(this.curVideoTime),
+                source:4
+            }).then(res=>{
+                console.log('更新播放时长成功');
+            })
         }
     },
 }

+ 1 - 0
pages-voice/myVoice.vue

@@ -338,6 +338,7 @@ export default {
             })
             if(res.code===200){
                 console.log('上报音频播放记录');
+                this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
             }
         }
     },

+ 1 - 0
pages-voice/voiceDetail.vue

@@ -201,6 +201,7 @@ export default {
             })
             if(res.code===200){
                 console.log('上报音频播放记录');
+                this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
             }
         },
 

+ 29 - 1
pages/roadShow/video/list.vue

@@ -51,6 +51,8 @@
                     enable-play-gesture
                     :id="item.road_video_id"
                     @ended="handleVideoEnd"
+                    @pause="handleVideoPause"
+                    @timeupdate="handleTimeUpdate"
                     v-if="item.road_video_id==curVideoId"
                 ></video>
                 <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
@@ -113,7 +115,7 @@
 </template>
 <script>
 import {apiRoadShowVideoList,apiRoadShowVideoPlayLog} from '@/api/roadShow'
-import {apiGetSceneToParams,apiUserBindPermission} from '@/api/common'
+import {apiGetSceneToParams,apiUserBindPermission,apiViewLogUpdate} from '@/api/common'
 import noAuth from './components/noAuth.vue'
 import dragButton from '@/components/dragButton/dragButton.vue'
 export default {
@@ -136,6 +138,8 @@ export default {
 
             curVideoId:0,
             curVideoIns:null,
+            curVideoTime:0,
+            videoRecordId:0,
 
             isAuth:true,
             noAuthData:null,
@@ -282,6 +286,7 @@ export default {
             apiRoadShowVideoPlayLog({video_id:Number(item.road_video_id)}).then(res=>{
                 if(res.code===200){
                     console.log('视频埋点成功');
+                    this.videoRecordId=res.data
                 }
             })
         },
@@ -294,6 +299,29 @@ export default {
                 this.curVideoId=0
                 this.curVideoIns=null
             }, 200);
+        },
+
+        //时长变化
+        handleTimeUpdate(e){
+            // console.log(this.curVideoId,e.detail.currentTime);
+            this.curVideoTime=e.detail.currentTime
+        },
+
+        handleVideoPause(){
+            // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
+            this.handleUpdateVideoPlayTime()
+        },
+
+        // 更新播放时长
+        handleUpdateVideoPlayTime(){
+            if(!this.videoRecordId) return
+            apiViewLogUpdate({
+                id:this.videoRecordId,
+                stop_seconds:parseInt(this.curVideoTime),
+                source:4
+            }).then(res=>{
+                console.log('更新播放时长成功');
+            })
         }
     },
 }

+ 29 - 1
pages/video/videoList.vue

@@ -48,6 +48,8 @@
                     enable-play-gesture
                     :id="item.community_video_id"
                     @ended="handleVideoEnd"
+                    @pause="handleVideoPause"
+                    @timeupdate="handleTimeUpdate"
                     v-if="item.community_video_id==curVideoId"
                 ></video>
                 <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
@@ -110,7 +112,7 @@
 <script>
 import {apiVideoList,apiVideoPlayLog} from '@/api/video'
 import {apiOptionList} from '@/api/question'
-import {apiGetSceneToParams,apiGetTagTree} from '@/api/common'
+import {apiGetSceneToParams,apiGetTagTree,apiViewLogUpdate} from '@/api/common'
 import noAuth from './components/noAuth.vue'
 import dragButton from '@/components/dragButton/dragButton.vue'
 import commnet from './components/comment.vue'
@@ -135,6 +137,8 @@ export default {
 
             curVideoId:0,
             curVideoIns:null,
+            curVideoTime:0,
+            videoRecordId:0,
 
             isAuth:true,
             noAuthData:null,
@@ -277,6 +281,7 @@ export default {
             apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
                 if(res.code===200){
                     console.log('视频埋点成功');
+                    this.videoRecordId=res.data
                 }
             })
         },
@@ -289,6 +294,29 @@ export default {
                 this.curVideoId=0
                 this.curVideoIns=null
             }, 200);
+        },
+
+         //时长变化
+        handleTimeUpdate(e){
+            // console.log(this.curVideoId,e.detail.currentTime);
+            this.curVideoTime=e.detail.currentTime
+        },
+
+        handleVideoPause(){
+            // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
+            this.handleUpdateVideoPlayTime()
+        },
+
+        // 更新播放时长
+        handleUpdateVideoPlayTime(){
+            if(!this.videoRecordId) return
+            apiViewLogUpdate({
+                id:this.videoRecordId,
+                stop_seconds:parseInt(this.curVideoTime),
+                source:3
+            }).then(res=>{
+                console.log('更新播放时长成功');
+            })
         }
     },
 }

+ 30 - 1
pages/video/videoSearch.vue

@@ -39,6 +39,8 @@
                     enable-play-gesture
                     :id="item.community_video_id"
                     @ended="handleVideoEnd"
+                    @pause="handleVideoPause"
+                    @timeupdate="handleTimeUpdate"
                     v-if="item.community_video_id==curVideoId"
                 ></video>
                 <image @click="handelClickPlay(item)" v-else class="poster" :src="item.cover_img_url" mode="aspectFill" lazy-load/>
@@ -51,6 +53,7 @@
 <script>
 import searchBox from '@/components/searchBox/searchBox.vue'
 import {apiVideoList,apiVideoPlayLog} from '@/api/video'
+import {apiViewLogUpdate} from '@/api/common'
 import commnet from './components/comment.vue'
 export default {
     components: {
@@ -67,7 +70,9 @@ export default {
             pageSize:10,
 
             curVideoId:0,
-            curVideoIns:null
+            curVideoIns:null,
+            curVideoTime:0,
+            videoRecordId:0,
         }
     },
     onReachBottom() {
@@ -132,6 +137,7 @@ export default {
             apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
                 if(res.code===200){
                     console.log('视频埋点成功');
+                    this.videoRecordId=res.data
                 }
             })
         },
@@ -144,6 +150,29 @@ export default {
                 this.curVideoId=0
                 this.curVideoIns=null
             }, 200);
+        },
+
+        //时长变化
+        handleTimeUpdate(e){
+            // console.log(this.curVideoId,e.detail.currentTime);
+            this.curVideoTime=e.detail.currentTime
+        },
+
+        handleVideoPause(){
+            // console.log(`视频 pause---${this.videoRecordId}----${this.curVideoTime}`);
+            this.handleUpdateVideoPlayTime()
+        },
+
+        // 更新播放时长
+        handleUpdateVideoPlayTime(){
+            if(!this.videoRecordId) return
+            apiViewLogUpdate({
+                id:this.videoRecordId,
+                stop_seconds:parseInt(this.curVideoTime),
+                source:3
+            }).then(res=>{
+                console.log('更新播放时长成功');
+            })
         }
     },
 }

+ 1 - 0
pages/voice/voice.vue

@@ -423,6 +423,7 @@ export default {
             })
             if(res.code===200){
                 console.log('上报音频播放记录');
+                this.$store.commit('audio/addAudioRecordId',{recordId:res.data,source:2})
             }
         }
     },

+ 7 - 0
store/modules/audio.js

@@ -11,6 +11,8 @@ const audioModules={
         questionId:0,//当前是哪个问答的音频
         paused:true,//当前是否音频正在播放 true暂停状态
         curTime:0,//当前正在播放的音频播放的时间
+        recordId:0,//播放记录id
+        lastType:0,//上次播放的是那种的音频,用于更新媒体播放记录时长中的source
     },
     mutations: {
         addAudio(state,e){
@@ -51,6 +53,11 @@ const audioModules={
         // 关闭弹窗
         closePopAudio(state){
             state.show=false
+        },
+        // 设置播放记录id
+        addAudioRecordId(state,e){
+            state.recordId=e.recordId
+            state.lastType=e.source
         }
     }
 }