Commit 9cc7c598 by 胡悦

解决安卓手机使用webRTC协议报错的问题

1 parent fa7f579c
...@@ -22,6 +22,7 @@ ...@@ -22,6 +22,7 @@
<% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %> <% for (var i in htmlWebpackPlugin.options.cdn&&htmlWebpackPlugin.options.cdn.js) { %>
<script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script> <script src="<%= htmlWebpackPlugin.options.cdn.js[i] %>"></script>
<% } %> <% } %>
<script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
<!-- built files will be auto injected --> <!-- built files will be auto injected -->
<!-- <link href="https://web.sdk.qcloud.com/player/tcplayer/release/v4.2.1/tcplayer.min.css" rel="stylesheet"> <!-- <link href="https://web.sdk.qcloud.com/player/tcplayer/release/v4.2.1/tcplayer.min.css" rel="stylesheet">
<script src="https://web.sdk.qcloud.com/player/tcplayer/release/v4.2.1/libs/hls.min.0.13.2m.js"></script> <script src="https://web.sdk.qcloud.com/player/tcplayer/release/v4.2.1/libs/hls.min.0.13.2m.js"></script>
......
<template> <template>
<div <div :class="['live-box', { videoFullscreen: videoFullscreen }]" :style="videoStyle" id="live-box">
:class="['live-box',{'videoFullscreen':videoFullscreen}]" <div class="mask" @click="openFullscreen">
id="live-box"
>
<div class="mask">
<div class="sprite-icon icon-live-close"></div> <div class="sprite-icon icon-live-close"></div>
<div class="status flex"> <div class="status flex">
<div class="live-line"> <div class="live-line">
...@@ -14,39 +11,21 @@ ...@@ -14,39 +11,21 @@
<div class="text">正在直播</div> <div class="text">正在直播</div>
</div> </div>
<template v-if="!IsIOS"> <template v-if="!IsIOS">
<img <img src="https://wimg.588ku.com/gif620/20/04/23/79a7882dfb0c59497976fd8b3bfe60ef.gif" alt="" />
src="https://wimg.588ku.com/gif620/20/04/23/79a7882dfb0c59497976fd8b3bfe60ef.gif"
alt=""
>
</template> </template>
</div> </div>
<div <div class="fullscreen-btn" @click="openFullscreen(false)">
class="fullscreen-btn" <img src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/fullscreen.png" />
@click="openFullscreen(false)"
>
<img src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/fullscreen.png">
</div> </div>
<div <div class="poster-btn" @click="showKf = true">
class="poster-btn" <img src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/gift.gif" />
@click="showKf= true"
>
<img src="https://img02.glsx.com.cn/weapp/resource/scrm-mobile/crowdfunding/gift.gif">
</div> </div>
<video <video id="player-container-id" preload="auto" playsinline webkit-playsinline></video>
id="player-container-id" <kf-modal v-model="showKf" :detail="detail" />
preload="auto"
playsinline
webkit-playsinline
>
</video>
<kf-modal
v-model="showKf"
:detail="detail"
/>
</div> </div>
</template> </template>
<script type='text/ecmascript-6'> <script type="text/ecmascript-6">
import { KfModal } from './index' import { KfModal } from './index'
import { wxConfig } from '@/api' import { wxConfig } from '@/api'
export default { export default {
...@@ -66,25 +45,32 @@ export default { ...@@ -66,25 +45,32 @@ export default {
mounted () { mounted () {
let _this = this let _this = this
wxConfig.ready(() => { wxConfig.ready(() => {
if (Hls.isSupported()) {
_this.video = document.getElementById('player-container-id');
_this.hls = new Hls();
// bind them together
_this.hls.attachMedia(_this.video);
}
_this.player = TCPlayer('player-container-id', { _this.player = TCPlayer('player-container-id', {
fileID: '387702305074716718', //点播ID // fileID: '387702305074716718', //点播ID
appID: '1311227058', //点播APPID // appID: '1311227058', //点播APPID
autoplay: true, //自动播放 autoplay: true, // 自动播放
loop: true, // 循环播放 loop: true, // 循环播放
muted: true, //是否静音 muted: true, //是否静音
controlBar: { //控制条配置 controlBar: { //控制条配置
fullscreenToggle: false //隐藏全屏按钮 fullscreenToggle: false //隐藏全屏按钮
}, },
webrtcConfig: { //webrtcConfig 参数列表 webrtcConfig: { //webrtcConfig 参数列表
showLog: true //打印webrtc日志 showLog: true // 打印webrtc日志
} }
}) })
// _this.player.src('http://play.glsx.com.cn/live/live.m3u8') //直播地址 // _this.player.src('http://play.glsx.com.cn/live/live.m3u8') //直播地址
_this.player.src('webrtc://play.glsx.com.cn/live/live_normal')
wx.getNetworkType({ wx.getNetworkType({
success: (result) => { success: (result) => {
_this.player.ready(function () { //设置播放器初始化完成后的回调 _this.player.ready(function () { //设置播放器初始化完成后的回调
console.log('-------------------------', _this.player.poster()) console.log('-------------------------', _this.player.poster())
_this.player.play() //播放视频 _this.player.play() //播放视频
_this.draggable(document.getElementById('live-box'), _this.openFullscreen) _this.draggable(document.getElementById('live-box'), _this.openFullscreen)
}) })
...@@ -93,8 +79,25 @@ export default { ...@@ -93,8 +79,25 @@ export default {
_this.player.on('webrtcevent', function (event) { //监听webrtc _this.player.on('webrtcevent', function (event) { //监听webrtc
console.log(event) console.log(event)
}) })
_this.hls.on(Hls.Events.ERROR, function (event, data) {
if (data.fatal) {
switch (data.type) {
case Hls.ErrorTypes.NETWORK_ERROR:
// try to recover network error
console.log('fatal network error encountered, try to recover');
_this.hls.startLoad()
break
case Hls.ErrorTypes.MEDIA_ERROR:
console.log('fatal media error encountered, try to recover');
_this.hls.recoverMediaError();
break;
default:
// cannot recover
_this.hls.destroy();
break;
}
}
});
}) })
...@@ -113,7 +116,7 @@ export default { ...@@ -113,7 +116,7 @@ export default {
} }
</script> </script>
<style scoped lang='scss'> <style scoped lang="scss">
.live-box { .live-box {
position: fixed; position: fixed;
top: 23%; top: 23%;
...@@ -123,6 +126,7 @@ export default { ...@@ -123,6 +126,7 @@ export default {
height: 148px; height: 148px;
border-radius: 4px; border-radius: 4px;
overflow: hidden; overflow: hidden;
-webkit-user-select: auto;
.mask { .mask {
width: 100%; width: 100%;
height: 100%; height: 100%;
......
Markdown is supported
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!