用了?video.js?
import?videojs?from?'video.js'
import?'video.js/dist/video-js.css'
?data?()?{
????return?{
? ? ? ? player:?null,
??????watchMaxTime:?0
????}
??},
?getInitVideo?()?{
??????this.$nextTick(()?=>?{
????????const?_this?=?this
????????this.player?=?videojs(this.$refs.videoPlayer,?{
??????????//?預(yù)加載
??????????//?自動播放?默認(rèn)值false
??????????//?autoplay?:?false,
??????????//?控制欄
??????????controls:?true,
??????????language:?'zh-CN',?//?設(shè)置語言
??????????muted:?false,?//?是否靜音
??????????height:?'100%',
??????????width:?'100%',
??????????preload:?'auto'
????????},?function?onPlayerReady?()?{
??????????//?這里綁定事件
??????????const?myPlayer?=?this
??????????//?綁定?播放時間改變事件
??????????myPlayer.on('play',?function?()?{
? ? ? ? ? ?console.log('播放')
??????????})
??????????myPlayer.on('pause',?function?()?{
????????????console.log('暫停')
? ? ? ? ? ?})
??????????myPlayer.on('ended',?function?()?{
? ?????????????? ??console.log('結(jié)束')
? ? ? ? ?})
??????????myPlayer.on('loadedmetadata',?()?=>?{
????????????const?val?=?_this.currentitem.play_status?!==?1???_this.currentitem.process?:?0 //?設(shè)置之前的播放進(jìn)度
? ? ? ? ? ?myPlayer.play()
????????????myPlayer.currentTime(val)
??????????})
??????????myPlayer.on('timeupdate',?function?()?{
????????????const?time?=?myPlayer.currentTime()
????????????if?(time?>?_this.watchMaxTime)?{
??????????????_this.watchMaxTime?=?_this.currentitem.process?>?time???_this.currentitem.process?:?time? //? 設(shè)置最大可播放時間
????????????}?else?{
??????????????_this.watchMaxTime?=?_this.currentitem.process?? ?//? 設(shè)置最大可播放時間為之前已經(jīng)播放到的進(jìn)度
????????????}
??????????})
????????})
????????videojs.use('*',?function?(player)?{
??????????return?{
????????????setCurrentTime:?function?(time)?{
??????????????const?{?play_status?}?=?_this.currentitem
??????????????//?快進(jìn)??值比最大觀看點的大??則跳轉(zhuǎn)至最大觀看點
??????????????let?val?=?time
??????????????if?(time?>?_this.watchMaxTime?&&?play_status?!==?1)?{
????????????????val?=?_this.watchMaxTime
??????????????}
??????????????return?val
????????????}
??????????}
????????})
??????})
????},