Room.vue 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  1. <template>
  2. <div>
  3. <common @asynCallBack="asynCallBack"></common>
  4. <top-header :pageTitle="pageTitle" ></top-header>
  5. <div class="mui-content vongi-zbfj">
  6. <div class="mui-content-padded">
  7. <div class="fyy-video">
  8. <!--未开播状态-->
  9. <div class="mui-media-body" v-if="!detail.status">
  10. <img src="~$project/assets/img/gkke02.png" width="50"/>
  11. <h6>该直播间未开播</h6>
  12. </div>
  13. <video autoplay controls class="video" ref="myPlayer">
  14. <source :src="liveAddressUrl" type="application/x-mpegURL" />
  15. </video> </div>
  16. <div class="mui-table-view-cell flew-sp">
  17. {{detail.roomAddress}}
  18. <span class="color4fc5f7">[{{detail.status=='1'?'在线':'离线'}}]</span>
  19. </div>
  20. </div>
  21. <div class="mui-table-view-cell flew">
  22. 紧急联系热线
  23. <button class="mui-btn" type='button'>0716-8121234<span class="iconfont icon-ziyuan1"></span></button>
  24. </div>
  25. </div>
  26. <!--挂机弹窗-->
  27. <div class="vongi-popup" v-if="isLoading2">
  28. <div class="vongi-popup-bg"></div>
  29. <div class="vongi-popup-ceter vongi-zbfj-pop" style="top:10%">
  30. <div class="vongi-popup-inner">
  31. <div class="vongi-popup-ma">
  32. <img src="~$project/assets/img/lad.png" width="50%">
  33. <h3>还在观看吗?</h3>
  34. </div>
  35. <div class="vongi-btn vongi-login-btn">
  36. <button class="mui-btn mui-btn-pink"><spn class="iconfont icon-bofang"></spn>继续观看</button>
  37. <button class="mui-btn "><spn class="iconfont icon-tuichu4"></spn>结束观看</button>
  38. </div>
  39. </div>
  40. </div>
  41. </div>
  42. <loading :visible="isLoading"></loading>
  43. </div>
  44. </template>
  45. <script>
  46. import * as API_Common from '$project/apis/common'
  47. import * as API from '@/apis/Master/live'
  48. import Common from '$project/components/Common.vue'
  49. import Loading from '$project/components/Loading.vue'
  50. import TopHeader from '$project/components/TopHeader.vue'
  51. import Hls from 'hls.js'
  52. import {
  53. mapGetters,
  54. mapMutations
  55. } from 'vuex'
  56. import {
  57. currentTimeStamp,
  58. parseUnixTime
  59. } from '$project/utils'
  60. export default {
  61. name: 'GuestFromInfo',
  62. components: {
  63. Common,
  64. Loading,
  65. TopHeader
  66. },
  67. data() {
  68. return {
  69. pageTitle: '教室直播间',
  70. id: this.$route.query.id,
  71. detail: {
  72. status: 0
  73. },
  74. liveAddressUrl: "",
  75. player: {},
  76. list: [],
  77. isLoading: false,
  78. sz: ["", "一", "二", "三", "四", "五", "六", "日"],
  79. plan: "",
  80. planshow: false,
  81. hls: null,
  82. setTimeoutId:null,
  83. isLoading2:false,
  84. isLoading3:false,
  85. banner:null,
  86. serverList: [],
  87. bannerList:[],
  88. }
  89. },
  90. created() {
  91. this.id = this.$route.query.id;
  92. },
  93. methods: {
  94. getBannerInfo() {
  95. API_Common.getBannerInfo("4").then(response => {
  96. //this.bannerList = response;
  97. for (var i in response) {
  98. var mod = response[i];
  99. this.bannerList.push(mod);
  100. }
  101. if(this.bannerList.length>0){
  102. var x=Math.floor(Math.random()*this.bannerList.length);
  103. this.banner=this.bannerList[x];
  104. }
  105. }).catch(error => {
  106. this.isLoading = false;
  107. mui.toast(error);
  108. })
  109. },myback(){
  110. this.$router.push({
  111. name: 'Student',
  112. })
  113. },
  114. mystart(){
  115. if(this.isLoading3){
  116. window.location.reload();
  117. }else{
  118. this.player.play() //开始
  119. this.isLoading2=false;
  120. }
  121. }, handlePlay() {
  122. console.log("开始播放");
  123. if(this.player!=null){
  124. clearTimeout(this.setTimeoutId)
  125. this.setTimeoutId=setTimeout(()=> {
  126. console.log("延迟暂停");
  127. this.player.pause() //暂停
  128. if(document.exitFullscreen) {
  129. document.exitFullscreen();
  130. } else if(document.mozCancelFullScreen) {
  131. document.mozCancelFullScreen();
  132. } else if(document.webkitCancelFullScreen) {
  133. document.webkitCancelFullScreen();
  134. } else if(document.msExitFullscreen) {
  135. document.msExitFullscreen();
  136. }
  137. this.isLoading2=true;
  138. if(this.banner!=null){
  139. var x=Math.floor(Math.random()*this.bannerList.length);
  140. this.banner=this.bannerList[x];
  141. console.log(this.bannerList)
  142. console.log(x)
  143. }else{
  144. this.getSchoolServeList();
  145. }
  146. setTimeout(()=> {
  147. if(this.isLoading2){
  148. this.hls.stopLoad();
  149. this.isLoading3=true;//需要刷新;
  150. }
  151. },1000*60*1)
  152. },1000*60*10)
  153. }
  154. },
  155. getplan(mod) {
  156. return "每周" + this.sz[mod.week] + mod.startTime + '-' + mod.endTime + "开播";
  157. },
  158. play() {
  159. this.liveAddressUrl = this.liveAddressUrl.replace("http:", "https:");
  160. this.player = this.$refs["myPlayer"];
  161. var userAgent = navigator.userAgent;
  162. if (/(iPhone|iPad|iPod|iOS)/i.test(userAgent)) {
  163. //this.player.play();
  164. console.log("ios原生支持播放m3u8!");
  165. } else {
  166. this.player.addEventListener('play', this.handlePlay);
  167. var hls = new Hls();
  168. hls.loadSource(this.liveAddressUrl);
  169. hls.attachMedia(this.player);
  170. hls.on(Hls.Events.MANIFEST_PARSED, () => {
  171. this.player.play();
  172. });
  173. this.hls = hls;
  174. }
  175. },
  176. cameraDetail(){
  177. var week = new Date().getDay();
  178. if (week == 0) {
  179. week = 7;
  180. }
  181. this.isLoading = true;
  182. API.cameraDetail({
  183. id:this.id
  184. }).then(response => {
  185. this.isLoading = false;
  186. this.detail = response.detail;
  187. var text = this.detail.roomAddress + "(" + this.detail.deviceSerial + ")";
  188. if (this.detail.status&& response.json) {
  189. //this.liveAddressUrl = response.json.hdAddress;
  190. this.liveAddressUrl = response.json.liveAddress;
  191. this.play();
  192. } else {
  193. this.isLoading = false;
  194. }
  195. }).catch(error => {
  196. this.isLoading = false;
  197. mui.toast(error);
  198. })
  199. },asynCallBack(){},
  200. },
  201. mounted() {
  202. console.log("open class living...");
  203. this.cameraDetail();
  204. },
  205. destroyed() {
  206. this.liveAddressUrl = "";
  207. console.log("页面销毁");
  208. if (this.$refs["myPlayer"] != null) {
  209. //this.player.dispose()
  210. this.$refs["myPlayer"].pause() //暂停
  211. this.$refs["myPlayer"].dispose() //销毁
  212. console.log("关闭视频流");
  213. }
  214. if (this.hls != null) {
  215. this.hls.destroy()
  216. this.hls.loadSource(this.liveAddressUrl);
  217. }
  218. },
  219. computed: {
  220. ...mapGetters({
  221. openId: 'wx_openid',
  222. token: 'token',
  223. person_data: 'person_data',
  224. person_popedom: 'person_popedom',
  225. })
  226. }
  227. }
  228. </script>
  229. <style scoped src="$project/assets/css/pension.css"></style>
  230. <style scoped src="$project/assets/css/xpwyfyy.css"></style>
  231. <style src="$project/assets/css/iconfont.css"></style>
  232. <style>
  233. </style>