开发准备
vue-video-player和videojs-contrib-hls
npm i vue-video-player
npm i videojs-contrib-hls
引入
js
import { videoPlayer } from 'vue-video-player'
import 'videojs-contrib-hls'
使用
html
<videoPlayer
v-else
id="jsVideo"
ref="videoPlayer"
:playsinline="true"
:options="playerOptions">
</videoPlayer>
js
playerOptions: {
sources: [{
type: 'application/x-mpegURL',
src: 'https:xxxxx..m3u8' // 这里写自己的视频地址就可以
}],
autoplay: true,
loop: true,
poster: '',
controlBar: {
fullscreenToggle: false,
playToggle: false,
volumePanel: false,
},
},
video.js 播放器的默认结构如下所示:
Player
├── MediaLoader (has no DOM element)
├── PosterImage
├── TextTrackDisplay
├── LoadingSpinner
├── BigPlayButton
├── LiveTracker (has no DOM element)
├─┬ ControlBar
│ ├── PlayToggle
│ ├── VolumePanel
│ ├── CurrentTimeDisplay (hidden by default)
│ ├── TimeDivider (hidden by default)
│ ├── DurationDisplay (hidden by default)
│ ├─┬ ProgressControl (hidden during live playback, except when liveui: true)
│ │ └─┬ SeekBar
│ │ ├── LoadProgressBar
│ │ ├── MouseTimeDisplay
│ │ └── PlayProgressBar
│ ├── LiveDisplay (hidden during VOD playback)
│ ├── SeekToLive (hidden during VOD playback)
│ ├── RemainingTimeDisplay
│ ├── CustomControlSpacer (has no UI)
│ ├── PlaybackRateMenuButton (hidden, unless playback tech supports rate changes)
│ ├── ChaptersButton (hidden, unless there are relevant tracks)
│ ├── DescriptionsButton (hidden, unless there are relevant tracks)
│ ├── SubtitlesButton (hidden, unless there are relevant tracks)
│ ├── CaptionsButton (hidden, unless there are relevant tracks)
│ ├── SubsCapsButton (hidden, unless there are relevant tracks)
│ ├── AudioTrackButton (hidden, unless there are relevant tracks)
│ ├── PictureInPictureToggle
│ └── FullscreenToggle
├── ErrorDisplay (hidden, until there is an error)
├── TextTrackSettings
controlBar组件的说明
playToggle, // 播放暂停按钮
volumeMenuButton,// 音量控制
currentTimeDisplay,// 当前播放时间
timeDivider, // '/' 分隔符
durationDisplay, // 总时间
progressControl, // 点播流时,播放进度条,seek控制
liveDisplay, // 直播流时,显示LIVE
remainingTimeDisplay, // 当前播放时间
playbackRateMenuButton, // 播放速率,当前只有html5模式下才支持设置播放速率
fullscreenToggle // 全屏控制