VedioJS 10

  • 手机端横屏
  • 中文菜单

依赖

复制代码
yarn add @videojs/html@10.0.1 @videojs/hlsjs-video@10.0.1

创建组件 Player.vue

复制代码
#Player.vue

<template>
  <media-i18n>
    <orientation-video-player ref="player" orientation-lock-type="landscape" >
      <video-skin ref="skin">
        <slot />
      </video-skin>
    </orientation-video-player>
  </media-i18n>
</template>

<script setup>
import { createPlayer, orientationLockFeature } from '@videojs/html'
import { videoFeatures } from '@videojs/html/video'

import '@videojs/html/video/skin.css'
import '@videojs/html/video/player'
import '@videojs/html/video/skin'
import '@videojs/html/media/hlsjs-video'
import '@videojs/html/i18n/locales/zh-CN/register'//中文


import {onMounted} from "vue";



/**
 * 注册支持横屏锁定的自定义播放器
 * <video-player> 是预设播放器,默认包含 videoFeatures,但不包含 orientationLockFeature
 * 想使用 Video.js 10 自带的横屏锁定功能,就需要通过 createPlayer() 注册一个包含该功能的播放器
 * https://videojs.org/docs/framework/html/guides/fullscreen
 * 
 */
function registerPlayer() {
  if (!customElements.get('orientation-video-player')) {

    const { PlayerElement } = createPlayer({
      features: [
        ...videoFeatures,
        orientationLockFeature
      ]
    })
    customElements.define(
        'orientation-video-player',
        PlayerElement
    )
  }
}
registerPlayer()

onMounted(()=>{

})


defineProps({
  lang: {
    type: String,
    default: 'zh-CN'
  }
})
</script>

<style scoped>
video-skin {
  display: block;
  width: 100%;
  aspect-ratio: 16 / 9;
}
</style>

在其他组件中使用

复制代码
<template>
  <player lang="zh-cn">
          <hlsjs-video src="http://xxx.com/xxxx.mp4"></hlsjs-video>
        </player>

</template>

<script setup>
import player from "@/components/player.vue";

</script>
相关推荐
夏幻灵9 小时前
JavaScript this 面试:五种绑定规则、优先级与常见面试陷阱
开发语言·javascript·面试
三天不学习10 小时前
Egg.js 4 突然爆火,原因是否归结于AI 原生落地需求爆发?
前端·javascript·全栈·egg.js
xcs1940511 小时前
前端 vue 的前端页面debugger 进不去
前端·javascript·vue.js
小宋102116 小时前
A2UI从零实战:Agent安全生成交互界面与事件回传
javascript·人工智能·安全·交互
大包子16 小时前
structuredClone vs lodash.cloneDeep:核心差异与选型指南
javascript·vue.js
lerhxx17 小时前
AI 应用中的上下文管理 —— 从"上下文窗口"到"分层压缩"的工程实践
前端·javascript
Mahut17 小时前
我在 Mac 上做了个本地剪辑器
javascript·架构·产品
汉堡大王952717 小时前
GPT-6 上线 48 小时,我扒开了 Intelligent UI 的运行机制:DIL、沙箱 Worker 和一个 React 式协调器
前端·javascript·后端
hai_android17 小时前
Chat 聊天模块功能总结
前端·javascript·vue.js