亚洲乱码中文字幕综合,中国熟女仑乱hd,亚洲精品乱拍国产一区二区三区,一本大道卡一卡二卡三乱码全集资源,又粗又黄又硬又爽的免费视频

vue-video-player 斷點(diǎn)續(xù)播的實(shí)現(xiàn)

 更新時間:2021年02月01日 11:19:49   作者:liuxss123  
這篇文章主要介紹了vue-video-player 斷點(diǎn)續(xù)播的實(shí)現(xiàn),本文給大家介紹的非常詳細(xì),對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下

最近的項(xiàng)目中需要實(shí)現(xiàn)視頻斷點(diǎn)續(xù)播的功能,一聽到這個功能。內(nèi)心方張了..但卻又有點(diǎn)小竊喜,小懵亂。抱著求學(xué)態(tài)度去挑戰(zhàn)一下。

1.安裝插件

npm install vue-video-player --save

2.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.頁面使用組件

<el-tree :data="ChapterOptions"
     :props="defaultProps"
     node-key='id'
     highlight-current
     :filter-node-method="filterNode"
     ref="tree"
     default-expand-all
     @node-click="handleNodeClick" />
<video-player ref="videoPlayer"
        class="video-player vjs-custom-skin"
        style="width: 1000px;height: 576px;display: inline-flex"
        :playsinline="true"
        :options="playerOptions"
        @pause="onPlayerPause($event)"
        @ended="onPlayerEnded($event)"
        @play="onPlayerPlay($event)"
        @timeupdate="onPlayerTimeupdate($event)"
        @ready="playerReadied"
    />
<script>
import { videoPlayer } from 'vue-video-player'
import 'video.js/dist/video-js.css'
import 'vue-video-player/src/custom-theme.css'
import { treeselect } from "@/api//driver/videoChapter";
import Treeselect from "@riophae/vue-treeselect";
import "@riophae/vue-treeselect/dist/vue-treeselect.css";
export default {
 name: "videoPlayer",
 components: { Treeselect,videoPlayer },
 data() {
 return {
  //用戶信息
  user:{},
  //===============================
  paused: true,
  learningDuration: {
  userId: '', //用戶id
  chapterId:'',//章節(jié)id
  timeLog: '', //視頻觀看時長
  },
 
  playerOptions: {
  playbackRates: [0.5, 1.0, 1.5, 2.0], //播放速度
  autoplay: false, // 如果true,瀏覽器準(zhǔn)備好時開始回放。
  muted: false, // 默認(rèn)情況下將會消除任何音頻。
  loop: false, // 導(dǎo)致視頻一結(jié)束就重新開始。
  preload: 'auto', // 建議瀏覽器在<video>加載元素后是否應(yīng)該開始下載視頻數(shù)據(jù)。auto瀏覽器選擇最佳行為,立即開始加載視頻(如果瀏覽器支持)
  language: 'zh-CN',
  aspectRatio: '16:9', // 將播放器置于流暢模式,并在計(jì)算播放器的動態(tài)大小時使用該值。值應(yīng)該代表一個比例 - 用冒號分隔的兩個數(shù)字(例如"16:9"或"4:3")
  fluid: true, // 當(dāng)true時,Video.js player將擁有流體大小。換句話說,它將按比例縮放以適應(yīng)其容器。
  sources: [
   {
   type: 'video/mp4', // 這里的種類支持很多種:基本視頻格式、直播、流媒體等,具體可以參看git網(wǎng)址項(xiàng)目
   src: ''// url地址
   }
  ],
  hls: true,
  poster: '', // 你的封面地址
  width: document.documentElement.clientWidth, // 播放器寬度
  notSupportedMessage: '此視頻暫無法播放,請稍后再試', // 允許覆蓋Video.js無法播放媒體源時顯示的默認(rèn)信息。
  controlBar: {
   //當(dāng)前時間和持續(xù)時間的分隔符
   timeDivider: true,
   //顯示持續(xù)時間
   durationDisplay: true,
   //是否顯示剩余時間功能
   remainingTimeDisplay: false,
   //全屏按鈕
   fullscreenToggle: true
  }
  }
 };
},
computed: {
 player() {
  return this.$refs.videoPlayer.player//自定義播放
 }
 },
mounted () {
 this.timer = setInterval(this.putLearningObj, 3000)
 },
destroyed () {
 // 如果定時器在運(yùn)行則關(guān)閉
 if (this.timer) {
  clearInterval(this.timer)
  }
 },
methods: {
 //用戶信息
 getUser() {
  getUserProfile().then(response => {
  this.user = response.data;
  this.learningDuration.userId = this.user.userId
  });
 },
  //============================
 fullScreen() {
  const player = this.$refs.videoPlayer.player
  player.requestFullscreen()//調(diào)用全屏api方法
  player.isFullscreen(true)
  player.play()
 },
 onPlayerPlay(player) {
  this.paused = false
  // player.play()
 },
 onPlayerPause (player) {
  this.paused = true
  // console.log('onPlayerPause!', player)
 },
 onPlayerEnded (player) {
  this.paused = false;
  // clearInterval(this.timer);
 },
 //當(dāng)前播放位置發(fā)生變化時觸發(fā)。
 onPlayerTimeupdate (player) {
  // console.log(' onPlayerTimeupdate!', this.timeLog)
 },
 /* 設(shè)置視頻進(jìn)度 */
 playerReadied: function (player) {
 },
};
</script>

上面的 src視頻地址可以換成具體的地址串,也能換成后臺的地址串,因?yàn)槲业氖钦鹿?jié)樹所以我和章節(jié)id進(jìn)行了關(guān)聯(lián)

 /** 查詢部門下拉樹結(jié)構(gòu) */
 getTreeselect() {
  treeselect().then((response) => {
  //封面
  var img = '';
  this.ChapterOptions = response.data;
  for (let i = 0; i <this.ChapterOptions.length ; i++) {
   this.videoName = this.ChapterOptions[0].children[0].chapterName
   this.videoIntroduce = this.ChapterOptions[0].children[0].chapterIntroduce
   this.VideoUrl = JSON.parse(this.ChapterOptions[0].children[0].videoAddress)
   img = JSON.parse(this.ChapterOptions[0].children[0].imageAddress)
   //初始化封面
   for (let j = 0; j <img.length ; j++) {
   this.playerOptions.poster =img[0];
   }
   //初始化第一個章節(jié)視頻
   for (let j = 0; j <this.VideoUrl.length ; j++) {
   this.playerOptions.sources[0].src = this.VideoUrl[0]
   }
   //初始化章節(jié)
   this.learningDuration.chapterId = this.ChapterOptions[0].children[0].id;
   //默認(rèn)高亮第一個章節(jié)節(jié)點(diǎn)
   this.$nextTick(()=>{
   this.$refs.tree.setCurrentKey(this.ChapterOptions[0].children[0].id);
   })
  }
  });
 },
 // 篩選節(jié)點(diǎn)
 filterNode(value, data) {
  if (!value) return true;
  return data.label.indexOf(value) !== -1;
 },
 // 節(jié)點(diǎn)單擊事件
 handleNodeClick(data) {
  // console.log(data)
  var img = '';
  //刷新原視頻, 原封面
  this.playerOptions.sources[0].src = '';
  this.playerOptions.poster = '';
  //轉(zhuǎn)換視頻
  this.VideoUrl= JSON.parse(data.videoAddress);
  // console.log("this.VideoUrl")
  for (let i = 0; i <this.VideoUrl.length ; i++) {
  this.playerOptions.sources[0].src = this.VideoUrl[0];
  }
  img = JSON.parse(data.imageAddress);
  for (let i = 0; i <img.length ; i++) {
  this.playerOptions.poster = img[0];
  }
  // console.log("this.playerOptions.sources[0].src")
  // console.log(this.playerOptions.sources[0].src)
  //章節(jié)介紹
  this.videoIntroduce = data.chapterIntroduce;
  //章節(jié)名稱
  this.videoName = data.chapterName;
  //章節(jié)id
  this.learningDuration.chapterId = data.id
  // console.log(this.videoIntroduce)
 },

4.進(jìn)度保存

接下來就是 保存視頻的進(jìn)度條了,通過打印發(fā)現(xiàn)onPlayerTimeupdate可獲取到視頻的進(jìn)度,故采用定時器 每3秒觸發(fā)一次數(shù)據(jù)交互

computed: {
 player() {
  return this.$refs.videoPlayer.player//自定義播放
 }
 },
 mounted () {
 this.timer = setInterval(this.putLearningObj, 3000)
 },
 destroyed () {
 // 如果定時器在運(yùn)行則關(guān)閉
 if (this.timer) {
  clearInterval(this.timer)
  }
 },
methods: {  
putLearningObj () {
  if (!this.paused) {
  //保存視頻進(jìn)度
  saveTime(this.learningDuration)
  console.log('putLearningObj ~~~~~~~~~')
  }
 },
//當(dāng)前播放位置發(fā)生變化時觸發(fā)。
onPlayerTimeupdate (player) {
 this.learningDuration.timeLog = player.cache_.currentTime
  // console.log(' onPlayerTimeupdate!', this.timeLog)
 },
},

saveTime是我自定義的與后端交互的方法。(可自行定義)

// 保存視頻進(jìn)度
export function saveTime(data) {
 return request({
 url: '/***/****/***/',
 method: 'put',
 data: data
 })
}

那么到了這一步 進(jìn)度就能保存下來了

4.進(jìn)度恢復(fù)

想要恢復(fù)進(jìn)度,就必須在視頻播放前把 保存進(jìn)度下來的設(shè)置到視頻當(dāng)中,通過打印可以看出playerReadied 可以設(shè)置

/* 設(shè)置視頻進(jìn)度 */
playerReadied: function (player) {
//可在此調(diào)用后臺交互方法
...
player.currentTime(this.learningDuration.timeLog)
},

到此 進(jìn)度可以 恢復(fù)了 大功告成!。至于后臺交互數(shù)據(jù) 需求不一樣,代碼也就沒有貼出來。

到此這篇關(guān)于vue-video-player 斷點(diǎn)續(xù)播的文章就介紹到這了,更多相關(guān)vue video player 斷點(diǎn)續(xù)播內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關(guān)文章希望大家以后多多支持腳本之家!

相關(guān)文章

  • vue Watch和Computed的使用總結(jié)

    vue Watch和Computed的使用總結(jié)

    本文主要介紹Vue.js中監(jiān)聽器和計(jì)算屬性的相關(guān)知識點(diǎn),包括對普通屬性的監(jiān)聽、對對象的監(jiān)聽、對數(shù)組的監(jiān)聽,以及計(jì)算屬性的Set方法,計(jì)算屬性與監(jiān)聽器的區(qū)別等等
    2021-05-05
  • ElementUI多個子組件表單的校驗(yàn)管理實(shí)現(xiàn)

    ElementUI多個子組件表單的校驗(yàn)管理實(shí)現(xiàn)

    這篇文章主要介紹了ElementUI多個子組件表單實(shí)現(xiàn)方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-11-11
  • Vue.js2.0中的變化小結(jié)

    Vue.js2.0中的變化小結(jié)

    最近小編在學(xué)習(xí)vue.js ,發(fā)現(xiàn)里面有好多好玩的東東,今天小編給大家分享Vue.js2.0中的變化,小編會在日后給大家持續(xù)更新的,感興趣的朋友參考下吧
    2017-10-10
  • Vue 3開發(fā)中VueUse強(qiáng)大Hooks庫

    Vue 3開發(fā)中VueUse強(qiáng)大Hooks庫

    VueUse提供了一個豐富且強(qiáng)大的Hooks庫,可以幫助開發(fā)者快速實(shí)現(xiàn)各種功能,提高開發(fā)效率,本文來詳細(xì)的介紹一下,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2024-08-08
  • Vue的MVVM實(shí)現(xiàn)方法

    Vue的MVVM實(shí)現(xiàn)方法

    本篇文章主要主要介紹了Vue的MVVM實(shí)現(xiàn)方法,小編覺得挺不錯的,現(xiàn)在分享給大家,也給大家做個參考。一起跟隨小編過來看看吧
    2017-08-08
  • Vue實(shí)現(xiàn)手機(jī)橫屏效果的代碼示例

    Vue實(shí)現(xiàn)手機(jī)橫屏效果的代碼示例

    有時候一些頁面希望在手機(jī)上可以實(shí)現(xiàn)橫屏的效果,比如播放頁面,所以本文我們講給大家介紹Vue如何實(shí)現(xiàn)手機(jī)橫屏效果,文章通過代碼示例介紹的非常詳細(xì),感興趣的同學(xué)跟著小編一起來看看吧
    2023-08-08
  • Vue中使用Lodop插件實(shí)現(xiàn)打印功能的簡單方法

    Vue中使用Lodop插件實(shí)現(xiàn)打印功能的簡單方法

    這篇文章主要給大家介紹了關(guān)于Vue中使用Lodop插件實(shí)現(xiàn)打印功能的簡單方法,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用Vue具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-12-12
  • vue.js開發(fā)環(huán)境安裝教程

    vue.js開發(fā)環(huán)境安裝教程

    這篇文章主要為大家詳細(xì)介紹了vue.js開發(fā)環(huán)境的安裝教程,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Delete `,` 如何解決(vue eslint與prettier沖突)

    Delete `,` 如何解決(vue eslint與prettier沖突)

    這篇文章主要介紹了Delete `,` 如何解決(vue eslint與prettier沖突)問題,具有很好的參考價(jià)值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教
    2023-10-10
  • react里組件通信的幾種方式小結(jié)

    react里組件通信的幾種方式小結(jié)

    本文主要介紹了react里組件通信的幾種方式小結(jié),包含了5種方式,主要是props傳遞,回調(diào)函數(shù)作為props,Context,Redux或MobX,refs,具有一定的參考價(jià)值,感興趣的可以了解一下
    2024-06-06

最新評論