国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件

這篇具有很好參考價(jià)值的文章主要介紹了vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件。希望對大家有所幫助。如果存在錯(cuò)誤或未考慮完全的地方,請大家不吝賜教,您也可以點(diǎn)擊"舉報(bào)違法"按鈕提交疑問。

1、背景

項(xiàng)目中有涉及視頻播放的需求,并且UI設(shè)計(jì)了樣式,與原生的視頻video組件有差異,所以使用了vue-video-player插件,并對vue-video-player進(jìn)行樣式改造,自定義播放暫停按鈕、全屏按鈕、時(shí)間進(jìn)度條樣式等,自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件等。

2、效果圖

這是樣式處理后的效果:
vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件
這是未處理樣式的效果:
vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件

3、代碼實(shí)現(xiàn)

3.1 安裝插件

我安裝的是指定版本npm install vue-video-player@5.0.1 --save,因?yàn)槲抑苯影惭b最新版本npm install vue-video-player --save項(xiàng)目就會報(bào)錯(cuò),如果你們安裝最新版本沒報(bào)錯(cuò)也可以安裝最新版。

安裝vue-video-player插件后不需要再安裝videojs插件,因?yàn)関ue-video-player已經(jīng)包含有videojs在里面了

3.2 引入、注冊插件

在main.js文件中,填入以下代碼

import VideoPlayer from 'vue-video-player/src'
import 'vue-video-player/src/custom-theme.css'
import 'video.js/dist/video-js.css'
Vue.use(VideoPlayer)
3.3 創(chuàng)建組件

在components文件夾下(隨意位置,導(dǎo)入的時(shí)候更改文件路徑就行),新建testVideo.vue文件,填入以下代碼

<template>
    <div class="video">
    	<!-- 使用組件 -->
      <video-player  class="video-player vjs-custom-skin"
           ref="videoPlayer"
           :playsinline="true"
           :options="playerOptions"
      ></video-player>
    </div>
</template>
<script>
// 以下三行一定要引入
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
// import 'video.js/dist/lang/zh-CN'
 
export default {
	// name: 'videoplayer',
	components: { // 必需引入
		videoPlayer
  },
  props: [ // 接收父組件的數(shù)據(jù)
    'mp4Pic',
    'mp4Url'
  ],
	data () {
		return {
			fileAreaHeight: 675,
			fileType: 'mp4', // 資源的類型
		}
	},
	computed: { // 使用計(jì)算屬性
	    playerOptions () {
	      const playerOptionsObj = {
	        playbackRates: [0.7, 1.0, 1.5, 2.0], //視頻播放速度
	        autoplay: false, // 如果true,瀏覽器準(zhǔn)備好時(shí)開始回放。
	        muted: false, // 默認(rèn)情況下將會消除任何音頻。
	        loop: false, // 導(dǎo)致視頻一結(jié)束就重新開始。
	        // preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應(yīng)該開始下載視頻數(shù)據(jù)。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)。
	        language: 'zh-CN',
	        // aspectRatio: '16:9', // 將播放器置于流暢模式,并在計(jì)算播放器的動態(tài)大小時(shí)使用該值。值應(yīng)該代表一個(gè)比例 - 用冒號分隔的兩個(gè)數(shù)字(例如"16:9"或"4:3")。
	        fluid: false, // 當(dāng)true時(shí),Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應(yīng)其容器。
	        sources: [{
	          type: 'video/' + this.fileType,	// 資源格式寫法:'video/mp4',否則控制臺會出現(xiàn)notSupportedMessage設(shè)置的錯(cuò)誤。
	          src: this.mp4Url // 視頻url地址
	        }],
	        poster: this.mp4Pic, // 視頻封面地址
	        // width: document.documentElement.clientWidth,
          width: 1200,
	        height: this.fileAreaHeight,	// 設(shè)置高度,fluid需要設(shè)置成flase
	        notSupportedMessage: '此視頻暫無法播放...', // 允許覆蓋Video.js無法播放媒體源時(shí)顯示的默認(rèn)信息。
	        controlBar: {
	          timeDivider: true, // 當(dāng)前時(shí)間和持續(xù)時(shí)間的分隔符
	          durationDisplay: true,  // 顯示持續(xù)時(shí)間
	          remainingTimeDisplay: false,  // 是否顯示剩余時(shí)間功能
	          fullscreenToggle: true  //全屏按鈕
	        }
	      }
	      return playerOptionsObj
      }
    },
    watch: {
 
    }
  }
</script>
<style>
  .video /*可不設(shè)置*/
  {
    margin: 48px 0;
  }
  .vjs-poster {
    background-color: #aaaaaa00;
  }

/*播放按鈕設(shè)置成寬高一致,圓形,居中*/
.vjs-custom-skin > .video-js .vjs-big-play-button {
  outline: none;
  border: none;
  width: 66px;
  height: 66px !important;
  background-color: rgba(0,0,0,0) !important;
}

.video-js .vjs-big-play-button .vjs-icon-placeholder:before {
  content: '';
  width: 66px;
  height: 66px;
  background: url('../assets/icon_stop@2x.png') no-repeat;
  background-size: 100% 100%;
}


/*control-bar布局時(shí)flex,通過order調(diào)整剩余時(shí)間的位置到進(jìn)度條右邊*/
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-remaining-time{
  order:3 !important;
}

/* 進(jìn)度條下面的播放按鈕 */
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-play-control {
  margin: 0;
  line-height: 20px;
  height: 94px;
  padding: 50px 0 24px 0;
}
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-play-control .vjs-icon-placeholder:before {
  position: absolute;
  font-size: 20px;
  top: 44px;
  left: 24px;
  width: 20px;
  height: 20px;
}

/** 時(shí)間組件 */
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-time-control {
  margin: 0;
  line-height: 20px;
  height: 94px;
  padding: 50px 0 24px 0;
  min-width: auto;
}
/* 時(shí)間-左 */
.video-js .vjs-current-time, .vjs-no-flex .vjs-current-time {
  min-width: 32px;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FFFFFF;
  line-height: 20px;
  margin: 0 0 0 24px !important;
}
/* 下面控件的時(shí)間分割線 */
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-time-divider {
  min-width: 6px;
  margin: 0 8px !important;
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: rgba(255,255,255,0.2);
  line-height: 20px;
}
/* 時(shí)間-右 */
.video-js .vjs-duration, .vjs-no-flex .vjs-duration {
  font-size: 12px;
  font-family: PingFangSC-Regular, PingFang SC;
  font-weight: 400;
  color: #FFFFFF;
  line-height: 20px;
}
.video-js .vjs-control-bar {
  height: 94px;
  background: linear-gradient(180deg, rgba(0,0,0,0) 0%, rgba(0,0,0,0.7) 100%)
}
/*進(jìn)度條單獨(dú)放置一行*/
.vjs-custom-skin > .video-js .vjs-progress-control.vjs-control{
  position: absolute;
  left: 0;
  right: 0;
  bottom: 68px;
  width: 100%;
  height: 2px;
  padding: 0 24px;
}
/* 進(jìn)度條背景軌道 */
.video-js .vjs-slider{
  border-radius: 1em;
  background-color: rgba(255,255,255,0.2);
}
/* 加載進(jìn)度條背景色 */
.video-js .vjs-load-progress {
  background: rgba(255,255,255,0.1);
}
/* 進(jìn)度條進(jìn)度 */
.vjs-custom-skin > .video-js .vjs-play-progress, .vjs-custom-skin > .video-js .vjs-volume-level{
  border-radius: 1px;
  background: #FFFFFF;
}
 
/*鼠標(biāo)進(jìn)入播放器后,播放按鈕顏色會變*/
.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) !important;
}
 
/*control bar*/
.video-js .vjs-control-bar{
  background-color: rgba(0,0,0,0.2) !important;
}
 
/*點(diǎn)擊按鈕時(shí)不顯示藍(lán)色邊框*/
.video-js .vjs-control-bar button{
  outline: none;
}
.vjs-volume-panel .vjs-control .vjs-volume-panel-horizontal {
  width: 0;
  display: none;
}
/** 隱藏倍速 */
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-playback-rate {
  display: none;
}
/** 音量按鈕 */
.video-js .vjs-volume-panel {
  /* display: none; */
  position: absolute;
  right: 48px;
  bottom: 24px;
  width: 20px;
  height: 20px;
}
.vjs-icon-volume-high:before, .video-js .vjs-mute-control .vjs-icon-placeholder:before {
  font-size: 20px;
  width: 20px;
  height: 20px;
  line-height: 20px;
  color: rgba(255,255,255,0.9);
}
.video-js .vjs-volume-bar {
  margin: 8px 16px 8px 0;
}
.video-js .vjs-volume-level {
  left: -21px;
}
/* 全屏組件 */
.vjs-custom-skin > .video-js .vjs-control-bar .vjs-fullscreen-control {
  position: absolute;
  right: 24px;
  bottom: 24px;
  width: 20px;
  height: 20px;
}
.video-js .vjs-big-play-button .vjs-icon-placeholder:before, .vjs-button > .vjs-icon-placeholder:before {
  text-align: right;
}
/* 全屏按鈕圖標(biāo) */
.vjs-icon-fullscreen-enter:before, .video-js .vjs-fullscreen-control .vjs-icon-placeholder:before {
  content: '';
  width: 20px;
  height: 20px;
  background: url('../assets/icon_full@2x.png') no-repeat;
  background-size: 100% 100%;
}
/* 全屏播放后隱藏自定義全屏圖標(biāo) */
.vjs-icon-fullscreen-exit:before, .video-js.vjs-fullscreen .vjs-fullscreen-control .vjs-icon-placeholder:before {
  background: url('');
  line-height: 20px;
  margin-right: 10px;
}
</style>

樣式文件里的圖片及路徑,大家根據(jù)自己的實(shí)際情況進(jìn)行調(diào)整
vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件

3.4 完成效果圖!其實(shí)最重要的就是樣式調(diào)整這里。。。

4、設(shè)置自動播放

1、將muted屬性設(shè)置為true
2、調(diào)用視頻播放事件

// 設(shè)置自動播放事件中,將下面的代碼放進(jìn)去
this.$refs.videoPlayer.player.load()
this.$refs.videoPlayer.player.play()

5、設(shè)置一開始全屏播放視頻

在全屏播放事件中,將下面的代碼放進(jìn)去

this.$refs.videoPlayer.player.requestFullscreen()

6、監(jiān)聽視頻的全屏事件

視頻的全屏事件,在網(wǎng)上查了好久的資料,都沒有找到解決辦法,查chatGPT也是報(bào)錯(cuò),最后結(jié)合網(wǎng)上的例子,一個(gè)一個(gè)試出來,暫時(shí)沒發(fā)現(xiàn)有問題,可以獲取到視頻是否全屏狀態(tài)。文章來源地址http://www.zghlxwxcb.cn/news/detail-477809.html

<video-player 
   class="video-player vjs-custom-skin"
   ref="videoPlayer"
   :playsinline="true"
   :options="playerOptions"
   @loadeddata="onLoadedData"
 ></video-player>
methods: {
   /** 監(jiān)聽視頻 */
   onLoadedData(player) {
     player.on('fullscreenchange', () => {
       // player.isFullscreen_就是全屏的狀態(tài),true為全屏,false為不全屏
       // 在這里處理你的需求
     })
   },
 }

到了這里,關(guān)于vue 視頻播放插件vue-video-player自定義樣式、自動播放設(shè)置、設(shè)置一開始全屏播放視頻、監(jiān)聽全屏事件的文章就介紹完了。如果您還想了解更多內(nèi)容,請?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點(diǎn)僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實(shí)不符,請點(diǎn)擊違法舉報(bào)進(jìn)行投訴反饋,一經(jīng)查實(shí),立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費(fèi)用

相關(guān)文章

  • vue-video-player,springboot實(shí)現(xiàn)視頻分段下載播放

    vue-video-player,springboot實(shí)現(xiàn)視頻分段下載播放

    事情的起因是在博主把項(xiàng)目部署到服務(wù)器上后,發(fā)現(xiàn)由于視頻太大,加上服務(wù)器太垃圾,導(dǎo)致稍微大點(diǎn)的視頻加載很久才能播放(指十多分鐘…),然后就上網(wǎng)查找資料,看下咋實(shí)現(xiàn)。 這里涉及到有關(guān)http請求的知識“HTTP Header里的Range和Content-Range參數(shù),Range是在請求頭里 Ra

    2023年04月13日
    瀏覽(56)
  • vue2 組件vue-video-player播放視頻,支持hls格式

    參考教程:https://juejin.cn/post/6939898078526881823 官方:https://github.com/surmon-china/videojs-player 安裝指令 安裝指令要注意帶上版本號,如果沒有會默認(rèn)使用最新版,最新版僅支持vue3,因此會出問題。 HLSPlay.vue 自定義組件代碼 直接引用,如果組件配置了自動播放,則會自動播放。 更

    2024年02月11日
    瀏覽(16)
  • vue2 使用 vue-video-player 播放m3u8 流地址視頻

    安裝插件? : 注意需要引入??videojs-contrib-hls ,否則無法播放hls流文件? main.js 引入 代碼內(nèi)引入: 注意點(diǎn):??? 1.type: \\\'application/x-mpegURL\\\' ,否則無法播放流文件? 2.aspectRatio: \\\'16:9\\\',? 寬高比需要進(jìn)行設(shè)置, 若沒有進(jìn)行設(shè)置,會出現(xiàn)黑邊過高或者過寬的問題 常用API方法:

    2024年02月07日
    瀏覽(27)
  • vue 使用vue-video-player加載視頻(鋪滿容器)

    安裝 main.js 引入 使用 使視頻鋪滿容器

    2024年02月13日
    瀏覽(19)
  • vue使用vue-video-player實(shí)現(xiàn)web視頻直播展示m3u8格式

    vue使用vue-video-player實(shí)現(xiàn)web視頻直播展示m3u8格式

    最近有一個(gè)需求,就是web展示攝像頭的實(shí)時(shí)畫面,mentor讓我先探索探索,所以我先測試一些小demo。 這里邊個(gè)人想了一下啊,還是比較復(fù)雜的,包含推流和拉流等操作,還有延遲的問題要解決。 自己主要負(fù)責(zé)前端,所以先用vue-video-player播放了一下本地的視頻,熟悉一下功能,

    2023年04月22日
    瀏覽(25)
  • Vue3之使用vue-video-player

    Vue3之使用vue-video-player

    *vue-video-player 報(bào)錯(cuò)The media could not be loaded, either because the server or network failed or because the format is not supported * 原因: 我的src的路徑即視頻文件存放到本地了,路徑直接寫 src: \\\'videos/demo.mp4\\\' 而不用 \\\"/videos/demo.mp4\\\" 二、剛開始運(yùn)行安裝命令時(shí),在入口文件引入報(bào)錯(cuò),會顯示找不到文

    2024年01月18日
    瀏覽(31)
  • vue-video-player 在使用時(shí)視頻加載不出來,報(bào)錯(cuò)The media could not be loaded, either because the server ...

    vue-video-player 在使用時(shí)視頻加載不出來,報(bào)錯(cuò)The media could not be loaded, either because the server ...

    問題:在項(xiàng)目里安裝引入vue-video-player之后,在開發(fā)階段引入本地圖片,顯示X,同時(shí)報(bào)錯(cuò) The media could not be loaded, either because the server or network failed or because the format is not supported 解決:引入本地視頻資源時(shí)需要require引入, 配置引入使用的相關(guān)代碼:

    2024年02月11日
    瀏覽(30)
  • Unity視頻播放之Video Player的簡單使用

    Unity視頻播放之Video Player的簡單使用

    使用Unity自帶的VideoPlayer來播放視頻 一、準(zhǔn)備視頻 Unity3D常用視頻格式:.mov、.mpg、.mpeg、.mp4、.avi、.asf 如果都不識別,試試轉(zhuǎn)換成ogv格式。轉(zhuǎn)換完成之后,將視頻素材文件拖入U(xiǎn)nity Assets 文件夾內(nèi)。 二、創(chuàng)建UI及添加組件 創(chuàng)建RenderTexture資源,設(shè)置分辨率,跟視頻分辨率一致

    2024年01月18日
    瀏覽(41)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包