热门标签 | HotTags
当前位置:  开发笔记 > 编程语言 > 正文

html播放video实现弹幕效果DPlayer

先上效果InstallationUsingnpm:npminstalldplayer--saveUsingYarn:yarnadddplayerQuickStartAtfi

先上效果

 


Installation

Using npm:

npm install dplayer --save

Using Yarn:

yarn add dplayer

Quick Start

At first, let's initialize a simplest DPlayer

Load DPlayer files



Or work with module bundler:

import DPlayer from 'dplayer';const dp = new DPlayer(options);

Initialization in js:

const dp = new DPlayer({container: document.getElementById('dplayer'),screenshot: true,video: {url: 'demo.mp4',pic: 'demo.jpg',thumbnails: 'thumbnails.jpg',},subtitle: {url: 'webvtt.vtt',},danmaku: {id: 'demo',api: 'https://api.prprpr.me/dplayer/',},
});

Options

You can custom your player instance by those options


NameDefaultDescription
containerdocument.querySelector('.dplayer')player container
livefalseenable live mode, see #live
autoplayfalsevideo autoplay
theme'#b7daff'main color
loopfalsevideo loop
langnavigator.language.toLowerCase()values: 'en', 'zh-cn', 'zh-tw'
screenshotfalseenable screenshot, if true, video and video poster must enable Cross-Origin
airplaytrueenable airplay in Safari
hotkeytrueenable hotkey, support FF, FR, volume control, play & pause
preload'auto'values: 'none', 'metadata', 'auto'
volume0.7default volume, notice that player will remember user setting, default volume will not work after user set volume themselves
playbackSpeed[0.5, 0.75, 1, 1.25, 1.5, 2]optional playback speed, or or you can set a custom one
logo-showing logo in the top left corner, you can adjust its size and position by CSS
apiBackend-getting and sending danmaku in your way, see #live
video-video info
video.quality-see #Quality switching
video.defaultQuality-see #Quality switching
video.url-video url
video.pic-video poster
video.thumbnails-video thumbnails, generated by DPlayer-thumbnails(opens new window)
video.type'auto'values: 'auto', 'hls', 'flv', 'dash', 'webtorrent', 'normal' or other custom type, see #MSE support
video.customType-custom video type, see #MSE support
subtitle-external subtitle
subtitle.urlrequiredsubtitle url
subtitle.type'webvtt'subtitle type, values: 'webvtt', 'ass', but only webvtt is supported for now
subtitle.fontSize'20px'subtitle font size
subtitle.bottom'40px'the distance between the subtitle and player bottom, values like: '10px' '10%'
subtitle.color'#fff'subtitle color
danmaku-showing danmaku
danmaku.idrequireddanmaku pool id, it must be unique
danmaku.apirequiredsee #Danmaku API
danmaku.token-back end verification token
danmaku.maximum-danmaku maximum quantity
danmaku.addition-additional danmaku, see #bilibili danmaku
danmaku.user'DIYgod'danmaku user name
danmaku.bottom-values like: '10px' '10%', the distance between the danmaku bottom and player bottom, in order to prevent warding off subtitle
danmaku.unlimitedfalsedisplay all danmaku even though danmaku overlap, notice that player will remember user setting, default setting will not work after user set it themselves
contextmenu[]custom contextmenu
highlight[]custom time markers upon progress bar
mutextrueprevent to play multiple player at the same time, pause other players when this player start play

const dp = new DPlayer({container: document.getElementById('dplayer'),autoplay: false,theme: '#FADFA3',loop: true,lang: 'zh-cn',screenshot: true,hotkey: true,preload: 'auto',logo: 'logo.png',volume: 0.7,mutex: true,video: {url: 'dplayer.mp4',pic: 'dplayer.png',thumbnails: 'thumbnails.jpg',type: 'auto',},subtitle: {url: 'dplayer.vtt',type: 'webvtt',fontSize: '25px',bottom: '10%',color: '#b7daff',},danmaku: {id: '9E2E3368B56CDBB4',api: 'https://api.prprpr.me/dplayer/',token: 'tokendemo',maximum: 1000,addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=4157142'],user: 'DIYgod',bottom: '15%',unlimited: true,},contextmenu: [{text: 'custom1',link: 'https://github.com/DIYgod/DPlayer',},{text: 'custom2',click: (player) => {console.log(player);},},],highlight: [{text: 'marker for 20s',time: 20,},{text: 'marker for 2mins',time: 120,},],
});

查看插件地址:传送门


推荐阅读
  • Webpack5内置处理图片资源的配置方法
    本文介绍了在Webpack5中处理图片资源的配置方法。在Webpack4中,我们需要使用file-loader和url-loader来处理图片资源,但是在Webpack5中,这两个Loader的功能已经被内置到Webpack中,我们只需要简单配置即可实现图片资源的处理。本文还介绍了一些常用的配置方法,如匹配不同类型的图片文件、设置输出路径等。通过本文的学习,读者可以快速掌握Webpack5处理图片资源的方法。 ... [详细]
  • 网络请求模块选择——axios框架的基本使用和封装
    本文介绍了选择网络请求模块axios的原因,以及axios框架的基本使用和封装方法。包括发送并发请求的演示,全局配置的设置,创建axios实例的方法,拦截器的使用,以及如何封装和请求响应劫持等内容。 ... [详细]
  • React 小白初入门
    推荐学习:React官方文档:https:react.docschina.orgReact菜鸟教程:https:www.runoob.c ... [详细]
  • 前言:原本纠结于Web模板,选了Handlebars。后来发现页面都是弱逻辑的,不支持复杂逻辑表达式。几乎要放弃之际,想起了Javascript中ev ... [详细]
  • 本文主要解析了Open judge C16H问题中涉及到的Magical Balls的快速幂和逆元算法,并给出了问题的解析和解决方法。详细介绍了问题的背景和规则,并给出了相应的算法解析和实现步骤。通过本文的解析,读者可以更好地理解和解决Open judge C16H问题中的Magical Balls部分。 ... [详细]
  • 本文讨论了一个关于cuowu类的问题,作者在使用cuowu类时遇到了错误提示和使用AdjustmentListener的问题。文章提供了16个解决方案,并给出了两个可能导致错误的原因。 ... [详细]
  • 本文介绍了P1651题目的描述和要求,以及计算能搭建的塔的最大高度的方法。通过动态规划和状压技术,将问题转化为求解差值的问题,并定义了相应的状态。最终得出了计算最大高度的解法。 ... [详细]
  • 本文介绍了在Windows环境下如何配置php+apache环境,包括下载php7和apache2.4、安装vc2015运行时环境、启动php7和apache2.4等步骤。希望对需要搭建php7环境的读者有一定的参考价值。摘要长度为169字。 ... [详细]
  • Java学习笔记之面向对象编程(OOP)
    本文介绍了Java学习笔记中的面向对象编程(OOP)内容,包括OOP的三大特性(封装、继承、多态)和五大原则(单一职责原则、开放封闭原则、里式替换原则、依赖倒置原则)。通过学习OOP,可以提高代码复用性、拓展性和安全性。 ... [详细]
  • CentOS 6.5安装VMware Tools及共享文件夹显示问题解决方法
    本文介绍了在CentOS 6.5上安装VMware Tools及解决共享文件夹显示问题的方法。包括清空CD/DVD使用的ISO镜像文件、创建挂载目录、改变光驱设备的读写权限等步骤。最后给出了拷贝解压VMware Tools的操作。 ... [详细]
  • 本文讨论了在手机移动端如何使用HTML5和JavaScript实现视频上传并压缩视频质量,或者降低手机摄像头拍摄质量的问题。作者指出HTML5和JavaScript无法直接压缩视频,只能通过将视频传送到服务器端由后端进行压缩。对于控制相机拍摄质量,只有使用JAVA编写Android客户端才能实现压缩。此外,作者还解释了在交作业时使用zip格式压缩包导致CSS文件和图片音乐丢失的原因,并提供了解决方法。最后,作者还介绍了一个用于处理图片的类,可以实现图片剪裁处理和生成缩略图的功能。 ... [详细]
  • 预备知识可参考我整理的博客Windows编程之线程:https:www.cnblogs.comZhuSenlinp16662075.htmlWindows编程之线程同步:https ... [详细]
  • ECMA262规定typeof操作符的返回值和instanceof的使用方法
    本文介绍了ECMA262规定的typeof操作符对不同类型的变量的返回值,以及instanceof操作符的使用方法。同时还提到了在不同浏览器中对正则表达式应用typeof操作符的返回值的差异。 ... [详细]
  • Netty源代码分析服务器端启动ServerBootstrap初始化
    本文主要分析了Netty源代码中服务器端启动的过程,包括ServerBootstrap的初始化和相关参数的设置。通过分析NioEventLoopGroup、NioServerSocketChannel、ChannelOption.SO_BACKLOG等关键组件和选项的作用,深入理解Netty服务器端的启动过程。同时,还介绍了LoggingHandler的作用和使用方法,帮助读者更好地理解Netty源代码。 ... [详细]
  • RN即ReactNative基于React框架针对移动端的跨平台框架,在学习RN前建议最好熟悉下html,css,js,当然如果比较急,那就直接上手吧,毕竟用学习前面基础的时间,R ... [详细]
author-avatar
陈小超Sum
这个家伙很懒,什么也没留下!
PHP1.CN | 中国最专业的PHP中文社区 | DevBox开发工具箱 | json解析格式化 |PHP资讯 | PHP教程 | 数据库技术 | 服务器技术 | 前端开发技术 | PHP框架 | 开发工具 | 在线工具
Copyright © 1998 - 2020 PHP1.CN. All Rights Reserved | 京公网安备 11010802041100号 | 京ICP备19059560号-4 | PHP1.CN 第一PHP社区 版权所有