LiveDetail.vue 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. <template><page-meta :root-font-size="fontSize+'px'"></page-meta>
  2. <member-base :show="false">
  3. <view class="div room-bg">
  4. <!-- #ifdef H5 -->
  5. <view class="div bg-img" id="id_test_video"></view>
  6. <!-- #endif -->
  7. <!-- #ifdef MP-WEIXIN -->
  8. <live-player class="bg-img" id="id_test_video" :src="liveApplyInfo.live_apply_play_rtmp_url"
  9. @statechange="videoStatechange">
  10. </live-player>
  11. <!-- #endif -->
  12. <main-content v-if="isTest || isPlay" :liveApplyInfo="liveApplyInfo" :onlineInfo="onlineInfo"></main-content>
  13. </view>
  14. <uni-popup background-color="#fff" ref="confirm" type="dialog">
  15. <uni-popup-dialog :mode="dialog.mode" :title="dialog.title" :content="dialog.content"
  16. :placeholder="dialog.content" @confirm="confirmDialog" @close="closeDialog"></uni-popup-dialog>
  17. </uni-popup>
  18. </member-base>
  19. </template>
  20. <script>
  21. import {getFontSize} from '@/util/common'
  22. import {
  23. mapState,
  24. mapActions
  25. } from 'vuex'
  26. import MemberBase from '../MemberBase'
  27. import mainContent from './child/main-content'
  28. import {
  29. loadScript,
  30. loadCSS
  31. } from '../../../util/common'
  32. import {
  33. getLiveInfo
  34. } from '../../../api/memberLive'
  35. export default {
  36. data() {
  37. return {
  38. dialog: {},
  39. isTest: 0,
  40. live_apply_id: 0,
  41. isPlay: false,
  42. liveApplyInfo: false,
  43. onlineInfo:false
  44. }
  45. },
  46. computed:{
  47. fontSize(){
  48. return getFontSize()
  49. },
  50. ...mapState({
  51. config: state => state.config.config,
  52. }),
  53. },
  54. components: {
  55. MemberBase,
  56. mainContent
  57. },
  58. onLoad: function(option) {
  59. this.isTest = option.test ? 1 : 0
  60. this.fetchConfig({})
  61. this.live_apply_id = option.live_apply_id
  62. if (!this.live_apply_id) {
  63. uni.showToast({
  64. icon: 'none',
  65. title: '参数错误'
  66. })
  67. }
  68. const res = uni.getSystemInfoSync()
  69. var width = res.windowWidth
  70. var height = res.windowHeight
  71. getLiveInfo(this.live_apply_id).then(res => {
  72. this.liveApplyInfo = res.result.live_apply_info
  73. this.onlineInfo=res.result.online_info
  74. // #ifdef MP-WEIXIN
  75. var player = uni.createLivePlayerContext("id_test_video", this)
  76. player.play()
  77. // #endif
  78. // #ifdef H5
  79. var _this = this
  80. if (this.config.video_type == 'aliyun') {
  81. loadCSS('aliplayer', 'https://g.alicdn.com/de/prismplayer/2.8.2/skins/default/aliplayer-min.css')
  82. loadScript('aliplayer', 'https://g.alicdn.com/de/prismplayer/2.8.2/aliplayer-min.js', function() {
  83. var player = new Aliplayer({
  84. "id": "id_test_video",
  85. "source": _this.liveApplyInfo.live_apply_play_url,
  86. "width": width,
  87. "height": height,
  88. "autoplay": true,
  89. "isLive": true,
  90. "rePlay": false,
  91. "playsinline": true,
  92. "preload": true,
  93. "controlBarVisibility": "hover",
  94. "useH5Prism": true
  95. }, function(player) {
  96. player.play();
  97. player.on('play', function() {
  98. _this.videoPlay()
  99. });
  100. player.on('pause', function() {
  101. _this.videoPause()
  102. });
  103. player.on('liveStreamStop', function() {
  104. _this.videoEnded()
  105. });
  106. });
  107. })
  108. } else {
  109. loadScript('TcPlayer', '//imgcache.qq.com/open/qcloud/video/vcplayer/TcPlayer-2.3.2.js', function() {
  110. var player = new TcPlayer('id_test_video', {
  111. 'm3u8_hd': _this.liveApplyInfo.live_apply_play_url, // 请替换成实际可用的播放地址
  112. // 'autoplay': true, // iOS 下 safari 浏览器,以及大部分移动端浏览器是不开放视频自动播放这个能力的
  113. 'live': true,
  114. 'controls': 'system',
  115. 'systemFullscreen': true,
  116. 'width': width,
  117. 'height': height,
  118. 'x5_player': true,
  119. 'x5_type': 'h5',
  120. 'x5_fullscreen': 'true',
  121. 'listener': function(res) {
  122. if (res.type == 'play') {
  123. _this.videoPlay()
  124. } else if (res.type == 'pause') {
  125. _this.videoPause()
  126. } else if (res.type == 'error') {
  127. _this.videoEnded()
  128. }
  129. }
  130. })
  131. })
  132. }
  133. // #endif
  134. }).catch(res => {
  135. if(res.result.live_apply_info){
  136. this.isTest=1
  137. this.liveApplyInfo = res.result.live_apply_info
  138. }
  139. uni.showToast({
  140. icon: 'none',
  141. title: res.message
  142. })
  143. })
  144. },
  145. methods: {
  146. closeDialog() {},
  147. confirmDialog(value) {
  148. switch (this.dialog.condition) {
  149. case 1:
  150. uni.navigateTo({
  151. url: '/pages/member/live/LiveList'
  152. })
  153. break
  154. }
  155. },
  156. videoPlay() {
  157. this.isPlay = true
  158. },
  159. videoPause() {
  160. this.isPlay = false
  161. },
  162. videoEnded(type) {
  163. console.log(type)
  164. this.dialog = {
  165. condition: 1,
  166. content: '主播已离开,是否要看看其他直播?'
  167. }
  168. this.$refs.confirm.open()
  169. },
  170. videoStatechange(e) {
  171. console.log(e)
  172. switch (e.detail.code) {
  173. case 2004:
  174. this.videoPlay()
  175. break
  176. case 2006:
  177. case -2301:
  178. this.videoEnded()
  179. break
  180. }
  181. },
  182. ...mapActions({
  183. fetchConfig: 'fetchConfig'
  184. }),
  185. }
  186. }
  187. </script>
  188. <style lang="scss" scoped>
  189. .room-bg {
  190. position: relative;
  191. }
  192. .bg-img {
  193. height: 100vh;
  194. width: 100vw;
  195. position: fixed;
  196. top: 0;
  197. left: 0;
  198. z-index: 0;
  199. }
  200. </style>