视频地址:rtmp://rtmp01open.ys7.com:1935/v3/openlive/F37874691_10_2?expire=1630752171&id=353973131969540096&t=77333ff57c7282721c23b3f2c1dbcb14744cc15f73f617b883643c92033a8118&ev=100&supportH265=1
第一步:展示live-player标签,展示正常,并执行 LivePlayerContext.play(),能够正常播放。
第二步:进行停止视频播放,执行LivePlayerContext.stop(),并同时隐藏live-player标签,标签已经隐藏成功,如下图:
第3步:再次执行视频播放,展示live-player标签,标签展示成功,并执行 LivePlayerContext.play()方法,然后视频状态就停留在"2008:解码器已启动"这里再也没有动静了。
代码如下:
<template>
<live-player
class="video"
id="myVideo"
:src="videoUrl"
controls
ref="videoDOM"
style="width: 100%"
v-if="videoUrl && isPlaying"
@statechange="statechange"
@click="pauseVideo"
></live-player>
<view class="video" @click="toPlayVideo" v-else>点击开始播放</view>
</template>
<script>
export default {
name: "Test",
data() {
return {
videoCtx: undefined,
videoUrl: undefined,
isPlaying: false,
isFirstPlay: true,
};
},
onLoad() {
this.videoCtx = wx.createLivePlayerContext("myVideo", this);
},
methods: {
toPlayVideo() {
let url =
"rtmp://rtmp01open.ys7.com:1935/v3/openlive/F37874691_2_2?expire=1630980209&id=354929592471822336&t=9ed21a1d3e78f59e791c97bb5a03de1104acfaf84e7b33be5c260d692f9007dd&ev=100&supportH265=1";
if (!this.isFirstPlay) {
url =
"rtmp://rtmp01open.ys7.com:1935/v3/openpb/F37874691_10_1?begin=20210903155605&end=20210903155615&expire=1630979079&id=354924855321063424&rec=local&t=06f7374a380901f39bc5a2a8ede72b81ae0392f4c810d1a0c8f2e1b6259aeee3&ev=100&supportH265=1";
}
this.playVideo(url);
},
playVideo(url) {
this.videoUrl = url;
this.isPlaying = true;
this.videoCtx.play();
this.isFirstPlay = false;
},
pauseVideo() {
this.videoCtx.stop();
this.videoUrl = undefined;
this.isPlaying = false;
},
statechange(status) {
const code = status.detail.code;
if (code === 2001) {
this.$api.msg("2001: 已经连接服务器");
} else if (code === 2002) {
this.$api.msg("2002: 已经连接 RTMP 服务器,开始拉流");
} else if (code === 2003) {
this.$api.msg("2003: 网络接收到首个视频数据包(IDR)");
} else if (code === 2004) {
this.$api.msg("2004: 视频播放开始");
} else if (code === 2008) {
this.$api.msg("解码器启动,如遇不播放或卡顿,请尝试重新播放", 3000);
} else if (code === 2009) {
console.warn("2009: 视频分辨率改变");
} else if (code === 2101) {
this.$api.msg("2101: 当前视频帧解码失败");
} else if (code === 2102) {
this.$api.msg("2102: 当前音频帧解码失败");
} else if (code === 2103) {
this.$api.msg("2103: 网络断连, 已启动自动重连");
} else if (code === 2104) {
this.$api.msg(
"2104: 网络来包不稳:可能是下行带宽不足,或由于主播端出流不均匀"
);
} else if (code === 2105) {
this.$api.msg("2105: 当前视频播放出现卡顿");
} else if (code === 2106) {
this.$api.msg("2106: 硬解启动失败,采用软解");
} else if (code === 2107) {
this.$api.msg("2107: 当前视频帧不连续,可能丢帧");
} else if (code === 2108) {
this.$api.msg("2108: 当前流硬解第一个I帧失败,SDK自动切软解");
} else if (code === 3001) {
this.$api.msg("3001: RTMP -DNS解析失败");
} else if (code === 3002) {
this.$api.msg("3002: RTMP服务器连接失败");
} else if (code === 3003) {
this.$api.msg("3003: RTMP服务器握手失败");
} else if (code === 3005) {
this.$api.msg("3005: RTMP 读/写失败,之后会发起网络重试");
} else if (code === -2301) {
this.$api.msg(
"-2301: 网络断连,且经多次重连抢救无效,更多重试请自行重启播放"
);
} else if (code === -2302) {
this.$api.msg("-2302: 获取加速拉流地址失败");
}
},
},
};
</script>
<style lang="scss" scoped></style>
你好,麻烦提供能复现问题的简单代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)。