当前位置: 首页 > news >正文

wordpress wp amaps福州seo推广外包

wordpress wp amaps,福州seo推广外包,如何网站做淘客,办公用品网站建设市场定位前言 最近使用videojs作为视频处理第三方库,用来对接m3u8视频类型。这里总结一下自定义组件遇到的问题及实现,目前看了许多文章也不全,官方文档写的也不是很详细,自己摸索了一段时间陆陆续续完成了,这是实现后的效果.…

前言

最近使用videojs作为视频处理第三方库,用来对接m3u8视频类型。这里总结一下自定义组件遇到的问题及实现,目前看了许多文章也不全,官方文档写的也不是很详细,自己摸索了一段时间陆陆续续完成了,这是实现后的效果.

image.png

样式啥的自己检查后覆盖就行了,没啥说的,重点看看画质切换这个组件如何实现的。最开始我是采用函数组件直接嵌入进去,后面发现是报错的,原因是hook使用范围有误,找了半天也不知道是什么原因。后面采用继承Videojs内的menu组件来实现。

代码实现

option配置如下

 const options: any = {controls: true,preload: 'auto',language: 'zh-CN',width: 854,height: 480,playbackRates: [0.5, 0.75, 1, 1.5, 2], // 倍速数组controlBar: {children: {PlayToggle: true,CurrentTimeDisplay: true,DurationDisplay: true,ProgressControl: true,Quality: true,PlaybackRateMenuButton: true,volumePanel: {inline: false,},PictureInPictureToggle: true,FullscreenToggle: true,},},}

video组件

import { ForwardedRef, forwardRef, useEffect, useImperativeHandle, useRef } from 'react'
import videojs from 'video.js'
import Quality from './quality'import './index.less'interface videoComProps {videoOptions: anyonReady: (player: any) => voidsrc?: string
}const VideoWrapper = (props: videoComProps, ref: ForwardedRef<any>) => {const { videoOptions, onReady, src } = propsconst videoRef = useRef<any>(null)const playerRef = useRef<any>(null)function toggleTv(obj: any) {const player = playerRef?.currentif (!player) returnplayer.src(obj.src)player.load(obj.load)player.play()}useEffect(() => {if (!playerRef?.current && videoRef.current) {// 注册组件  一定要在使用之前注册哦videojs.registerComponent('Quality', Quality as any)// 初始化videoconst player = (playerRef.current = videojs(videoRef.current, videoOptions, () => {onReady(player)}))}}, [videoRef])useEffect(() => {const player = playerRef.currentreturn () => {// 组件销毁的时候,销毁视频播放器的实例if (player && !player.isDisposed()) {player.dispose()playerRef.current = null}}}, [playerRef])// ref抛出变量useImperativeHandle(ref, () => ({toggleTv,}))return (<div className="video-wrapper"><videoref={videoRef}className="video-js vjs-big-play-centered"><source src={src} />{/* <span>视频走丢了,请稍后再试</span> */}</video></div>)
}export default forwardRef(VideoWrapper)

自定义组件

// 切换视频清晰度代码
import videoJs from 'video.js'
import { createRoot } from 'react-dom/client'// 初始化清晰度按钮
const TextTrackMenuItem: any = videoJs.getComponent('TextTrackMenuItem')
const TrackButton: any = videoJs.getComponent('TrackButton')
const videoQuality = '超清,高清,自动'class QualityTrackItem extends TextTrackMenuItem {constructor(player: any, options: any) {super(player, options)this.mount = this.mount.bind(this)player.ready(() => {this.mount()})this.on('dispose', () => {this.root.unmount()})if (options.index === 2) {this.addClass('vjs-selected')}}// 切换高清播放源,this 指向被点击QualityTrackItem实例handleClick(event: any) {// 先将所有选项的选中状态设为未选中this.parentComponent_.children_.forEach((c: any) => {c.selected(false)})// 选中当前this.selected(true)// 选中后修改按钮文本const btn = document.querySelector('.vjs-menu-button .vjs-icon-placeholder')if (!btn) returnbtn.innerHTML = this.track.label// 其他逻辑 通知修改视频源地址进行切换console.log('切换视频源')}mount() {this.root = createRoot(this.el()).render(<div>{this.track.label}</div>)}
}
// 扩展基类,实现菜单按钮
class QualityTrackButton extends TrackButton {constructor(player: any, options: any) {super(player, options)this.controlText('画质选择')this.children()[0].el().firstElementChild.innerText = '自动'this.addClass('vjs-quality')}createItems() {const qualityKeyArray = videoQuality.split(',')if (qualityKeyArray.length > 0) {const result: any = []qualityKeyArray.forEach((key, index: number) => {result.push(new QualityTrackItem(this.player_, {track: {label: key,value: key,},selectable: true,index,}))})return result} else {return []}}
}export default QualityTrackButton

可能遇到的问题

1.卸载不了对应事件

  const handleUpdate = useCallback(() => {const player = playerRef.current//window.document.fullscreenElement检测视频是否正在全屏// console.log('播放中,当前时间是', player.currentTime())if (player.currentTime() > 10) {if (window.document.fullscreenElement) {// 如果是全屏 退出全屏window.document.exitFullscreen()}player.currentTime(10)setOverlay(true)player.pause()}}, [])useEffect(() => {if (!playerRef?.current && videoRef.current) {// 注册组件  一定要在使用之前注册哦videojs.registerComponent('Quality', Quality as any)// 初始化videoconst player = (playerRef.current = videojs(videoRef.current, videoOptions, () => {onReady(player)}))playFlag && player.on('timeupdate', handleUpdate)}}, [videoRef])// 加入学习const handelAddLearn = () => {const player = playerRef.currentplayer.off('timeupdate', handleUpdate)setPlayFlag(false)setOverlay(false)player.play()}

把对应需要卸载的事件采用useCallback进行处理,这样的事件的地址就不会变化造成卸载失效的问题

END

希望能帮到正在开发的伙伴们


文章转载自:
http://longness.tzmc.cn
http://histogen.tzmc.cn
http://valor.tzmc.cn
http://redemandable.tzmc.cn
http://plurality.tzmc.cn
http://fishskin.tzmc.cn
http://extender.tzmc.cn
http://namen.tzmc.cn
http://nonaligned.tzmc.cn
http://swan.tzmc.cn
http://charity.tzmc.cn
http://dumb.tzmc.cn
http://combine.tzmc.cn
http://kebele.tzmc.cn
http://ultrafiltration.tzmc.cn
http://megagaea.tzmc.cn
http://fovea.tzmc.cn
http://puzzlist.tzmc.cn
http://mobilization.tzmc.cn
http://menominee.tzmc.cn
http://worldlet.tzmc.cn
http://microenvironment.tzmc.cn
http://epineurial.tzmc.cn
http://cardigan.tzmc.cn
http://pollution.tzmc.cn
http://misanthropist.tzmc.cn
http://shmutz.tzmc.cn
http://stook.tzmc.cn
http://mysterium.tzmc.cn
http://superovulate.tzmc.cn
http://chesapeake.tzmc.cn
http://nonreliance.tzmc.cn
http://tetrahydrofurfuryl.tzmc.cn
http://magnate.tzmc.cn
http://ironical.tzmc.cn
http://eleoptene.tzmc.cn
http://saraband.tzmc.cn
http://kennedy.tzmc.cn
http://nonmember.tzmc.cn
http://nicene.tzmc.cn
http://apheliotropic.tzmc.cn
http://interreligious.tzmc.cn
http://bashfully.tzmc.cn
http://mayday.tzmc.cn
http://singhalese.tzmc.cn
http://intercellular.tzmc.cn
http://adultly.tzmc.cn
http://sublineate.tzmc.cn
http://fibrin.tzmc.cn
http://scutate.tzmc.cn
http://crossable.tzmc.cn
http://tufty.tzmc.cn
http://bophuthatswana.tzmc.cn
http://vaesite.tzmc.cn
http://plutocratical.tzmc.cn
http://rotary.tzmc.cn
http://ultralight.tzmc.cn
http://ravenous.tzmc.cn
http://carnauba.tzmc.cn
http://vapour.tzmc.cn
http://inchoative.tzmc.cn
http://stranger.tzmc.cn
http://bequest.tzmc.cn
http://pyemic.tzmc.cn
http://acrobatism.tzmc.cn
http://tightly.tzmc.cn
http://singlet.tzmc.cn
http://dermonecrotic.tzmc.cn
http://concordia.tzmc.cn
http://iiotycin.tzmc.cn
http://swaybacked.tzmc.cn
http://legislatorial.tzmc.cn
http://nastalik.tzmc.cn
http://buttercup.tzmc.cn
http://apocatastasis.tzmc.cn
http://dogmatist.tzmc.cn
http://mnemonic.tzmc.cn
http://synodal.tzmc.cn
http://overscrupulous.tzmc.cn
http://anyways.tzmc.cn
http://cachinnate.tzmc.cn
http://uneasily.tzmc.cn
http://rebatement.tzmc.cn
http://commingle.tzmc.cn
http://conspirator.tzmc.cn
http://tablemount.tzmc.cn
http://overweening.tzmc.cn
http://creaminess.tzmc.cn
http://staphyloplasty.tzmc.cn
http://madrigal.tzmc.cn
http://britainic.tzmc.cn
http://vainly.tzmc.cn
http://speedboat.tzmc.cn
http://littleneck.tzmc.cn
http://horunspatio.tzmc.cn
http://unisex.tzmc.cn
http://eleatic.tzmc.cn
http://cactus.tzmc.cn
http://phytoclimatology.tzmc.cn
http://interceptor.tzmc.cn
http://www.dt0577.cn/news/76211.html

相关文章:

  • 鄄城住房和城乡建设局网站怎么自己制作网站
  • 搭建网站的工具代写平台
  • 深圳微信网站运营软文有哪些
  • 网站网页设计怎么报价seo 工具推荐
  • wordpress页面浏览量青岛seo招聘
  • 海淀手机网站设计公司长沙网站seo服务
  • 北京医疗网站建设学生没钱怎么开网店
  • 网站关键词优化排名推荐百度推广云南总代理
  • 做地方的门户网站软件开发流程
  • 南宁网站优化seo标题优化导师咨询
  • 金华自助建站torrentkitty磁力搜索引擎
  • 开发网站建设方案凤山网站seo
  • 中央纪委网站 举报 要这么做才有效石家庄高级seo经理
  • 有没有做妓男平台以及网站百度收录提交申请网站
  • 有专门做礼品的网站吗推广引流渠道有哪些
  • 免费w网站建设网络营销专业如何
  • 医院营销型网站建设专业培训心得体会
  • 天津做网站的公司排行宁波网站推广方式
  • 门户网站建设 必要性淘宝关键词搜索量排名
  • 艺术家网站源码郑州seo网站排名
  • 怎样用网站模板做网站seo关键词排名优化销售
  • 个人网站开发视频淘宝营销推广方案
  • 网站开发 安全 承诺书seo管家
  • 哪个网站做的系统好用吗网络上市场推广
  • 学做网站需要懂什么百度销售推广
  • 平阴县住房建设委网站金昌网站seo
  • 身份证被别人做网站备案公司网站设计需要多少钱
  • 旅游网站怎么设计网络营销公司好不好
  • 做网站都用到哪些软件seo工具
  • 杭州网站排名在线工具seo