minhangChannel.vue 4.65 KB
<template>
  <div id="channelList" style="width: 100%">
    <div class="page-header">
      <div class="page-title">
        <el-button icon="el-icon-back" size="mini" style="font-size: 20px; color: #000;" type="text"
          @click="showDevice"></el-button>
        <el-divider direction="vertical"></el-divider>
        设备列表
      </div>
    </div>
    <el-dialog title="视频播放" top="0" :close-on-click-modal="false" :visible.sync="showVideoDialog" @close="close()"
      v-if="showVideoDialog">
      <div style="width: 100%; height: 100%">
        <!-- 使用video播放视频铺满 -->
        <video ref="myVideo" autoplay controls width="100%" height="500" id="myVideo"></video>
      </div>
    </el-dialog>
    <el-container style="height: 82vh;">
      <el-main style="padding: 5px;">
        <el-table ref="channelListTable" :data="deviceChannelList" :height="winHeight" style="width: 100%"
          header-row-class-name="table-header">
          <el-table-column prop="name" label="通道名称" min-width="180">
          </el-table-column>
          <el-table-column label="操作" width="100" fixed="right">
            <template slot-scope="scope">
              <el-button @click="handlerOnPlay(scope.row)" size="medium" icon="el-icon-video-play" type="text">播放
              </el-button>
            </template>
          </el-table-column>
        </el-table>
      </el-main>
    </el-container>
  </div>
</template>

<script>
import flvjs from 'flv.js';
import MinhangService from "../service/MinhangService.js";
export default {
  name: 'minhangChannel',
  data() {
    return {
      videoUrl: "",
      player: null,
      hasAudio: false,
      showVideoDialog: false,
      minhangService: new MinhangService(),
      deviceId: this.$route.params.deviceId,
      deviceChannelList: [
        {
          channelId: 5,
          name: "车前",
        },
        {
          channelId: 3,
          name: "驾驶舱"
        },
        {
          channelId: 0,
          name: "中门",
        },
        {
          channelId: 4,
          name: "前门"
        },
        {
          channelId: 2,
          name: "后车厢"
        },
        {
          channelId: 7,
          name: "右后视镜"
        },
        {
          channelId: 6,
          name: "倒车"
        },
        {
          channelId: 1,
          name: "前车箱"
        },
      ],
      online: "",
      subStream: "",
      winHeight: window.innerHeight - 200,
      currentPage: 1,
      count: 15,
      total: 0,
    };
  },

  mounted() {
    this.initData();

  },
  destroyed() {
    if (!this.player) return
    this.player.pause()
    this.player.unload()
    this.player.detachMediaElement()
    this.player.destroy()
    this.player = null
  },
  methods: {
    createdPlay() {
      if (flvjs.isSupported()) {
        // var videoDom = document.getElementById('myVideo')
        console.log(this.videoUrl);
        let videoDom = this.$refs.myVideo
        // 创建一个播放器实例
        var player = flvjs.createPlayer({
          type: 'flv', // 媒体类型,默认是 flv,
          isLive: true, // 是否是直播流
          url: this.videoUrl // 流地址
        }, {
          // 其他的配置项可以根据项目实际情况参考 api 去配置
          autoCleanupMinBackwardDuration: true, // 清除缓存 对 SourceBuffer 进行自动清理
        })
        player.attachMediaElement(videoDom)
        player.load()
        player.play()
        this.player = player
      }
    },
    showDevice() {
      this.$router.push({ name: 'minhang' })
    },
    initData() {

    },
    handlerOnPlay(val) {
      this.minhangService.onPlay(this.deviceId, val.channelId, (res => {
        this.videoUrl = res.data
        this.showVideoDialog = true
        this.$nextTick(() => {
          this.createdPlay()
        })
      }))
    },
    close() {
      this.showVideoDialog = false
    }
  }
};
</script>

<style>
.videoList {
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
}

.video-item {
  position: relative;
  width: 15rem;
  height: 10rem;
  margin-right: 1rem;
  background-color: #000000;
}

.video-item-img {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 100%;
  height: 100%;
}

.video-item-img:after {
  content: "";
  display: inline-block;
  position: absolute;
  z-index: 2;
  top: 0;
  bottom: 0;
  left: 0;
  right: 0;
  margin: auto;
  width: 3rem;
  height: 3rem;
  background-size: cover;
  background-color: #000000;
}

.video-item-title {
  position: absolute;
  bottom: 0;
  color: #000000;
  background-color: #ffffff;
  line-height: 1.5rem;
  padding: 0.3rem;
  width: 14.4rem;
}
</style>