瀏覽代碼

媒体播放时长统计

jwyu 2 年之前
父節點
當前提交
61da9a9765

+ 11 - 0
src/api/common.js

@@ -165,6 +165,17 @@ export const apiGetTagTree = params=>{
 /**
  * 获取用户已绑定权限
  */
+
 export const apiUserBindPermission=params=>{
     return get('/company/permission/bind',params)
+}
+
+/**
+ * 更新媒体播放记录时长
+ * @param id 日志ID
+ * @param stop_seconds 访问时长
+ * @param source 来源:1-问答社区; 2-语音播报; 3-视频社区; 4-路演视频
+ */
+export const apiViewLogUpdate=params=>{
+    return post('/public/view_log/update',params)
 }

+ 120 - 3
src/store/index.js

@@ -2,8 +2,12 @@ import { createStore } from "vuex";
 import {ElMessage} from 'element-plus'
 import {apiUserInfo} from '@/api/user.js'
 import {apiActivityAudioPlayRecordAdd,apiActivityAudioPlayRecordUpate} from '@/api/activity'
+import {apiViewLogUpdate} from  '@/api/common'
+import{apiCountAudioClick}from '@/api/question'
+import {apiVoicePlayRecord} from '@/api/voice'
 
 let lastActivityAudioRecordId=0//上次新曾活动音频记录时的id
+let lastAudioRecordId=0//上次问答社区\语音播报 音频记录id
 
 const token=localStorage.getItem('token')||''
 let platform='web'
@@ -72,6 +76,19 @@ export default createStore({
 
     // 设置音频播放
     addAudio(state,e){
+      // 更新活动音频播放时长
+      if(state.audioData.activityId!=0&&lastActivityAudioRecordId!=0){
+        handleActivityAudioRecordUpdate(state.audioData)
+      }
+      // 更新问答\语音播报 音频播放时长
+      if(lastAudioRecordId!=0){
+        if(state.audioData.voiceId!=0){
+          handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+        }
+        if(state.audioData.questionId!=0){
+          handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+        }
+      }
       state.audioData.index=e.index
       state.audioData.list=e.list
       state.audioData.activityId=e.activityId||0
@@ -81,11 +98,14 @@ export default createStore({
       state.audioData.show=true
       state.audioData.INS.play()
       if(state.audioData.activityId!=0){
-        if(lastActivityAudioRecordId!=0){
-          handleActivityAudioRecordUpdate(state.audioData)
-        }
         handleActivityAudioRecordAdd(state.audioData)
       }
+      if(state.audioData.voiceId!=0){
+        handleVoiceAudioRecordAdd(state.audioData)
+      }
+      if(state.audioData.questionId!=0){
+        handleQuestionAudioRecordAdd(state.audioData)
+      }
     },
     //切换音频
     changeAudio(state,e){
@@ -96,7 +116,25 @@ export default createStore({
           if(state.audioData.activityId!=0){
             handleActivityAudioRecordUpdate(state.audioData)
           }
+          if(state.audioData.voiceId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+          }
+          if(state.audioData.questionId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+          }
+
           state.audioData.index--
+
+          if(state.audioData.activityId!=0){
+            handleActivityAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.voiceId!=0){
+            handleVoiceAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.questionId!=0){
+            handleQuestionAudioRecordAdd(state.audioData)
+          }
+          
         }
       }else if(e==='next'){//点击按钮切换下一首
         if(state.audioData.index==state.audioData.list.length-1){
@@ -105,8 +143,23 @@ export default createStore({
           if(state.audioData.activityId!=0){
             handleActivityAudioRecordUpdate(state.audioData)
           }
+          if(state.audioData.voiceId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+          }
+          if(state.audioData.questionId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+          }
           
           state.audioData.index++
+          if(state.audioData.activityId!=0){
+            handleActivityAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.voiceId!=0){
+            handleVoiceAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.questionId!=0){
+            handleQuestionAudioRecordAdd(state.audioData)
+          }
         }
       }else if(e==='auto'){//自动播放切换下一首
         if(state.audioData.index==state.audioData.list.length-1){
@@ -114,6 +167,12 @@ export default createStore({
           if(state.audioData.activityId!=0){
             handleActivityAudioRecordUpdate(state.audioData)
           }
+          if(state.audioData.voiceId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+          }
+          if(state.audioData.questionId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+          }
           
           state.audioData.list=[]
           state.audioData.index=0
@@ -128,8 +187,23 @@ export default createStore({
           if(state.audioData.activityId!=0){
             handleActivityAudioRecordUpdate(state.audioData)
           }
+          if(state.audioData.voiceId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+          }
+          if(state.audioData.questionId!=0){
+            handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+          }
           
           state.audioData.index++
+          if(state.audioData.activityId!=0){
+            handleActivityAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.voiceId!=0){
+            handleVoiceAudioRecordAdd(state.audioData)
+          }
+          if(state.audioData.questionId!=0){
+            handleQuestionAudioRecordAdd(state.audioData)
+          }
         }
       }
     },
@@ -138,6 +212,12 @@ export default createStore({
       if(state.audioData.activityId!=0){
         handleActivityAudioRecordUpdate(state.audioData)
       }
+      if(state.audioData.voiceId!=0){
+        handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+      }
+      if(state.audioData.questionId!=0){
+        handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+      }
       
       state.audioData.list=[]
       state.audioData.index=0
@@ -164,6 +244,12 @@ export default createStore({
       if(state.audioData.activityId!=0){
         handleActivityAudioRecordUpdate(state.audioData)
       }
+      if(state.audioData.voiceId!=0){
+        handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:2})
+      }
+      if(state.audioData.questionId!=0){
+        handleAudioRecordUpdate({audioCurrentTime:state.audioData.audioCurrentTime,source:1})
+      }
       
       state.audioData.show=false
     },
@@ -255,4 +341,35 @@ function handleActivityAudioRecordUpdate(params) {
       console.log('更新音频记录成功');
     }
   })
+}
+
+// 更新问答社区、语音播报模块 音频播放记录
+function handleAudioRecordUpdate(params){
+  apiViewLogUpdate({
+    id:lastAudioRecordId,
+    stop_seconds:parseInt(params.audioCurrentTime),
+    source:params.source,
+  }).then(res=>{
+    console.log('更新播放时长成功');
+  })
+}
+
+//新增语音播报音频播放记录
+function handleVoiceAudioRecordAdd(params){
+  apiVoicePlayRecord({
+    broadcast_id:params.voiceId
+  }).then(res=>{
+    console.log('上报音频播放记录');
+    lastAudioRecordId=res.data
+  })
+} 
+
+//新增问答社区语音播放记录
+function handleQuestionAudioRecordAdd(params){
+  apiCountAudioClick({
+    community_question_audio_id:params.list[params.index].id
+  }).then(res=>{
+    console.log('上报问答音频播放记录');
+    lastAudioRecordId=res.data
+  })
 }

+ 8 - 8
src/views/question/List.vue

@@ -276,17 +276,17 @@ const handlePlay=(item)=>{
     }
     const audioItem=item.audio_list[0]
     store.commit('addAudio',{
-        list:[{name:item.question_content,url:audioItem.audio_url,time:audioItem.audio_play_seconds}],
+        list:[{name:item.question_content,url:audioItem.audio_url,time:audioItem.audio_play_seconds,id:audioItem.community_question_audio_id}],
         questionId:item.community_question_id,
         index:0
     })
-    apiCountAudioClick({
-        community_question_audio_id:audioItem.community_question_audio_id
-    }).then((res)=>{
-        if(res.code===200){
-          console.log('音频id为'+audioItem.community_question_audio_id+'点击次数+1')  
-        }  
-    })
+    // apiCountAudioClick({
+    //     community_question_audio_id:audioItem.community_question_audio_id
+    // }).then((res)=>{
+    //     if(res.code===200){
+    //       console.log('音频id为'+audioItem.community_question_audio_id+'点击次数+1')  
+    //     }  
+    // })
 }
 
 

+ 8 - 8
src/views/question/MyList.vue

@@ -300,17 +300,17 @@ const handlePlay=(item)=>{
     }
     const audioItem=item.audio_list[0]
     store.commit('addAudio',{
-        list:[{name:item.question_content,url:audioItem.audio_url,time:audioItem.audio_play_seconds}],
+        list:[{name:item.question_content,url:audioItem.audio_url,time:audioItem.audio_play_seconds,id:audioItem.community_question_audio_id}],
         questionId:item.community_question_id,
         index:0
     })
-    apiCountAudioClick({
-        community_question_audio_id:audioItem.community_question_audio_id
-    }).then((res)=>{
-        if(res.code===200){
-          console.log('音频id为'+audioItem.community_question_audio_id+'点击次数+1')  
-        }  
-    })
+    // apiCountAudioClick({
+    //     community_question_audio_id:audioItem.community_question_audio_id
+    // }).then((res)=>{
+    //     if(res.code===200){
+    //       console.log('音频id为'+audioItem.community_question_audio_id+'点击次数+1')  
+    //     }  
+    // })
 }
 
 getBarList()

+ 18 - 1
src/views/roadShow/video/List.vue

@@ -3,7 +3,7 @@ import {ref,reactive,onMounted,onActivated} from 'vue'
 import { useElementSize } from '@vueuse/core'
 import { ElMessage, ElMessageBox } from 'element-plus'
 
-import {apiGetWechatQRCode,apiUserBindPermission} from '@/api/common'
+import {apiGetWechatQRCode,apiUserBindPermission,apiViewLogUpdate} from '@/api/common'
 import {apiRoadShowVideoList,apiRoadShowVideoPlayLog} from '@/api/roadShow'
 import {apiApplyPermission} from '@/api/user'
 
@@ -210,15 +210,31 @@ const onLoad=()=>{
 
 //当前正在播放哪个
 let curVideoId=ref(0)
+let videoRecordId=0//音频播放记录id
 const handelClickPlay=(item)=>{
     curVideoId.value=item.road_video_id
     //记录播放
     apiRoadShowVideoPlayLog({video_id:Number(item.road_video_id)}).then(res=>{
         if(res.code===200){
             console.log('视频埋点成功');
+            videoRecordId=res.data
         }
     })
 }
+//视频播放暂停事件
+const handleVideoPause=(e)=>{
+    const target=e.target||e.path[0]
+    const t=target.currentTime||0
+    console.log('记录播放时长',t);
+    if(!videoRecordId||t==0) return
+    apiViewLogUpdate({
+        id:videoRecordId,
+        stop_seconds:parseInt(t),
+        source:4
+    }).then(res=>{
+        console.log('记录播放时长成功');
+    })
+}
 
 
 //获取视频单个对应的小程序二维码
@@ -344,6 +360,7 @@ onActivated(()=>{
                         autoplay
                         v-if="item.road_video_id==curVideoId"
                         @ended="curVideoId=0"
+                        @pause="handleVideoPause"
                     ></video>
                     <div v-else class="poster-img" :style="'background-image:url('+item.cover_img_url+')'" @click="handelClickPlay(item)"></div>
                     <div class="time">发布时间:{{item.publish_time}}</div>

+ 18 - 1
src/views/video/List.vue

@@ -2,7 +2,7 @@
 import {ref,reactive,onMounted,onActivated} from 'vue'
 import { ElMessage, ElMessageBox } from 'element-plus'
 
-import {apiFICCPermissionList,apiGetWechatQRCode,apiGetTagTree} from '@/api/common'
+import {apiFICCPermissionList,apiGetWechatQRCode,apiGetTagTree,apiViewLogUpdate} from '@/api/common'
 import {apiVideoList,apiVideoPlayLog} from '@/api/video'
 import {apiApplyPermission} from '@/api/user'
 
@@ -209,15 +209,31 @@ const onLoad=()=>{
 
 //当前正在播放哪个
 let curVideoId=ref(0)
+let videoRecordId=0//音频播放记录id
 const handelClickPlay=(item)=>{
     curVideoId.value=item.community_video_id
     //记录播放
     apiVideoPlayLog({video_id:Number(item.community_video_id)}).then(res=>{
         if(res.code===200){
             console.log('视频埋点成功');
+            videoRecordId=res.data
         }
     })
 }
+//视频播放暂停事件
+const handleVideoPause=(e)=>{
+    const target=e.target||e.path[0]
+    const t=target.currentTime||0
+    console.log('记录播放时长',t);
+    if(!videoRecordId||t==0) return
+    apiViewLogUpdate({
+        id:videoRecordId,
+        stop_seconds:parseInt(t),
+        source:3
+    }).then(res=>{
+        console.log('记录播放时长成功');
+    })
+}
 
 
 //获取视频单个对应的小程序二维码
@@ -349,6 +365,7 @@ onActivated(()=>{
                         autoplay
                         v-if="item.community_video_id==curVideoId"
                         @ended="curVideoId=0"
+                        @pause="handleVideoPause"
                     ></video>
                     <div v-else class="poster-img" :style="'background-image:url('+item.cover_img_url+')'" @click="handelClickPlay(item)"></div>
              

+ 1 - 1
src/views/voice/Detail.vue

@@ -220,7 +220,7 @@ const handlePlay=(item)=>{
         voiceId:item.BroadcastId,
         index:0
     })
-    handleVoiceRecord(item)
+    // handleVoiceRecord(item)
 }
 
 //上报音频播放记录

+ 1 - 1
src/views/voice/List.vue

@@ -269,7 +269,7 @@ const handlePlay=(item)=>{
         voiceId:item.BroadcastId,
         index:0
     })
-    handleVoiceRecord(item)
+    // handleVoiceRecord(item)
 }
 
 //上报音频播放记录

+ 1 - 1
src/views/voice/Mine.vue

@@ -239,7 +239,7 @@ const handlePlay=(item)=>{
         index:0
     })
     if(item.PublishState==0) return //待发布的不记录
-    handleVoiceRecord(item)
+    // handleVoiceRecord(item)
 }
 
 //上报音频播放记录