123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152 |
- <template>
- <view>
- <ujp-navbar title="设备详情"></ujp-navbar>
- <view style=" padding: 10px 16px;
- font-size: 16px;" >{{detail.deviceName}}<span style="float: right;"><span class="boot" :class="{
- boot2:detail.status
- }"></span>{{detail.status?'在线':'离线'}}</span></view>
- <img src="@/assets/img/gkke02.png" v-if="!detail.status" style="width: 100%;height: 234px;" />
-
- <view class="video-wrap" style="width: 100%;height: 234px;"
- v-html="html"
- v-show="detail.status" ref="videoWrapHls">
-
- </view>
- <!-- -->
- <view style=" text-align: center;" v-if="endTime">
- <u-button
- type="primary" size="medium"
- @click="getInfo" >继续播放</u-button>
- </view>
- <view style="padding: 10px ;" v-if="endTime">
- 单次播放时间为{{expireTime/60}}分钟;<br/>
- 过期后可点击“继续播放”
- </view>
- </view>
- </template>
- <script>
- import * as API from '@/apis/finance.js'
-
- //import Hls from '@/apis/hls.js';
- // import videojs from '@/apis/video.js'
- import Hls from 'hls.js'
- export default {
- data() {
- return {
- html:'<video id="myVideo" autoplay controls style="width: 100%; height: 234px;"><source id="myVideoSource" type="application/x-mpegURL" /></video>',
- subForm: {},
- liveAddressUrl: "",
- detail: {},
- hls: null,
- player: null,
- expireTime:10*60,
- endTime:0,
- }
- },
- onLoad(op) {
- this.subForm.id=op.id;
- },
- onReady() {
- //uniapp 渲染有问题, 自主渲染
- if(!this.player){
- // var video = document.createElement('video');
- // video.id = 'myVideo';
- // video.style="width: 100%;height: 234px;"
- // this.$refs.videoWrapHls.$el.appendChild(video);
- // this.player = video;
- var video=document.getElementById("myVideo")
- this.player = video;
- }
- this.getInfo();
-
- },
- methods: {
- getInfo(){
- uni.showLoading({
- title: "加载中",
- mask: true,
- })
- //秒
- this.subForm.expireTime=this.expireTime
- API.cameraDetail(this.subForm).then((res) => {
- this.detail=res.data.cameraInfo;
- this.endTime=0;
- if(this.detail.status&&res.data.liveJson){
- var myVideoSource =document.getElementById("myVideoSource")
-
- myVideoSource.src=this.liveAddressUrl;
-
- this.liveAddressUrl = res.data.liveJson.url
-
- var endTime=new Date(res.data.liveJson.expireTime).getTime()
- var nowTime=new Date().getTime()
-
- setTimeout(()=>{
- this.endTime=1;
- },endTime-nowTime)
-
- this.$nextTick(()=>{
- this.play();
- })
- }
-
- uni.hideLoading()
-
-
-
- }).catch(error => {
- uni.showToast({
-
- title: error
- })
- })
- },
- handlePlay() {
- },
- play() {
- var video= this.player;
-
- this.liveAddressUrl = this.liveAddressUrl.replace("http:", "https:");
- var videoSrc = this.liveAddressUrl;
- if (Hls.isSupported()) {
- var hls = new Hls();
- hls.loadSource(videoSrc);
- hls.attachMedia(video);
- hls.on(Hls.Events.MANIFEST_PARSED, () => {
- video.play();
- });
- this.hls = hls;
- } else if (video.canPlayType('application/vnd.apple.mpegurl')) {
- video.src = videoSrc;
- video.addEventListener('loadedmetadata', () => {
- video.play();
- });
- }
- //监听开始播放事件
- // this.player.addEventListener('play', this.handlePlay);
-
- }
- }
- }
- </script>
- <style scoped>
- .boot{
-
- display: inline-block;
- width: 12px;
- height: 12px;
- margin-left: 2px;
- background-color: rgba(255, 115, 0, 100);
- border-radius: 999px;
-
- }
- .boot2{
- background-color:rgba(0, 185, 98, 100)
- }
- </style>
|