vue使用video插件vue-video-player詳解
本文實(shí)例為大家分享了vue使用video插件vue-video-player的具體代碼,供大家參考,具體內(nèi)容如下
進(jìn)入我們的項(xiàng)目文件夾中,并打開(kāi)命令行窗口,然后進(jìn)行下面的步驟:
1、安裝vue-video-player
輸入命令:
npm install vue-video-player -S
2、引入插件
在項(xiàng)目的入口文件main.js中引入插件,如下:
import VideoPlayer from ’vue-video-player’require(’video.js/dist/video-js.css’)require(’vue-video-player/src/custom-theme.css’)Vue.use(VideoPlayer)
3、使用插件
創(chuàng)建vue組件文件VideoPlayer.vue,文件內(nèi)容如下:
<template> <div> <!-- 使用組件 --> <video-player ref='videoPlayer' :playsinline='true' :options='playerOptions' ></video-player> </div></template><script>// 導(dǎo)入組件import {videoPlayer} from ’vue-video-player’import ’videojs-flash’export default { name: ’VideoPlayer’, components: { videoPlayer }, data () { return { fileAreaHeight: 100, fileType: ’mp4’, // 資源的類(lèi)型 fileUrl: ’xxx’ // 資源的路徑地址 } }, computed: { playerOptions () { // 使用計(jì)算屬性 const playerOptionsObj = { techOrder: [’flash’], // 使用flase播放,可以播放flv格式的文件 playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度 autoplay: false, // 如果true,瀏覽器準(zhǔn)備好時(shí)開(kāi)始回放。 muted: false, // 默認(rèn)情況下將會(huì)消除任何音頻。 loop: false, // 導(dǎo)致視頻一結(jié)束就重新開(kāi)始。 // preload: ’auto’, // 建議瀏覽器在<video>加載元素后是否應(yīng)該開(kāi)始下載視頻數(shù)據(jù)。auto瀏覽器選擇最佳行為,立即開(kāi)始加載視頻(如果瀏覽器支持) language: ’zh-CN’, // aspectRatio: ’16:9’, // 將播放器置于流暢模式,并在計(jì)算播放器的動(dòng)態(tài)大小時(shí)使用該值。值應(yīng)該代表一個(gè)比例 - 用冒號(hào)分隔的兩個(gè)數(shù)字(例如'16:9'或'4:3') fluid: false, // 當(dāng)true時(shí),Video.js player將擁有流體大小。換句話說(shuō),它將按比例縮放以適應(yīng)其容器。 sources: [{ type: ’video/’ + this.fileType, // 資源格式寫(xiě)法:’video/mp4’,否則控制臺(tái)會(huì)出現(xiàn)notSupportedMessage設(shè)置的錯(cuò)誤 src: this.fileUrl // url地址 }], poster: ’’, // 你的封面地址 // width: document.documentElement.clientWidth, height: this.fileAreaHeight, // 設(shè)置高度,fluid需要設(shè)置成flase notSupportedMessage: ’此視頻暫無(wú)法播放...’, // 允許覆蓋Video.js無(wú)法播放媒體源時(shí)顯示的默認(rèn)信息。 controlBar: { timeDivider: true, durationDisplay: true, remainingTimeDisplay: false, fullscreenToggle: true //全屏按鈕 } } return playerOptionsObj } }}</script><style scoped>.video-js .vjs-big-play-button{ /*對(duì)播放按鈕的樣式進(jìn)行設(shè)置*/ }</style>
注:
如果在VideoPlayer.vue中不導(dǎo)入組件,則會(huì)報(bào)如下錯(cuò)誤:
關(guān)于vue.js組件的教程,請(qǐng)大家點(diǎn)擊專(zhuān)題vue.js組件學(xué)習(xí)教程進(jìn)行學(xué)習(xí)。
更多vue學(xué)習(xí)教程請(qǐng)閱讀專(zhuān)題《vue實(shí)戰(zhàn)教程》
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
1. React+umi+typeScript創(chuàng)建項(xiàng)目的過(guò)程2. ASP中常用的22個(gè)FSO文件操作函數(shù)整理3. ASP編碼必備的8條原則4. ASP調(diào)用WebService轉(zhuǎn)化成JSON數(shù)據(jù),附j(luò)son.min.asp5. 三個(gè)不常見(jiàn)的 HTML5 實(shí)用新特性簡(jiǎn)介6. Warning: require(): open_basedir restriction in effect,目錄配置open_basedir報(bào)錯(cuò)問(wèn)題分析7. SharePoint Server 2019新特性介紹8. 無(wú)線標(biāo)記語(yǔ)言(WML)基礎(chǔ)之WMLScript 基礎(chǔ)第1/2頁(yè)9. ASP.NET Core 5.0中的Host.CreateDefaultBuilder執(zhí)行過(guò)程解析10. php測(cè)試程序運(yùn)行速度和頁(yè)面執(zhí)行速度的代碼
