html video 自定义控制栏(移动端应用)

<!DOCTYPE HTML>
<html>
<meta charset="UTF-8">
<title>

</title>
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover">


<head>
<style>
#box {
width: 100%;
height: 40px;
background: #eeeeee;
border-radius: 10px;
<!--圆角-->box-shadow: 1px 1px 2px 2px #232;
<!--阴影-->border: 1px solid #ff0000
}

.play {
<!--用css画三角形-->width: 0px;
height: 0px;
float: left;
margin-top: 10px;
width: 10px;
width: 0;
height: 0;
border-top: 10px solid transparent;
border-left: 16px solid #666666;
border-bottom: 10px solid transparent;
}

.pause {
<!--用css画两条竖线-->width: 6px;
height: 18px;
border-left: 4px solid #666666;
border-right: 4px solid #666666;
float: left;
margin-top: 10px;
width: 10px;
}

.time {
color: #666666;
float: left;
width: 8%;
margin-top: 12px;
font-size: 14px;
margin-left: 10px;
height: 18px;
}

#progress {
float: left;
width: 55%;
height: 8px;
background: #fff;
box-shadow: 1px 1px 2px 2px #232;
border-radius: 5px;
margin-top: 16px;
margin-left: 16px;
position: relative;
}

#bar {
width: 10%;
height: 100%;
background: #ccc;
border-radius: 3px;
display: inline-block;
position: absolute;
top: 0;
left: 0;
}

#control {
width: 17px;
height: 17px;
position: absolute;
border-ra

  • 22
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要在 React 使用 Video.js 并添加自定义控制,你可以按照以下步骤: 1. 安装 Video.js 和 React Video.js 在你的 React 项目安装 Video.js 和 React Video.js: ``` npm install --save video.js react-videojs ``` 2. 导入 Video.js 和 React Video.js 在你的组件导入 Video.js 和 React Video.js: ``` import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import VideoJS from 'react-videojs'; ``` 3. 创建自定义控制 在 `componentDidMount` 生命周期创建自定义控制。你可以使用 Video.js API 创建控制,例如: ``` componentDidMount() { const videoJsOptions = { controls: false, sources: [{ src: 'https://example.com/path/to/video.mp4', type: 'video/mp4' }] }; this.player = videojs(this.videoNode, videoJsOptions); const ControlBar = videojs.getComponent('ControlBar'); const CustomControlBar = videojs.extend(ControlBar, { constructor: function() { ControlBar.apply(this, arguments); this.addClass('vjs-custom-control-bar'); } }); videojs.registerComponent('CustomControlBar', CustomControlBar); const customControlBar = new CustomControlBar(this.player); this.player.addChild(customControlBar); customControlBar.addChild('playToggle'); customControlBar.addChild('currentTimeDisplay'); customControlBar.addChild('timeDivider'); customControlBar.addChild('durationDisplay'); customControlBar.addChild('progressControl'); customControlBar.addChild('volumePanel'); customControlBar.addChild('fullscreenToggle'); } ``` 在上面的代码,我们创建了一个自定义控制,并将其添加到了 Video.js 播放器控制包含了常用的控制按钮和进度条。 4. 渲染 Video.js 播放器 在 `render` 方法,渲染 Video.js 播放器: ``` render() { return ( <div data-vjs-player> <video ref={ node => this.videoNode = node } className="video-js"></video> </div> ) } ``` 这将在 DOM 创建一个 `<video>` 元素并将其传递给 Video.js。 5. 完整代码示例 下面是一个完整的代码示例,演示如何在 React 使用 Video.js 并添加自定义控制: ``` import React, { Component } from 'react'; import videojs from 'video.js'; import 'video.js/dist/video-js.css'; import VideoJS from 'react-videojs'; export default class VideoPlayer extends Component { componentDidMount() { const videoJsOptions = { controls: false, sources: [{ src: 'https://example.com/path/to/video.mp4', type: 'video/mp4' }] }; this.player = videojs(this.videoNode, videoJsOptions); const ControlBar = videojs.getComponent('ControlBar'); const CustomControlBar = videojs.extend(ControlBar, { constructor: function() { ControlBar.apply(this, arguments); this.addClass('vjs-custom-control-bar'); } }); videojs.registerComponent('CustomControlBar', CustomControlBar); const customControlBar = new CustomControlBar(this.player); this.player.addChild(customControlBar); customControlBar.addChild('playToggle'); customControlBar.addChild('currentTimeDisplay'); customControlBar.addChild('timeDivider'); customControlBar.addChild('durationDisplay'); customControlBar.addChild('progressControl'); customControlBar.addChild('volumePanel'); customControlBar.addChild('fullscreenToggle'); } componentWillUnmount() { if (this.player) { this.player.dispose(); } } render() { return ( <div data-vjs-player> <video ref={ node => this.videoNode = node } className="video-js"></video> </div> ) } } ``` 注意,如果你需要在组件卸载时销毁 Video.js 播放器,请确保在 `componentWillUnmount` 生命周期调用 `this.player.dispose()`。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值