diff --git a/pages/plugins/live/pull/components/live-content/live-content.vue b/pages/plugins/live/pull/components/live-content/live-content.vue
index 3aaf0476..1af8760d 100644
--- a/pages/plugins/live/pull/components/live-content/live-content.vue
+++ b/pages/plugins/live/pull/components/live-content/live-content.vue
@@ -620,7 +620,7 @@
this.scroll_to_lower();
});
break;
- case 'live-status':
+ case 'pull-live-room-info': // 获取直播间数据
this.$emit('liveStatus', data.content);
break;
}
@@ -647,6 +647,14 @@
this.ping_timer = null;
}
},
+
+ /**
+ * WebSocket获取直播间数据
+ */
+ socket_connect() {
+ // 发送获取直播间数据消息
+ this.socket_send('pull-live-room-info');
+ },
/**
* 发送WebSocket消息
diff --git a/pages/plugins/live/pull/components/video/video.vue b/pages/plugins/live/pull/components/video/video.vue
index 6d00cb1b..fda4b211 100644
--- a/pages/plugins/live/pull/components/video/video.vue
+++ b/pages/plugins/live/pull/components/video/video.vue
@@ -1,6 +1,6 @@
-
+
@@ -49,7 +49,8 @@
windowWidth: 0,
windowHeight: 0,
muted: false,
- video_src: ''
+ video_src: '',
+ video_player_show: true,
}
},
created() {
@@ -63,10 +64,19 @@
// #ifndef MP
const video = this.$refs.videoPlayer;
// 深拷贝视频源地址,避免直接修改原地址
- const src = JSON.parse(JSON.stringify(this.video_src));
+ let src = '';
+ if (!isEmpty(this.propSrc)) {
+ src = this.propSrc;
+ }
this.video_src = ''; // 清除原地址
+ //#ifdef H5
+ this.video_player_show = false;
+ //#endif
setTimeout(() => {
this.video_src = src; // 重新赋值
+ //#ifdef H5
+ this.video_player_show = true;
+ //#endif
// #ifdef APP-NVUE
video.load(); // 重新加载
video.play().catch(() => this.retryLoadVideo());
@@ -76,6 +86,7 @@
},
// 视频元数据加载完成处理函数, 不太准确,有的时候是直播的中间区域状态加载完了,但是视频还没有开始播放
loadedmetadata() {
+ console.log('loadedmetadata');
this.$emit('loadedmetadata');
},
/**
@@ -92,18 +103,23 @@
* @param {Object} e - 错误事件对象
*/
error(e) {
- // #ifdef H5
- // 非初次加载错误的, 直播结束
- if (e.type != 'otherError' || e.details != 'internalException') {
- this.$emit('ended');
+ // 只有组件显示时才触发这个事件
+ if (this.video_player_show) {
+ // #ifdef H5
+ // 非初次加载错误的, 直播结束
+ if (e.type != 'otherError' || e.details != 'internalException') {
+ console.log('ended');
+
+ this.$emit('ended');
+ }
+ // #endif
+ // #ifdef APP-NVUE
+ if (!isEmpty(e.type) && e.type == 'error') {
+ this.$emit('ended');
+ }
+ // #endif
+ console.log(e, 'error');
}
- // #endif
- // #ifdef APP-NVUE
- if (!isEmpty(e.type) && e.type == 'error') {
- this.$emit('ended');
- }
- // #endif
- console.log(e, 'error');
},
/**
diff --git a/pages/plugins/live/pull/mixins/mixins.js b/pages/plugins/live/pull/mixins/mixins.js
index 1e9adfc4..89795349 100644
--- a/pages/plugins/live/pull/mixins/mixins.js
+++ b/pages/plugins/live/pull/mixins/mixins.js
@@ -27,7 +27,9 @@ export default {
lastLikeTime: 0, // 记录上次点赞时间,用于防抖
live_status: 1,
live_be_right_back_error: false,
- load_timer: null, // 加载定时器
+ load_timer: null, // 延时显示视频的定时器
+ retry_count: 0 // 重试计数器
+
}
},
@@ -128,38 +130,72 @@ export default {
},
/**
- * 视频元数据加载完成时触发
+ * 视频数据加载完成时触发
*/
loadedmetadata() {
- // 如果加载完成了,延迟一秒确定一下直播状态, 有的时候直播状态是正常的也加载成功了,但是获取不到视频流,需要确定一下没有执行error才算是真正的成功
+ // 如果加载完成了,延迟2秒确定一下直播状态, 有的时候直播状态是正常的也加载成功了,但是获取不到视频流,需要确定一下没有执行error才算是真正的成功
this.load_timer = setTimeout(() => {
+ this.retry_count = 0;
// 隐藏加载提示
uni.hideLoading();
+ // 直播状态为正常或者暂停直播了,才认为是正常的加载成功
if ([0, 1].includes(this.live_status)) {
+ // 如果重连的定时器还在运行中,则清除它
+ if (this.ended_timer) {
+ // 隐藏加载提示
+ clearTimeout(this.ended_timer);
+ }
this.live_be_right_back_error = false;
}
- }, 300);
+ }, 2000);
},
/**
* 标记直播结束或者直播暂停
*/
ended() {
// 隐藏加载提示
- uni.hideLoading();
+ uni.hideLoading();
// 如果加载定时器存在,则清除
if (this.load_timer) {
// 隐藏加载提示
clearTimeout(this.load_timer);
}
+ // 如果直播已结束,则返回
if (!this.is_live_ended) {
+
if (![1, 2].includes(this.live_status)) {
this.is_live_ended = true;
} else {
+ // 初始化重试计数器
+ if (this.retry_count === undefined) {
+ this.retry_count = 0;
+ }
+ // 如果历史定时器存在,则清除
+ if (this.ended_timer) {
+ // 隐藏加载提示
+ clearTimeout(this.ended_timer);
+ }
+
+ // 如果重试次数超过指定次数,则标记为真正结束
+ if (this.retry_count > 50) {
+ this.is_live_ended = true;
+ this.live_be_right_back_error = false;
+ // 重置计数器
+ this.retry_count = 0;
+ return;
+ }
+
+ // 增加重试计数
+ this.retry_count++;
// 暂停直播了或者继续直播了,则提示用户当前主播暂时离开
this.live_be_right_back_error = true;
+ // 延迟3秒后尝试重新连接
this.ended_timer = setTimeout(() => {
- this.live_be_right_back_error = false;
- }, 3000);
+ // 在定时结束后尝试重新连接
+ if (this.$refs.liveVideo) {
+ this.$refs.liveVideo.reload_video();
+ }
+ }, 5000);
}
}
},
@@ -245,7 +281,7 @@ export default {
this.lastTapPosition = { x, y };
},
socket_live_status(status) {
- this.live_status = status;
+ // this.live_status = status;
}
}
}
\ No newline at end of file
diff --git a/pages/plugins/live/pull/pull.nvue b/pages/plugins/live/pull/pull.nvue
index 8d2267b3..aaad5abf 100644
--- a/pages/plugins/live/pull/pull.nvue
+++ b/pages/plugins/live/pull/pull.nvue
@@ -6,9 +6,19 @@
+
+
+
+
+ 主播暂时离开
+ 休息片刻,更多精彩马上到来
+
+
+
+
直播已结束
@@ -17,26 +27,24 @@
-
-
- 直播连接失败,正在尝试重新连接...
-