Vue-视频加载(vue-video-player)支持.mp4.m3u8.flv.mov格式
1、安装vue-video-playerimport Vue from 'vue'import VideoPlayer from 'vue-video-player'require('vue-video-palyer/node-modules/video.js/dist/video-js.css')
·
github官方地址:https://github.com/surmon-china/vue-video-player.git
1、安装vue-video-player
1)、CDN引入
<link rel="stylesheet" href="path/to/video.js/dist/video-js.css"/>
<script type="text/javascript" src="path/to/video.min.js"></script>
<script type="text/javascript" src="path/to/vue.min.js"></script>
<script type="text/javascript" src="path/to/dist/vue-video-player.js"></script>
<script type="text/javascript">
Vue.use(window.VueVideoPlayer)
</script>
2)、npm
npm install vue-video-player --save
2、引入
1)、main.js引入
import Vue from 'vue'
import VueVideoPlayer from 'vue-video-player'
import 'video.js/dist/video-js.css'
Vue.use(VueVideoPlayer)
2)、局部引入
import 'video.js/dist/video-js.css'
import { videoPlayer } from 'vue-video-player'
export default {
components: {
videoPlayer
}
}
3、m3u8视频配置
<template>
<video-player class="vjs-custom-skin"
:options="playerOptions"
@ready="playerReadied">
</video-player>
</template>
<script>
// custom skin css
import '../src/custom-theme.css'
// videojs
import videojs from 'video.js'
window.videojs = videojs
// hls plugin for videojs6
require('videojs-contrib-hls/dist/videojs-contrib-hls.js')
// export
export default {
data() {
return {
playerOptions: {
// videojs and plugin options
height: '360',
sources: [{
withCredentials: false,
type: "application/x-mpegURL",
src: "https://logos-channel.scaleengine.net/logos-channel/live/biblescreen-ad-free/playlist.m3u8"
}],
controlBar: {
timeDivider: false,
durationDisplay: false
},
flash: { hls: { withCredentials: false }},
html5: { hls: { withCredentials: false }},
poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-5.jpg"
}
}
},
methods: {
playerReadied(player) {
var hls = player.tech({ IWillNotUseThisInPlugins: true }).hls
player.tech_.hls.xhr.beforeRequest = function(options) {
// console.log(options)
return options
}
}
}
}
</script>
4、mp4视频配置
<template>
<!--mp4-->
<video-player class="vjs-custom-skin"
ref="videoPlayer"
:options="playerOptions"
:playsinline="true"
@play="onPlayerPlay($event)"
@pause="onPlayerPause($event)"
@ended="onPlayerEnded($event)"
@loadeddata="onPlayerLoadeddata($event)"
@waiting="onPlayerWaiting($event)"
@playing="onPlayerPlaying($event)"
@timeupdate="onPlayerTimeupdate($event)"
@canplay="onPlayerCanplay($event)"
@canplaythrough="onPlayerCanplaythrough($event)"
@ready="playerReadied"
@statechanged="playerStateChanged($event)">
</video-player>
</template>
<script>
// custom skin css
import '../src/custom-theme.css'
export default {
data() {
return {
// videojs options
playerOptions: {
height: '360',
autoplay: true,
muted: true,
language: 'en',
playbackRates: [0.7, 1.0, 1.5, 2.0],
sources: [{
type: "video/mp4",
// mp4
src: "http://vjs.zencdn.net/v/oceans.mp4",
// webm
// src: "https://cdn.theguardian.tv/webM/2015/07/20/150716YesMen_synd_768k_vp8.webm"
}],
poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-1.jpg",
}
}
},
mounted() {
setTimeout(() => {
console.log('dynamic change options', this.player)
this.player.muted(false)
}, 5000)
},
computed: {
player() {
return this.$refs.videoPlayer.player
}
},
methods: {
// listen event
onPlayerPlay(player) {
// console.log('player play!', player)
},
onPlayerPause(player) {
// console.log('player pause!', player)
},
onPlayerEnded(player) {
// console.log('player ended!', player)
},
onPlayerLoadeddata(player) {
// console.log('player Loadeddata!', player)
},
onPlayerWaiting(player) {
// console.log('player Waiting!', player)
},
onPlayerPlaying(player) {
// console.log('player Playing!', player)
},
onPlayerTimeupdate(player) {
// console.log('player Timeupdate!', player.currentTime())
},
onPlayerCanplay(player) {
// console.log('player Canplay!', player)
},
onPlayerCanplaythrough(player) {
// console.log('player Canplaythrough!', player)
},
// or listen state event
playerStateChanged(playerCurrentState) {
// console.log('player current update state', playerCurrentState)
},
// player is ready
playerReadied(player) {
// seek to 10s
console.log('example player 1 readied', player)
player.currentTime(10)
// console.log('example 01: the player is readied', player)
}
}
}
</script>
5、flv视频配置
<template>
<!--Custom event name & hotkeys plugin & flash plugin / Flash插件 & 自定义事件名称 & 热键插件-->
<video-player class="vjs-custom-skin"
ref="videoPlayer"
:options="playerOptions"
customEventName="changed"
@ready="playerIsReady"
@changed="playerStateChanged($event)">
</video-player>
</template>
<script>
// custom skin css
import '../src/custom-theme.css'
// videojs hotkeys plugin
import 'videojs-flash'
import 'videojs-hotkeys'
// export
export default {
data() {
return {
playerOptions: {
height: '360',
autoplay: false,
sources: [{
// mp4
// type: 'video/mp4',
// src: 'http://vjs.zencdn.net/v/oceans.mp4',
// flv
type: 'video/x-flv',
src: 'http://fms.cntv.lxdns.com/live/flv/channel96.flv'
}],
language: 'zh-CN',
techOrder: ['flash'],
poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-6.jpg"
}
}
},
computed: {
player() {
return this.$refs.videoPlayer.player
}
},
methods: {
playerStateChanged(playerCurrentState) {
console.log('example 2: state changed', playerCurrentState)
},
playerIsReady(player) {
console.log('example 2 ready!', player)
player.hotkeys({
volumeStep: 0.1,
seekStep: 5,
enableModifiersForNumbers: false,
fullscreenKey: function(event, player) {
// override fullscreen to trigger when pressing the F key or Ctrl+Enter
return ((event.which === 70) || (event.ctrlKey && event.which === 13));
}
})
}
}
}
</script>
6、音轨 及 移动端不全屏
<template>
<!--AudioTrack && playsinline / 音轨 及 移动端不全屏-->
<video-player class="vjs-custom-skin"
:options="playerOptions"
:playsinline="true"
@ready="playerReadied($event)"></video-player>
</template>
<script>
// videojs
import videojs from 'video.js'
// export
export default {
data() {
return {
playerOptions: {
height: '360',
playbackRates: [0.7, 1, 1.3, 1.5, 1.7],
sources: [{
type: "video/mp4",
src: "http://7xkwa7.media1.z0.glb.clouddn.com/sample_video_L"
}],
poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-3.jpg",
}
}
},
methods: {
playerReadied(player) {
const track = new videojs.AudioTrack({
id: 'my-spanish-audio-track',
kind: 'translation',
label: 'Spanish',
language: 'es'
})
player.audioTracks().addTrack(track)
// Get the current player's AudioTrackList object.
const audioTrackList = player.audioTracks()
// Listen to the "change" event.
audioTrackList.addEventListener('change', function() {
// Log the currently enabled AudioTrack label.
for (let i = 0; i < audioTrackList.length; i++) {
const track = audioTrackList[i]
if (track.enabled) {
videojs.log(track.label)
return
}
}
})
}
}
}
</script>
7、.mov流媒体配置
<template>
<div>
<!--rtmp flash / 流媒体-->
<video-player class="vjs-custom-skin" :options="playerOptions"></video-player>
</div>
</template>
<script>
import 'videojs-flash'
export default {
data() {
return {
playerOptions: {
height: '360',
sources: [{
type: "rtmp/mp4",
src: "rtmp://184.72.239.149/vod/&mp4:BigBuckBunny_115k.mov"
}],
techOrder: ['flash'],
autoplay: false,
controls: true,
poster: "https://surmon-china.github.io/vue-quill-editor/static/images/surmon-9.jpg"
}
}
}
}
</script>
更多推荐
已为社区贡献2条内容
所有评论(0)