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>
相关推荐
Funlang24 分钟前
在 Windows 95 上写前端
前端·javascript·windows
AI前端工程狮1 小时前
我给 MCP 长任务加进度条,五步只显示了一步
javascript·人工智能·程序员
彩虹暴龙兽3 小时前
JavaScript 作用域、闭包与对象
javascript
Highcharts.js4 小时前
Highcharts与TypeScript集成指南
前端·javascript·typescript·前端框架·数据可视化·highcharts
桃李无言下自成蹊5 小时前
为什么越清晰的二维码越扫不出来:jsQR 四轮解码与 8 个真实坑
javascript
小y的笔记5 小时前
Vue 3 异步搜索实战:watch、请求取消与竞态控制
前端·javascript
用户298698530148 小时前
React 前端实现 Excel 与 HTML 双向转换:基于 WebAssembly 的浏览器端方案
javascript·html·excel
1-1=08 小时前
Vue 表单数据和过滤器
前端·javascript·vue.js
头发还在的女程序员9 小时前
智慧物业源码解析:房屋档案与业主变更怎样保持历史业务连续
前端·javascript·vue.js·物业管理·小区物业·智慧物业
feixing_fx18 小时前
第一个 JS 程序:在浏览器控制台和 Node 中分别运行
开发语言·前端·javascript·前端框架·ecmascript