vue使用海康H5视频播放器实现轮播功能

功能描述:点击左右按钮可以实现轮播视频的功能

需要引入的文件这个就不说了,不了解的可以去看我写的vue使用海康H5视频播放器这篇文章,后面里面所引用的VideoPlayer以及randomLenNum也可以在文章里面查找

首先在views下面创建一个vue文件:

父组件:

<template>
  <div style="width: 1230px; margin-left: 20px;"
    :style="{height: heightType == 1 ? '560px' : heightType == 2 ? '900px' : '0px'}">
    <div class="video-content" @mouseover="showPopup()" @mouseleave="hidePopup()">
      <div class="video-box">
        <el-carousel
          ref="carousel"
          :autoplay="false"
          height="150px"
          :loop="true"
          arrow="never"
          indicator-position="none">
          <el-carousel-item
            v-for="(item, index) in this.videoList"
            :key="index" v-loading="loading"
      element-loading-text="正在加载中,请稍后..."
      element-loading-spinner="el-icon-loading"
      element-loading-background="rgba(12,35,63, 0.8)">
            <video-player  ref="player" :option="videoOption"></video-player>
          </el-carousel-item>
        </el-carousel>
      </div>
      <div style="width: 100%; height: 100%" v-show="isShow">
        <el-button
          class="el-carousel__arrow el-carousel__arrow--left"
          @click="change('prev')">
          <i class="el-icon-arrow-left"></i>
        </el-button>
        <el-button
          class="el-carousel__arrow el-carousel__arrow--right"
          @click="change('next')">
          <i class="el-icon-arrow-right"></i>
        </el-button>
      </div>
    </div>
  </div>
</template>
<script>
import VideoPlayer from "@/components/videoPlayer";
import { randomLenNum } from "@/util/util";
export default {
  components: {
    VideoPlayer,
  },
  data() {
    return {
      videoOption: {
        width: "1230px",
        height: "548px",
        split: 1,
        id: randomLenNum(6),
      },
      videoList: [],
      isShow: false,
      currentCameraIndex: 0,
      loading: true
    };
  },
  mounted() {
    this.onLoad();
  },
  methods: {
    showPopup() {
      this.isShow = true;
    },
    hidePopup() {
      this.isShow = false;
    },
    onLoad() {
        //获取当前的父级
        this.$axios.get("xxx/station?type=station" + "&id=" + this.id + "&ping=1")
        .then((res) => {
          const dataList = res.data.data;
          this.videoList = dataList;
          //默认播放第一个视频  
          this.$axios.get("xxx/getliu?type=camera" + "&id=" + this.videoList[this.currentCameraIndex] + "&ping=1")
          .then((res) => {
            const dataList = res.data.data;
            for(let i = 0; i < dataList.length; i++){
              setTimeout(()=>{
                this.loadVideo(dataList[i].stream,i);
              },1000)
            }
          });
        });

    },
    change(type) {
      this.loading = true
      if (type == "prev") {
        this.currentCameraIndex--;
        if (this.currentCameraIndex == -1) {
          this.currentCameraIndex = this.videoList.length - 1;
        }
      } else {
        this.currentCameraIndex++;
        if (this.currentCameraIndex == this.videoList.length) {
          this.currentCameraIndex = 0;
        }
      }
        //获取流  左右切换的时候根据获取的所有子级id的索引获取当前所播放的视频流
        this.$axios.get("xxx/getliu?type=camera" + "&id=" + this.videoList[this.currentCameraIndex] + "&ping=1")
          .then((res) => {
            const dataList = res.data.data;
            for(let i = 0; i < dataList.length; i++){
              setTimeout(()=>{
                this.loadVideo(dataList[i].stream,i);
              },1000)
            }
          });
    },
    loadVideo(liuName, index) {
      this.$refs.player[0].initPlayer(this.videoOption);
      let param = {
        url: liuName,
        index: index,
      };
      this.$refs.player[0].play(param);
      setTimeout(()=>{
        this.loading = false
      },1000)
    },
  },
};
</script>
<style lang="scss" scoped>
.video-content {
  width: 100%;
  height: 100%;
  padding: 36px 6px 0;
  position: relative;
  .video-box {
    width: 100%;
    height: 100%;
    position: absolute;
  }
}

::v-deep .el-carousel,
::v-deep .el-carousel__container {
  height: 100% !important;
}

::v-deep .el-icon-arrow-left,
::v-deep .el-icon-arrow-right {
  font-size: 40px;
  color: #fff;
}

::v-deep .el-carousel__item {
  color: #fff;
}

::v-deep .el-button {
  width: 70px;
  height: 70px;
  line-height: 70px;
  font-size: 55px;
  background-color: rgba(31, 45, 61, 0.7);
  border-radius: 50%;
  border: 1px solid rgba(31, 45, 61, 0.7);
}

::v-deep .el-carousel__arrow i{
  transform: translateX(-5px) translateY(-15px);
}

::v-deep .el-carousel__arrow--left{
  transform: translateX(40px);
}

::v-deep .el-carousel__arrow--right{
  transform: translateX(-40px);
}
</style>

效果图:

  • 8
    点赞
  • 6
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
Vue3是一个流行的JavaScript框架,用于构建用户界面。H5是指基于HTML5标准开发的移动端网页,用于在移动设备上展示内容。海康是一家专注于视频图像处理技术的公司,提供视频监控解决方案。WS是指WebSocket,它是一种在客户端和服务器之间实现双向通信的协议。在线视频播放器指的是能够在网页上直接播放视频的工具。 基于Vue3的H5海康WS在线视频播放器是一个使用Vue3框架开发的适用于移动设备的在线视频播放器。它可以通过WebSocket与海康设备建立实时的视频流通信。通过使用H5技术,用户只需在移动设备上打开网页就可以实时观看海康设备传输的视频。 该播放器可以实现以下功能: 1. 实时观看视频传输:用户可以通过播放器直接观看海康设备传输的实时视频流,无需安装任何额外的应用程序。 2. 视频控制:播放器提供基本的视频控制功能,如播放、暂停、快进、快退等,用户可以根据自己的需求来控制视频播放。 3. 分辨率调节:播放器可以根据网络情况自动调整视频传输的分辨率,确保在恶劣网络环境下仍能流畅观看视频。 4. 声音控制:用户可以通过播放器控制海康设备的音频播放,根据需要开启或关闭设备的声音。 5. 全屏播放:播放器支持全屏播放模式,用户可以通过点击按钮将播放器切换到全屏模式,更好地观看视频。 总之,基于Vue3的H5海康WS在线视频播放器提供了便捷的视频观看体验,让用户能够通过移动设备方便地实时观看海康设备的视频传输。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值