vue中使用vue-video-player插件播放视频 以及 audio播放音频

embedded/2024/10/15 18:23:56/

一、使用vue-video-player插件播放视频

安装

  npm install vue-video-player --save

在main.js中引用

//引入视频播放插件
// main.js
import VueVideoPlayer from 'vue-video-player'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'Vue.use(VueVideoPlayer)

在组件中使用

<template><div class="playerBOx"><video-player ref="videoPlayer" class="player-video vjs-custom-skin" :playsinline="false" :options="playOptions"@play="onPlayerPlay($event)"  @ended="onPlayerEnd($event)"@waiting="onPlayerWaiting($event)" @timeupdate="onPlayerTimeupdate($event)"@statechanged="playerStateChanged($event)" /></div>
</template><script>
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'export default {components: {videoPlayer},props: {path: {  // 传入的地址type: String,default: "",},lastTime: {  // 传入的上次播放位置type: Number,default: 0,},videoType: {type: String,default: "",}},data() {return {playedTime: this.lastTime,currentTime: 0,maxTime: 0,playOptions: {playbackRates: [0.5, 1.0, 1.5, 2.0], // 可选的播放速度autoplay: false, // 如果为true,浏览器准备好时开始回放muted: false, // 默认情况下静音播放loop: false, // 是否视频一结束就重新开始preload: "auto", // 建议浏览器在<video>加载元素后是否应该开始下载视频数据,auto浏览器选择最佳行为,立即开始加载视频(如果浏览器支持)language: "zh-CN",aspectRatio: "16:9", // 将播放器置于流畅模式,并在计算播放器的动态大小时使用该值,值应该代表一个比例 - 用冒号分隔的两个数字(例如"16:9"或"4:3")fluid: true, // 当true时,Video.js player将拥有流体大小,换句话说,它将按比例缩放以适应其容器sources: [{type: `video/${this.videoType}`, // 类型src: this.path, // url地址,在使用本地的资源时,需要用require()引入,否则控制台会报错},],poster: '', // 设置封面地址notSupportedMessage: "此视频暂无法播放,请稍后再试", // 允许覆盖Video.js无法播放媒体源时显示的默认信width: 1900,controlBar: {currentTimeDisplay: true,progressControl: true,  // 是否显示进度条playbackRateMenuButton: true, // 是否显示调整播放倍速按钮timeDivider: true, // 当前时间和持续时间的分隔符durationDisplay: true, // 显示持续时间remainingTimeDisplay: true, // 是否显示剩余时间功能fullscreenToggle: true, // 是否显示全屏按钮// volumeControl:true,},},}},computed: {},mounted() {},methods: {// 视频暂停的onPlayerPause(player) {// this.$refs.videoPlayer.player.pause() // 暂停},// 视频播放回调onPlayerPlay(player) {// this.$refs.videoPlayer.player.play() // 播放},// 视频播放完onPlayerEnd(player) {// this.$refs.videoPlayer.player.src(this.path) // 重置进度条复制代码console.log(player);},// DOM元素上的readyState更改导致播放停止onPlayerWaiting(player) {console.log("播放停止中");},// 视频已开始播放onPlayerPlaying(player) {// console.log("开始播放了");// console.log(player);},// 当播放器在当前播放位置下载数据时触发onPlayerLoadeddata(player) {console.log("开始下载数据");},// 当前播放位置发生变化时触发onPlayerTimeupdate(player) {this.currentTime = player.currentTime();this.maxTime = this.currentTime > this.maxTime ? this.currentTime : this.maxTime;},//播放状态改变playerStateChanged(playerCurrentState) {console.log("播放状态变化了");},},mounted() {},
};
</script><style lang="scss">
.playerBOx {width: 100%;height: 100%;margin: 0 auto;position: relative;
}.vjs-custom-skin>.video-js {width: 100% !important;height: 100% !important;
}.video-player {width: 100% !important;height: 100% !important;
}.vjs-fluid {padding-top: 0 !important;background-color: rgba(0, 0, 0, 0.45);
}.video-js {position: static !important;
}/*播放按钮设置成宽高一致,圆形,居中*/
.vjs-custom-skin>.video-js .vjs-big-play-button {background-color: rgba(0, 0, 0, 0.45);font-size: 3.5em;border-radius: 50%;height: 2em !important;line-height: 2em !important;margin-top: -1em !important;margin-left: -1em !important;width: 2em !important;outline: none;
}.video-js .vjs-big-play-button .vjs-icon-placeholder:before {position: absolute;left: 0;width: 100%;height: 100%;
}/*control-bar布局时flex,通过order调整剩余时间的位置到进度条右边*/
.vjs-custom-skin>.video-js .vjs-control-bar .vjs-remaining-time {order: 3 !important;
}/*进度条背景轨道*/
.video-js .vjs-slider {border-radius: 1em;
}/*进度条进度*/
.vjs-custom-skin>.video-js .vjs-play-progress,
.vjs-custom-skin>.video-js .vjs-volume-level {border-radius: 1em;
}/*鼠标进入播放器后,播放按钮颜色会变*/
.video-js:hover .vjs-big-play-button,
.vjs-custom-skin>.video-js .vjs-big-play-button:active,
.vjs-custom-skin>.video-js .vjs-big-play-button:focus {background-color: rgba(0, 0, 0, 0.4) !important;
}/*control bar*/
.video-js .vjs-control-bar {background-color: rgba(0, 0, 0, 0.2) !important;
}/*点击按钮时不显示蓝色边框*/
.video-js .vjs-control-bar button {outline: none;
}
</style>

 二、audio播放音频

<template><div><div class="containeraudioBox"><div class="topAudioBox"><img src="../assets/close.png" alt="" @click="close"></div><div class="audioBox"><audioclass="audio":src="autioPath"autoplay="autoplay"controls="controls"ref="audio">音频</audio></div></div></div>
</template><script>export default {props: {autioPath: {  // 传入的地址type: String,default: "",},},data() {return {}},methods: {//点击关闭弹窗close(){//   this.playOptions.sources[0].src=''this.$refs.audio.pause()// 重置进度条复制代码this.$emit('closeVideo',false)}, //  //播放组件// handlePlay(row) {// this.src = row.filePath;// this.play();// },// //播放// play() {// this.dialogVisible = true;// this.$refs.audio.play();// },// //音频暂停// stop() {// this.dialogVisible = false;// this.$refs.audio.pause();// this.$refs.audio.currentTime = 0;// }},mounted () {console.log(this.autioPath);;},    }
</script><style lang="scss">
.containeraudioBox{width: 100%;height:100vh;
}
.containeraudioBox .topAudioBox{height: 120px;width: 100%;position: relative;}.containeraudioBox .topAudioBox img{width: 30px;height: 30px;position: absolute;z-index: 9999;top: 60px;right: 180px;cursor: pointer;}
.audioBox{width: 100%;height:calc(100% - 90px);position: relative;
}
.audio{width: 60%;// height: 100%;position: absolute;top: 50%;left: 50%;transform: translate(-50%,-50%);}
</style>


http://www.ppmy.cn/embedded/101533.html

相关文章

CPU、MPU、MCU、SOC分别是什么?

CPU、MPU、MCU和SoC都是与微电子和计算机科学相关的术语&#xff0c;它们在功能定位、应用场景以及处理能力等方面有所区别。具体如下&#xff1a; CPU&#xff1a;CPU是中央处理单元的缩写&#xff0c;它通常指计算机内部负责执行程序指令的芯片。CPU是所有类型计算机&#x…

SNP亮相 2024 SAP高科技行业峰会:科技新引擎 智领新增长

8月15日&#xff0c;以“科技新引擎 智领新增长”为主题的2024思爱普中国峰会行业论坛——SAP高科技行业峰会在上海成功举办。SNP中国受邀参与本次峰会&#xff0c;并发表主题演讲《云时代企业ERP升级创新实践案例》。合作伙伴ABeam、微软及100多位高科技行业CIO共同出席了本次…

SFF1604-ASEMI无人机专用SFF1604

编辑&#xff1a;ll SFF1604-ASEMI无人机专用SFF1604 型号&#xff1a;SFF1604 品牌&#xff1a;ASEMI 封装&#xff1a;ITO-220AB 批号&#xff1a;最新 恢复时间&#xff1a;35ns 最大平均正向电流&#xff08;IF&#xff09;&#xff1a;16A 最大循环峰值反向电压&a…

Python 爬虫框架

Python 中有许多强大且主流的爬虫框架&#xff0c;这些框架提供了更高级的功能&#xff0c;使得开发和维护爬虫变得更加容易。以下是一些常用的爬虫框架&#xff1a; 1. Scrapy - 简介: Scrapy 是 Python 最流行的爬虫框架之一&#xff0c;设计用于快速、高效地从网站中提取…

回答评论:使用流遍历文件 list

网友视频评论 回答评论&#xff1a; arraylist里包含了一个文件夹内部文件和子文件夹 怎么使用steam 可以遍历整个文件夹 最后生成的集合里是所有的文件路径&#xff0c;比如D:/test test文件夹里面有1.mp4, test2,test3的文件夹&#xff0c; test2和test3内部也嵌套了文件夹和…

开源程序实操:岩土工程渗流问题的有限单元法应用

有限单元法在岩土工程问题中应用非常广泛&#xff0c;很多商业软件如Plaxis/Abaqus/Comsol等都采用有限单元解法。尽管各类商业软件使用方便&#xff0c;但其使用对用户来说往往是一个“黑箱子”。相比而言&#xff0c;开源的有限元程序计算方法透明、计算过程可控&#xff0c;…

STM案例一:灯闪烁

一、使用元件 STlink&#xff0c;STM32F103C8T6 二、接线方法 STM32与STLINK的接线方法为&#xff1a; GND-->GND DCLK-->SWCLK DIO-->SWDIO 3.3-->3.3V 三、配置调试器 选择魔术棒按钮&#xff0c;单击Debug&#xff0c;选择ST-link Debug&#xff0c;选…

删除Vue2残留配置文件解决异常:Cannot find module ‘@vue/babel-plugin-transform-vue-jsx‘

背景 完成Vue2代码升级为Vue3后&#xff0c;将新代码上传至代码库。在修改源代码库代码后&#xff0c;启动项目&#xff0c;提示&#xff1a;Cannot find module ‘vue/babel-plugin-transform-vue-jsx‘&#xff0c;尝试安装该第三方库后仍然无效。 解决方案&#xff1a; 删…