美文网首页
vue-Vidoe视频播放

vue-Vidoe视频播放

作者: 等级7 | 来源:发表于2022-07-05 10:44 被阅读0次
<template>
  <div class="video" ref="vcontainer">
    <video
      class="video__player"
      ref="v"
      @timeupdate="handleTimeUpdate"
      @ended="handleEnd"
    >
      <!-- <source :src="videoSrc" /> -->
      <source src="http://qn-dmagic.dmagic.cn/202012071106711919_58274_git协同出现版本冲突的处理.mp4" />
    </video>
    <div class="controller">
      <div class="controller__btn-wrapper">
        <div class="controller__btn" @click="togglePlaying">
          <!-- <font-awesome-icon
            :icon="['fas', 'play']"
            v-if="isPaused"
          ></font-awesome-icon>
          <font-awesome-icon
            :icon="['fas', 'pause']"
            v-else
          ></font-awesome-icon> -->
          开始
        </div>
        <div class="controller__btn" @click="stopPlaying">
          <!-- <font-awesome-icon :icon="['fas', 'stop']"></font-awesome-icon> -->
          暂停
        </div>
        <div class="controller__btn" @click="toggleMute">
          <!-- <font-awesome-icon
            :icon="['fas', 'volume-up']"
            v-if="isMuted"
          ></font-awesome-icon>
          <font-awesome-icon
            :icon="['fas', 'volume-mute']"
            v-else
          ></font-awesome-icon> -->
          声音
        </div>
        <div class="controller__timer">
          {{ videoTime }}
        </div>
        <div
          class="controller__btn controller__btn--fullscreen"
          @click="toggleFullscreen"
        >
          <!-- <font-awesome-icon :icon="['fas', 'expand']"></font-awesome-icon> -->
          全屏
        </div>
      </div>
    </div>
  </div>
</template>

<script>
function secToTimer(originalSec) {
  const min = Math.floor(originalSec / 60);
  const sec = Math.floor(originalSec % 60);
  const minStr = min < 10 ? `0${min}` : String(min);
  const secStr = sec < 10 ? `0${sec}` : String(sec);
  return `${minStr}:${secStr}`;
}

export default {
  name: "videoPage",
  props: ["videoSrc"],//传入的视频连接
  data() {
    return {
      video: null,
      isPaused: true,
      isMuted: false,
      videoTime: "00:00 / 00:00"
    };
  },
  methods: {
    toggleFullscreen() {
      const isFullscreen = document.webkitIsFullScreen || document.fullscreen;
      if (isFullscreen) {
        const exitFunc =
          document.exitFullscreen || document.webkitExitFullscreen;
        exitFunc.call(document);
      } else {
        const element = this.$refs.vcontainer;
        const fullscreenFunc =
          element.requestFullscreen || element.webkitRequestFullScreen;
        fullscreenFunc.call(element);
      }
    },
    handleTimeUpdate() {
      this.videoTime = this.refreshTime();
    },
    refreshTime() {
      if (!this.video) {
        return `${secToTimer(0)} / ${secToTimer(0)}`;
      }
      const currTime = this.video.currentTime || 0;
      const duration = this.video.duration || 0;
      return `${secToTimer(currTime)} / ${secToTimer(duration)}`;
    },
    //开始和暂停按钮
    togglePlaying() {
      if (this.video.paused) {
        this.playVideo();
      } else {
        this.pauseVideo();
      }
    },
    stopPlaying() {
      this.video.currentTime = 0;
      this.pauseVideo();
    },
    toggleMute() {
      this.video.muted = !this.video.muted;
      this.isMuted = this.video.muted;
    },
    handleEnd() {
      this.pauseVideo();
    },
    playVideo() {
      this.isPaused = false;
      this.video.play();
    },
    pauseVideo() {
      this.isPaused = true;
      this.video.pause();
    }
  },
  mounted() {
    this.video = this.$refs.v;
  }
};
</script>

<style scoped>
.video {
  position: relative;
}

.video__player {
  width: 100%;
  height: 100%;
  display: flex;
}

.controller {
  flex-direction: column;
  height: 50px;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  background: rgba(0, 0, 0, 0.5);
}

.controller__btn-wrapper {
  position: relative;
  height: calc(100% - 5px);
  display: flex;
  align-items: center;
  color: #fff;
  padding: 0 18px;
}

.controller__btn {
  cursor: pointer;
  transition: 0.5s;
  margin: 0 20px;
   border: 1px #fff solid;
  width: 20px;
  height: 20px;
}

.controller__btn:hover {
  color: #409eff;
}

.controller__timer {
  margin-left: 15px;
}

.controller__btn--fullscreen {
  position: absolute;
  right: 15px;
  border: 1px #fff solid;
  width: 20px;
  height: 20px;
}
</style>

相关文章

  • vue-Vidoe视频播放

  • 初级视频播放功能

    打开相册选择视频 使用系统播放器播放视频 使用VideoView播放视频 使用SurfaceView播放视频 vo...

  • 3.4 音频播放.视频播放.相册调用.相机调用

    音频播放.视频播放.相册调用.相机调用 音频播放 视频播放 相册调用 视频音频资源 视频音频资源.png

  • 视频播放器

    系统播放器 打开视频列表 调用系统播放器播放视频 调用系统播放器播放网络视频 VideoView播放器 调用 V...

  • 视频播放

  • 视频播放

    import "ViewController.h" import "ZSPlayerView.h" @interf...

  • 视频播放

    NSString *file = [[NSBundle mainBundle]pathForResource:@"...

  • 视频播放

    视频播放器的实现有多种方式,此处主要针对主流方式实现一个播放器 MediaPlayer框架

  • 视频播放

    一. 视频播放介绍 实现方案四种: 1.AVPlayer 2.MPMoviePlayerControlle 3.M...

  • 播放视频

    主要使用 VideoView 类来实现。和 MediaPlayer 比较类似。 VideoView工作流程 1. ...

网友评论

      本文标题:vue-Vidoe视频播放

      本文链接:https://www.haomeiwen.com/subject/pacsbrtx.html