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

詳解vue3中如何使用shaka-player

 更新時間:2022年09月21日 09:09:10   作者:簡單卟容易  
這篇文章主要為大家介紹了vue3中如何使用shaka-player示例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪

正文

Shaka Player 是谷歌公司對外開源的一款 JavaScript 類庫,詳細(xì)請看谷歌官方API文檔。

開始使用

我們可以使用 npm 下載

npm i shaka-player

做成組件shakaPlayer

<script setup>
import { ref, watch, onMounted, onBeforeUnmount } from "vue";
import shaka from "shaka-player/dist/shaka-player.ui.js";
import "../../node_modules/shaka-player/dist/controls.css"; // 注意路徑
const props = defineProps({
  src: { type: String, required: true },
  poster: { type: String, default: "" },
  autoplay: { type: Boolean, default: false }
});
onMounted(() => {
  initApp();
});
onBeforeUnmount(() => {
  player && player.destroy();
});
const initApp = () => {
  if (shaka.Player.isBrowserSupported()) {
    initPlayer();
  } else {
    console.error("Browser not supported!");
  }
};
const videoPlayer = ref();
const videoContainer = ref();
let player = null;
const initPlayer = () => {
  player = new shaka.Player(videoPlayer.value);
  const ui = new shaka.ui.Overlay(
    player,
    videoContainer.value,
    videoPlayer.value
  );
  ui.configure({
    // 自定義控件
    controlPanelElements: [
      "time_and_duration", // 進(jìn)度
      "spacer",
      "mute", // 靜音
      "volume", // 音量
      "fullscreen", // 全屏
      "overflow_menu"
    ],
    overflowMenuButtons: [
      "picture_in_picture", // 畫中畫
      "playback_rate" // 倍速
    ],
    playbackRates: [0.5, 1, 1.5, 2], // 倍速選項
    // 視頻進(jìn)入全屏?xí)r設(shè)備是否應(yīng)旋轉(zhuǎn)到橫向模式
    forceLandscapeOnFullscreen: false
  });
  loadPlayer();
};
const loadPlayer = async () => {
  try {
    await player.load(props.src);
  } catch (e) {
    onError(e);
  }
};
const onError = (error) => {
  console.error("Error code", error.code, "object", error);
};
const play = () => videoPlayer.value && videoPlayer.value.play();
const pause = () => videoPlayer.value && videoPlayer.value.pause();
watch(
  () => props.src,
  () => initPlayer()
);
defineExpose({ play, pause });
</script>
<template>
  <div ref="videoContainer" class="max-w-full">
    <video
      ref="videoPlayer"
      class="full"
      :poster="poster"
      :autoplay="autoplay"
      muted
    ></video>
  </div>
</template>
<style scoped>
.max-w-full {
  max-width: 100%;
}
.full {
  width: 100%;
  height: 100%;
}
</style>

使用方式

<shaka-player
  class="video"
  :src="src"
  :poster="poster"
  autoplay
></shaka-player>
.video {
  width: 100%;
  height: 200px;
}

注意事項

默認(rèn)視頻控件是顯示所有的,允許我們自定義。

我們可以直接使用 video 原生方法、事件和屬性。

寬高可以用class樣式設(shè)置。

Shaka Player不支持Vue響應(yīng)對象,player 不能用 ref 來聲明。

移動端視頻默認(rèn)靜音時,autoplay 才會生效。

以上就是詳解vue3中如何使用shaka-player的詳細(xì)內(nèi)容,更多關(guān)于vue3使用shaka-player的資料請關(guān)注腳本之家其它相關(guān)文章!

相關(guān)文章

  • VUE路由動態(tài)加載實例代碼講解

    VUE路由動態(tài)加載實例代碼講解

    在本文里小編給大家整理了關(guān)于VUE路由動態(tài)加載實例代碼以及相關(guān)知識點,需要的朋友們學(xué)習(xí)下。
    2019-08-08
  • vue下canvas裁剪圖片實例講解

    vue下canvas裁剪圖片實例講解

    在本篇文章里小編給大家整理了關(guān)于vue下canvas裁剪圖片實例講解內(nèi)容,需要的朋友們可以參考下。
    2020-04-04
  • vue多頁面項目開發(fā)實戰(zhàn)指南

    vue多頁面項目開發(fā)實戰(zhàn)指南

    一般我們的vue項目都是單頁面的,其實因為vue在工程化開發(fā)的時候依賴了webpack,webpack幫我們將所有的資源整合到一起而形成一個單頁面,下面這篇文章主要給大家介紹了關(guān)于vue多頁面項目開發(fā)的相關(guān)資料,需要的朋友可以參考下
    2022-01-01
  • 解決Vue-cli npm run build生產(chǎn)環(huán)境打包,本地不能打開的問題

    解決Vue-cli npm run build生產(chǎn)環(huán)境打包,本地不能打開的問題

    今天小編就為大家分享一篇解決Vue-cli npm run build生產(chǎn)環(huán)境打包,本地不能打開的問題,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2018-09-09
  • vue-cli3跨域配置的簡單方法

    vue-cli3跨域配置的簡單方法

    這篇文章主要給大家介紹了關(guān)于vue-cli3跨域配置的簡單方法,文中通過示例代碼介紹的非常詳細(xì),對大家學(xué)習(xí)或者使用vue-cli3具有一定的參考學(xué)習(xí)價值,需要的朋友們下面來一起學(xué)習(xí)學(xué)習(xí)吧
    2019-09-09
  • Vue封裝一個Tabbar組件?帶組件路由跳轉(zhuǎn)方式

    Vue封裝一個Tabbar組件?帶組件路由跳轉(zhuǎn)方式

    這篇文章主要介紹了Vue封裝一個Tabbar組件?帶組件路由跳轉(zhuǎn)方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-04-04
  • vue3 template轉(zhuǎn)為render函數(shù)過程詳解

    vue3 template轉(zhuǎn)為render函數(shù)過程詳解

    在 Vue 中,template 模板是我們編寫組件的主要方式之一,而 Vue 內(nèi)部會將這些模板轉(zhuǎn)換為 render 函數(shù),render 函數(shù)是用于創(chuàng)建虛擬 DOM 的函數(shù),通過它,Vue 能夠高效地追蹤 DOM 的變化并進(jìn)行更新,下面我會通俗易懂地詳細(xì)解釋 Vue 如何將 template 轉(zhuǎn)換為 render 函數(shù)
    2024-10-10
  • Vue實現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式

    Vue實現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式

    這篇文章主要介紹了Vue實現(xiàn)戶籍管理系統(tǒng)戶籍信息的添加與刪除方式,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教
    2022-09-09
  • vue :src 文件路徑錯誤問題的解決方法

    vue :src 文件路徑錯誤問題的解決方法

    這篇文章主要介紹了vue :src 文件路徑錯誤問題的簡單解決方法,本文分步驟給大家介紹的非常詳細(xì),感興趣的朋友跟隨腳本之家小編一起學(xué)習(xí)吧
    2018-05-05
  • vue如何批量引入組件、注冊和使用詳解

    vue如何批量引入組件、注冊和使用詳解

    這篇文章主要給大家介紹了關(guān)于vue如何批量引入組件、注冊和使用的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧
    2021-05-05

最新評論