視頻播放器
vue視頻播放器插件vue-dplayer,支持m3u8格式,mp4格式.
1.npm -- 在vue 根目錄安裝
npm install vue-video-player --save
npm install videojs-contrib-hls --save
在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)
const hls = require('videojs-contrib-hls')
Vue.use(hls)
3.html代碼 --在需要引入的目錄引入
<div class="player-dv">
<video-player class="video-player vjs-custom-skin"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions"
></video-player>
</div>
4.js 這個要放在變數里面
playerOptions: {
// playbackRates: [0.7, 1.0, 1.5, 2.0], //播放速度 :class="[currentIndex==index?'current':'']"
autoplay: true, // 如果true,瀏覽器準備好時開始回放。
muted: false, // 默認情況下將會消除任何音頻。
loop: true, // 導致視頻一結束就重新開始。
preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應該開始下載視頻資料。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)
language: 'zh-CN',
aspectRatio: '16:9', // 將播放器置于流暢模式,并在計算播放器的動態大小時使用該值。值應該代表一個比例 - 用冒號分隔的兩個數字(例如"16:9"或"4:3")
fluid: true, // 當true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應其容器。
sources: [
{
type: 'application/x-mpegURL', // 型別
src:
'https://cdn.letv-cdn.com/2018/12/05/JOCeEEUuoteFrjCg/playlist.m3u8' // 路徑
},
{
src: '', // 路徑
type: 'video/mp4' // 型別
},
{
type: 'video/mp4', // 這里的種類支持很多種:基本視頻格式、直播、流媒體等,具體可以參看git網址專案
src: 'https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm' // url地址
}
],
hls: true,
poster: '', // 你的封面地址
width: document.documentElement.clientWidth, // 播放器寬度
notSupportedMessage: '此視頻暫無法播放,請稍后再試', // 允許覆寫Video.js無法播放媒體源時顯示的默認資訊。
controlBar: {
timeDivider: true,
durationDisplay: true,
remainingTimeDisplay: false,
fullscreenToggle: true // 全屏按鈕
}
},
轉載請註明出處,本文鏈接:https://www.uj5u.com/qianduan/127431.html
標籤:JavaScript
上一篇:富文本編輯器
下一篇:2020-09-24
