|
@@ -44,7 +44,8 @@ sidebar: auto
|
|
|
### Sponsors
|
|
|
|
|
|
| [极酷社](https://www.acg.app) |
|
|
|
-| :--------------------------: |
|
|
|
+| :---------------------------: |
|
|
|
+
|
|
|
|
|
|
## Installation
|
|
|
|
|
@@ -67,7 +68,7 @@ At first, let's initialize a simplest DPlayer
|
|
|
Load DPlayer files
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
|
```
|
|
@@ -90,15 +91,15 @@ const dp = new DPlayer({
|
|
|
video: {
|
|
|
url: 'demo.mp4',
|
|
|
pic: 'demo.jpg',
|
|
|
- thumbnails: 'thumbnails.jpg'
|
|
|
+ thumbnails: 'thumbnails.jpg',
|
|
|
},
|
|
|
subtitle: {
|
|
|
- url: 'webvtt.vtt'
|
|
|
+ url: 'webvtt.vtt',
|
|
|
},
|
|
|
danmaku: {
|
|
|
id: 'demo',
|
|
|
- api: 'https://api.prprpr.me/dplayer/'
|
|
|
- }
|
|
|
+ api: 'https://api.prprpr.me/dplayer/',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -106,46 +107,46 @@ const dp = new DPlayer({
|
|
|
|
|
|
You can custom your player instance by those options
|
|
|
|
|
|
-Name | Default | Description
|
|
|
-----|-------|----
|
|
|
-container | document.querySelector('.dplayer') | player container
|
|
|
-live | false | enable live mode, see [#live](#live)
|
|
|
-autoplay | false | video autoplay
|
|
|
-theme | '#b7daff' | main color
|
|
|
-loop | false | video loop
|
|
|
-lang | navigator.language.toLowerCase() | values: 'en', 'zh-cn', 'zh-tw'
|
|
|
-screenshot | false | enable screenshot, if true, video and video poster must enable Cross-Origin
|
|
|
-hotkey | true | enable hotkey, support FF, FR, volume control, play & pause
|
|
|
-preload | 'auto' | values: 'none', 'metadata', 'auto'
|
|
|
-volume | 0.7 | default volume, notice that player will remember user setting, default volume will not work after user set volume themselves
|
|
|
-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](#live)
|
|
|
-video | - | video info
|
|
|
-video.quality | - | see [#Quality switching](#quality-switching)
|
|
|
-video.defaultQuality | - | see [#Quality switching](#quality-switching)
|
|
|
-video.url | - | video url
|
|
|
-video.pic | - | video poster
|
|
|
-video.thumbnails | - | video thumbnails, generated by [DPlayer-thumbnails](https://github.com/MoePlayer/DPlayer-thumbnails)
|
|
|
-video.type | 'auto' | values: 'auto', 'hls', 'flv', 'dash', 'webtorrent', 'normal' or other custom type, see [#MSE support](#mse-support)
|
|
|
-video.customType | - | custom video type, see [#MSE support](#mse-support)
|
|
|
-subtitle | - | external subtitle
|
|
|
-subtitle.url | `required` | subtitle 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.id | `required` | danamku pool id, it must be unique
|
|
|
-danmaku.api | `required` | see [#Danmaku API](#danmaku-api)
|
|
|
-danmaku.token | - | back end verification token
|
|
|
-danmaku.maximum | - | danmaku maximum quantity
|
|
|
-danmaku.addition | - | additional danmaku, see [#bilibili danmaku](#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.unlimited | false | display 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
|
|
|
-mutex | true | prevent to play multiple player at the same time, pause other players when this player start play
|
|
|
+| Name | Default | Description |
|
|
|
+| -------------------- | ---------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
|
+| container | document.querySelector('.dplayer') | player container |
|
|
|
+| live | false | enable live mode, see [#live](#live) |
|
|
|
+| autoplay | false | video autoplay |
|
|
|
+| theme | '#b7daff' | main color |
|
|
|
+| loop | false | video loop |
|
|
|
+| lang | navigator.language.toLowerCase() | values: 'en', 'zh-cn', 'zh-tw' |
|
|
|
+| screenshot | false | enable screenshot, if true, video and video poster must enable Cross-Origin |
|
|
|
+| hotkey | true | enable hotkey, support FF, FR, volume control, play & pause |
|
|
|
+| preload | 'auto' | values: 'none', 'metadata', 'auto' |
|
|
|
+| volume | 0.7 | default volume, notice that player will remember user setting, default volume will not work after user set volume themselves |
|
|
|
+| 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](#live) |
|
|
|
+| video | - | video info |
|
|
|
+| video.quality | - | see [#Quality switching](#quality-switching) |
|
|
|
+| video.defaultQuality | - | see [#Quality switching](#quality-switching) |
|
|
|
+| video.url | - | video url |
|
|
|
+| video.pic | - | video poster |
|
|
|
+| video.thumbnails | - | video thumbnails, generated by [DPlayer-thumbnails](https://github.com/MoePlayer/DPlayer-thumbnails) |
|
|
|
+| video.type | 'auto' | values: 'auto', 'hls', 'flv', 'dash', 'webtorrent', 'normal' or other custom type, see [#MSE support](#mse-support) |
|
|
|
+| video.customType | - | custom video type, see [#MSE support](#mse-support) |
|
|
|
+| subtitle | - | external subtitle |
|
|
|
+| subtitle.url | `required` | subtitle 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.id | `required` | danamku pool id, it must be unique |
|
|
|
+| danmaku.api | `required` | see [#Danmaku API](#danmaku-api) |
|
|
|
+| danmaku.token | - | back end verification token |
|
|
|
+| danmaku.maximum | - | danmaku maximum quantity |
|
|
|
+| danmaku.addition | - | additional danmaku, see [#bilibili danmaku](#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.unlimited | false | display 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 |
|
|
|
+| mutex | true | prevent to play multiple player at the same time, pause other players when this player start play |
|
|
|
|
|
|
```js
|
|
|
const dp = new DPlayer({
|
|
@@ -164,14 +165,14 @@ const dp = new DPlayer({
|
|
|
url: 'dplayer.mp4',
|
|
|
pic: 'dplayer.png',
|
|
|
thumbnails: 'thumbnails.jpg',
|
|
|
- type: 'auto'
|
|
|
+ type: 'auto',
|
|
|
},
|
|
|
subtitle: {
|
|
|
url: 'dplayer.vtt',
|
|
|
type: 'webvtt',
|
|
|
fontSize: '25px',
|
|
|
bottom: '10%',
|
|
|
- color: '#b7daff'
|
|
|
+ color: '#b7daff',
|
|
|
},
|
|
|
danmaku: {
|
|
|
id: '9E2E3368B56CDBB4',
|
|
@@ -181,204 +182,210 @@ const dp = new DPlayer({
|
|
|
addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=4157142'],
|
|
|
user: 'DIYgod',
|
|
|
bottom: '15%',
|
|
|
- unlimited: true
|
|
|
+ unlimited: true,
|
|
|
},
|
|
|
contextmenu: [
|
|
|
{
|
|
|
text: 'custom1',
|
|
|
- link: 'https://github.com/DIYgod/DPlayer'
|
|
|
+ link: 'https://github.com/DIYgod/DPlayer',
|
|
|
},
|
|
|
{
|
|
|
text: 'custom2',
|
|
|
click: (player) => {
|
|
|
console.log(player);
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
],
|
|
|
highlight: [
|
|
|
{
|
|
|
text: 'marker for 20s',
|
|
|
- time: 20
|
|
|
+ time: 20,
|
|
|
},
|
|
|
{
|
|
|
text: 'marker for 2mins',
|
|
|
- time: 120
|
|
|
- }
|
|
|
- ]
|
|
|
+ time: 120,
|
|
|
+ },
|
|
|
+ ],
|
|
|
});
|
|
|
```
|
|
|
|
|
|
## API
|
|
|
|
|
|
-+ `dp.play()`: play video
|
|
|
+- `dp.play()`: play video
|
|
|
|
|
|
-+ `dp.pause()`: pause video
|
|
|
+- `dp.pause()`: pause video
|
|
|
|
|
|
-+ `dp.seek(time: number)`: seek to specified time
|
|
|
+- `dp.seek(time: number)`: seek to specified time
|
|
|
|
|
|
- ```js
|
|
|
- dp.seek(100);
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.seek(100);
|
|
|
+ ```
|
|
|
|
|
|
-+ `dp.toggle()`: toggle between play and pause
|
|
|
+- `dp.toggle()`: toggle between play and pause
|
|
|
|
|
|
-+ `dp.on(event: string, handler: function)`: bind video and player events, [see more details](http://dplayer.js.org/#/home?id=event-binding)
|
|
|
+- `dp.on(event: string, handler: function)`: bind video and player events, [see more details](http://dplayer.js.org/#/home?id=event-binding)
|
|
|
|
|
|
-+ `dp.switchVideo(video, danmaku)`: switch to a new video
|
|
|
+- `dp.switchVideo(video, danmaku)`: switch to a new video
|
|
|
|
|
|
- ```js
|
|
|
- dp.switchVideo({
|
|
|
- url: 'second.mp4',
|
|
|
- pic: 'second.png',
|
|
|
- thumbnails: 'second.jpg'
|
|
|
- }, {
|
|
|
- id: 'test',
|
|
|
- api: 'https://api.prprpr.me/dplayer/',
|
|
|
- maximum: 3000,
|
|
|
- user: 'DIYgod'
|
|
|
- });
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.switchVideo(
|
|
|
+ {
|
|
|
+ url: 'second.mp4',
|
|
|
+ pic: 'second.png',
|
|
|
+ thumbnails: 'second.jpg',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ id: 'test',
|
|
|
+ api: 'https://api.prprpr.me/dplayer/',
|
|
|
+ maximum: 3000,
|
|
|
+ user: 'DIYgod',
|
|
|
+ }
|
|
|
+ );
|
|
|
+ ```
|
|
|
|
|
|
-+ `dp.notice(text: string, time: number, opacity: number)`: show message, the unit of time is millisecond, the default of time is 2000, the default of opacity is 0.8
|
|
|
+- `dp.notice(text: string, time: number, opacity: number)`: show message, the unit of time is millisecond, the default of time is 2000, the default of opacity is 0.8
|
|
|
|
|
|
- ```js
|
|
|
- dp.notice('Amazing player', 2000, 0.8);
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.notice('Amazing player', 2000, 0.8);
|
|
|
+ ```
|
|
|
|
|
|
-+ `dp.switchQuality(index: number)`: switch quality
|
|
|
+- `dp.switchQuality(index: number)`: switch quality
|
|
|
|
|
|
-+ `dp.destroy()`: destroy player
|
|
|
+- `dp.destroy()`: destroy player
|
|
|
|
|
|
-+ `dp.speed(rate: number)`: set video speed
|
|
|
+- `dp.speed(rate: number)`: set video speed
|
|
|
|
|
|
-+ `dp.volume(percentage: number, nostorage: boolean, nonotice: boolean)`: set video volume
|
|
|
+- `dp.volume(percentage: number, nostorage: boolean, nonotice: boolean)`: set video volume
|
|
|
|
|
|
- ```js
|
|
|
- dp.volume(0.1, true, false);
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.volume(0.1, true, false);
|
|
|
+ ```
|
|
|
|
|
|
-+ `dp.video`: native video
|
|
|
+- `dp.video`: native video
|
|
|
|
|
|
- + `dp.video.currentTime`: returns the current playback position
|
|
|
+- `dp.video.currentTime`: returns the current playback position
|
|
|
|
|
|
- + `dp.video.duration`: returns video total time
|
|
|
+- `dp.video.duration`: returns video total time
|
|
|
|
|
|
- + `dp.video.paused`: returns whether the video paused
|
|
|
+- `dp.video.paused`: returns whether the video paused
|
|
|
|
|
|
- + most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
|
|
|
+- most [native api](http://www.w3schools.com/tags/ref_av_dom.asp) are supported
|
|
|
|
|
|
-+ `dp.danmaku`
|
|
|
+- `dp.danmaku`
|
|
|
|
|
|
- + `dp.danmaku.send(danmaku, callback: function)`: submit a new danmaku to back end
|
|
|
+- `dp.danmaku.send(danmaku, callback: function)`: submit a new danmaku to back end
|
|
|
|
|
|
- ```js
|
|
|
- dp.danmaku.send({
|
|
|
- text: 'dplayer is amazing',
|
|
|
- color: '#b7daff',
|
|
|
- type: 'right' // should be `top` `bottom` or `right`
|
|
|
- }, function () {
|
|
|
- console.log('success');
|
|
|
- });
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.danmaku.send(
|
|
|
+ {
|
|
|
+ text: 'dplayer is amazing',
|
|
|
+ color: '#b7daff',
|
|
|
+ type: 'right', // should be `top` `bottom` or `right`
|
|
|
+ },
|
|
|
+ function() {
|
|
|
+ console.log('success');
|
|
|
+ }
|
|
|
+ );
|
|
|
+ ```
|
|
|
|
|
|
- + `dp.danmaku.draw(danmaku)`: draw a new danmaku to player in real time
|
|
|
+- `dp.danmaku.draw(danmaku)`: draw a new danmaku to player in real time
|
|
|
|
|
|
- ```js
|
|
|
- dp.danmaku.draw({
|
|
|
- text: 'DIYgod is amazing',
|
|
|
- color: '#fff',
|
|
|
- type: 'top'
|
|
|
- });
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.danmaku.draw({
|
|
|
+ text: 'DIYgod is amazing',
|
|
|
+ color: '#fff',
|
|
|
+ type: 'top',
|
|
|
+ });
|
|
|
+ ```
|
|
|
|
|
|
- + `dp.danmaku.opacity(percentage: number)`: set danmaku opacity, opacity should between 0 and 1
|
|
|
+- `dp.danmaku.opacity(percentage: number)`: set danmaku opacity, opacity should between 0 and 1
|
|
|
|
|
|
- ```js
|
|
|
- dp.danmaku.opacity(0.5);
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.danmaku.opacity(0.5);
|
|
|
+ ```
|
|
|
|
|
|
- + `dp.danmaku.clear()`: clear all danmakus
|
|
|
+- `dp.danmaku.clear()`: clear all danmakus
|
|
|
|
|
|
- + `dp.danmaku.hide()`: hide danmaku
|
|
|
+- `dp.danmaku.hide()`: hide danmaku
|
|
|
|
|
|
- + `dp.danmaku.show()`: show danmaku
|
|
|
+- `dp.danmaku.show()`: show danmaku
|
|
|
|
|
|
-+ `dp.fullScreen`: two type: `web` or `browser`, the default one is `browser`
|
|
|
+- `dp.fullScreen`: two type: `web` or `browser`, the default one is `browser`
|
|
|
|
|
|
- + `dp.fullScreen.request(type: string)`: request fullscreen
|
|
|
+- `dp.fullScreen.request(type: string)`: request fullscreen
|
|
|
|
|
|
- ```js
|
|
|
- dp.fullScreen.request('web');
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.fullScreen.request('web');
|
|
|
+ ```
|
|
|
|
|
|
- + `dp.fullScreen.cancel(type: string)`: cancel fullscreen
|
|
|
+- `dp.fullScreen.cancel(type: string)`: cancel fullscreen
|
|
|
|
|
|
- ```js
|
|
|
- dp.fullScreen.cancel('web');
|
|
|
- ```
|
|
|
+ ```js
|
|
|
+ dp.fullScreen.cancel('web');
|
|
|
+ ```
|
|
|
|
|
|
## Event binding
|
|
|
|
|
|
`dp.on(event, handler)`
|
|
|
|
|
|
```js
|
|
|
-dp.on('ended', function () {
|
|
|
+dp.on('ended', function() {
|
|
|
console.log('player ended');
|
|
|
});
|
|
|
```
|
|
|
|
|
|
Video events
|
|
|
|
|
|
-- abort
|
|
|
-- canplay
|
|
|
-- canplaythrough
|
|
|
-- durationchange
|
|
|
-- emptied
|
|
|
-- ended
|
|
|
-- error
|
|
|
-- loadeddata
|
|
|
-- loadedmetadata
|
|
|
-- loadstart
|
|
|
-- mozaudioavailable
|
|
|
-- pause
|
|
|
-- play
|
|
|
-- playing
|
|
|
-- progress
|
|
|
-- ratechange
|
|
|
-- seeked
|
|
|
-- seeking
|
|
|
-- stalled
|
|
|
-- suspend
|
|
|
-- timeupdate
|
|
|
-- volumechange
|
|
|
-- waiting
|
|
|
+- abort
|
|
|
+- canplay
|
|
|
+- canplaythrough
|
|
|
+- durationchange
|
|
|
+- emptied
|
|
|
+- ended
|
|
|
+- error
|
|
|
+- loadeddata
|
|
|
+- loadedmetadata
|
|
|
+- loadstart
|
|
|
+- mozaudioavailable
|
|
|
+- pause
|
|
|
+- play
|
|
|
+- playing
|
|
|
+- progress
|
|
|
+- ratechange
|
|
|
+- seeked
|
|
|
+- seeking
|
|
|
+- stalled
|
|
|
+- suspend
|
|
|
+- timeupdate
|
|
|
+- volumechange
|
|
|
+- waiting
|
|
|
|
|
|
Player events
|
|
|
|
|
|
-- screenshot
|
|
|
-- thumbnails_show
|
|
|
-- thumbnails_hide
|
|
|
-- danmaku_show
|
|
|
-- danmaku_hide
|
|
|
-- danmaku_clear
|
|
|
-- danmaku_loaded
|
|
|
-- danmaku_send
|
|
|
-- danmaku_opacity
|
|
|
-- contextmenu_show
|
|
|
-- contextmenu_hide
|
|
|
-- notice_show
|
|
|
-- notice_hide
|
|
|
-- quality_start
|
|
|
-- quality_end
|
|
|
-- destroy
|
|
|
-- resize
|
|
|
-- fullscreen
|
|
|
-- fullscreen_cancel
|
|
|
-- webfullscreen
|
|
|
-- webfullscreen_cancel
|
|
|
-- subtitle_show
|
|
|
-- subtitle_hide
|
|
|
-- subtitle_change
|
|
|
+- screenshot
|
|
|
+- thumbnails_show
|
|
|
+- thumbnails_hide
|
|
|
+- danmaku_show
|
|
|
+- danmaku_hide
|
|
|
+- danmaku_clear
|
|
|
+- danmaku_loaded
|
|
|
+- danmaku_send
|
|
|
+- danmaku_opacity
|
|
|
+- contextmenu_show
|
|
|
+- contextmenu_hide
|
|
|
+- notice_show
|
|
|
+- notice_hide
|
|
|
+- quality_start
|
|
|
+- quality_end
|
|
|
+- destroy
|
|
|
+- resize
|
|
|
+- fullscreen
|
|
|
+- fullscreen_cancel
|
|
|
+- webfullscreen
|
|
|
+- webfullscreen_cancel
|
|
|
+- subtitle_show
|
|
|
+- subtitle_hide
|
|
|
+- subtitle_change
|
|
|
|
|
|
## Quality switching
|
|
|
|
|
@@ -405,19 +412,22 @@ Set video url and video type in `video.quality`, set default quality by `video.d
|
|
|
const dp = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
|
- quality: [{
|
|
|
- name: 'HD',
|
|
|
- url: 'demo.m3u8',
|
|
|
- type: 'hls'
|
|
|
- }, {
|
|
|
- name: 'SD',
|
|
|
- url: 'demo.mp4',
|
|
|
- type: 'normal'
|
|
|
- }],
|
|
|
+ quality: [
|
|
|
+ {
|
|
|
+ name: 'HD',
|
|
|
+ url: 'demo.m3u8',
|
|
|
+ type: 'hls',
|
|
|
+ },
|
|
|
+ {
|
|
|
+ name: 'SD',
|
|
|
+ url: 'demo.mp4',
|
|
|
+ type: 'normal',
|
|
|
+ },
|
|
|
+ ],
|
|
|
defaultQuality: 0,
|
|
|
pic: 'demo.png',
|
|
|
thumbnails: 'thumbnails.jpg',
|
|
|
- }
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -447,9 +457,9 @@ API: <https://api.prprpr.me/dplayer/v3/bilibili?aid=[aid]>
|
|
|
const option = {
|
|
|
danmaku: {
|
|
|
// ...
|
|
|
- addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=[aid]']
|
|
|
- }
|
|
|
-}
|
|
|
+ addition: ['https://api.prprpr.me/dplayer/v3/bilibili?aid=[aid]'],
|
|
|
+ },
|
|
|
+};
|
|
|
```
|
|
|
|
|
|
## MSE support
|
|
@@ -466,7 +476,7 @@ It requires the library [hls.js](https://github.com/video-dev/hls.js) and it sho
|
|
|
}"></DPlayer>
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="hls.min.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -477,8 +487,8 @@ const dp = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
|
url: 'demo.m3u8',
|
|
|
- type: 'hls'
|
|
|
- }
|
|
|
+ type: 'hls',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -490,13 +500,13 @@ const dp = new DPlayer({
|
|
|
url: 'demo.m3u8',
|
|
|
type: 'customHls',
|
|
|
customType: {
|
|
|
- 'customHls': function (video, player) {
|
|
|
+ customHls: function(video, player) {
|
|
|
const hls = new Hls();
|
|
|
hls.loadSource(video.src);
|
|
|
hls.attachMedia(video);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -505,7 +515,7 @@ const dp = new DPlayer({
|
|
|
It requires the library [dash.js](https://github.com/Dash-Industry-Forum/dash.js) and it should be loaded before `DPlayer.min.js`.
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="dash.min.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -516,8 +526,8 @@ const dp = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
|
url: 'demo.mpd',
|
|
|
- type: 'dash'
|
|
|
- }
|
|
|
+ type: 'dash',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -529,11 +539,14 @@ const dp = new DPlayer({
|
|
|
url: 'demo.mpd',
|
|
|
type: 'customDash',
|
|
|
customType: {
|
|
|
- 'customDash': function (video, player) {
|
|
|
- dashjs.MediaPlayer().create().initialize(video, video.src, false);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ customDash: function(video, player) {
|
|
|
+ dashjs
|
|
|
+ .MediaPlayer()
|
|
|
+ .create()
|
|
|
+ .initialize(video, video.src, false);
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -542,7 +555,7 @@ const dp = new DPlayer({
|
|
|
It requires the library [shaka-player](https://github.com/google/shaka-player) and it should be loaded before `DPlayer.min.js`.
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="shaka-player.compiled.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -556,13 +569,13 @@ const dp = new DPlayer({
|
|
|
url: 'demo.mpd',
|
|
|
type: 'shakaDash',
|
|
|
customType: {
|
|
|
- 'shakaDash': function (video, player) {
|
|
|
+ shakaDash: function(video, player) {
|
|
|
var src = video.src;
|
|
|
var playerShaka = new shaka.Player(video); // 将会修改 video.src
|
|
|
playerShaka.load(src);
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -578,7 +591,7 @@ It requires the library [flv.js](https://github.com/Bilibili/flv.js) and it shou
|
|
|
}"></DPlayer>
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="flv.min.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -589,8 +602,8 @@ const dp = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
|
url: 'demo.flv',
|
|
|
- type: 'flv'
|
|
|
- }
|
|
|
+ type: 'flv',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -602,16 +615,16 @@ const dp = new DPlayer({
|
|
|
url: 'demo.flv',
|
|
|
type: 'customFlv',
|
|
|
customType: {
|
|
|
- 'customFlv': function (video, player) {
|
|
|
+ customFlv: function(video, player) {
|
|
|
const flvPlayer = flvjs.createPlayer({
|
|
|
type: 'flv',
|
|
|
- url: video.src
|
|
|
+ url: video.src,
|
|
|
});
|
|
|
flvPlayer.attachMediaElement(video);
|
|
|
flvPlayer.load();
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -627,7 +640,7 @@ It requires the library [webtorrent](https://github.com/webtorrent/webtorrent) a
|
|
|
}"></DPlayer>
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="webtorrent.min.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -638,8 +651,8 @@ const dp = new DPlayer({
|
|
|
container: document.getElementById('dplayer'),
|
|
|
video: {
|
|
|
url: 'magnet:demo',
|
|
|
- type: 'webtorrent'
|
|
|
- }
|
|
|
+ type: 'webtorrent',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -651,21 +664,25 @@ const dp = new DPlayer({
|
|
|
url: 'magnet:demo',
|
|
|
type: 'customWebTorrent',
|
|
|
customType: {
|
|
|
- 'customWebTorrent': function (video, player) {
|
|
|
+ customWebTorrent: function(video, player) {
|
|
|
player.container.classList.add('dplayer-loading');
|
|
|
const client = new WebTorrent();
|
|
|
const torrentId = video.src;
|
|
|
client.add(torrentId, (torrent) => {
|
|
|
const file = torrent.files.find((file) => file.name.endsWith('.mp4'));
|
|
|
- file.renderTo(video, {
|
|
|
- autoplay: player.options.autoplay
|
|
|
- }, () => {
|
|
|
- player.container.classList.remove('dplayer-loading');
|
|
|
- });
|
|
|
+ file.renderTo(
|
|
|
+ video,
|
|
|
+ {
|
|
|
+ autoplay: player.options.autoplay,
|
|
|
+ },
|
|
|
+ () => {
|
|
|
+ player.container.classList.remove('dplayer-loading');
|
|
|
+ }
|
|
|
+ );
|
|
|
});
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -674,7 +691,7 @@ const dp = new DPlayer({
|
|
|
DPlayer can work with any MSE library via `customType` option.
|
|
|
|
|
|
```html
|
|
|
-<link rel="stylesheet" href="DPlayer.min.css">
|
|
|
+<link rel="stylesheet" href="DPlayer.min.css" />
|
|
|
<div id="dplayer"></div>
|
|
|
<script src="pearplayer.js"></script>
|
|
|
<script src="DPlayer.min.js"></script>
|
|
@@ -687,14 +704,14 @@ const dp = new DPlayer({
|
|
|
url: 'https://qq.webrtc.win/tv/Pear-Demo-Yosemite_National_Park.mp4',
|
|
|
type: 'pearplayer',
|
|
|
customType: {
|
|
|
- 'pearplayer': function (video, player) {
|
|
|
+ pearplayer: function(video, player) {
|
|
|
new PearPlayer(video, {
|
|
|
src: video.src,
|
|
|
- autoplay: player.options.autoplay
|
|
|
+ autoplay: player.options.autoplay,
|
|
|
});
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
+ },
|
|
|
+ },
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -718,19 +735,19 @@ const dp = new DPlayer({
|
|
|
live: true,
|
|
|
danmaku: true,
|
|
|
apiBackend: {
|
|
|
- read: function (options) {
|
|
|
+ read: function(options) {
|
|
|
console.log('Pretend to connect WebSocket');
|
|
|
callback();
|
|
|
},
|
|
|
- send: function (options) {
|
|
|
+ send: function(options) {
|
|
|
console.log('Pretend to send danamku via WebSocket', options.data);
|
|
|
callback();
|
|
|
- }
|
|
|
+ },
|
|
|
},
|
|
|
video: {
|
|
|
url: 'demo.m3u8',
|
|
|
- type: 'hls'
|
|
|
- }
|
|
|
+ type: 'hls',
|
|
|
+ },
|
|
|
});
|
|
|
```
|
|
|
|
|
@@ -740,7 +757,7 @@ Draw danmaku after getting a danmaku via WebSocket:
|
|
|
const danmaku = {
|
|
|
text: 'Get a danamku via WebSocket',
|
|
|
color: '#fff',
|
|
|
- type: 'right'
|
|
|
+ type: 'right',
|
|
|
};
|
|
|
dp.danmaku.draw(danmaku);
|
|
|
```
|
|
@@ -754,12 +771,7 @@ If player is contained in a iframe, try adding the `allowfullscreen` attribute t
|
|
|
For full browser support it should look like this:
|
|
|
|
|
|
```html
|
|
|
-<iframe src="example.com"
|
|
|
- allowfullscreen="allowfullscreen"
|
|
|
- mozallowfullscreen="mozallowfullscreen"
|
|
|
- msallowfullscreen="msallowfullscreen"
|
|
|
- oallowfullscreen="oallowfullscreen"
|
|
|
- webkitallowfullscreen="webkitallowfullscreen"></iframe>
|
|
|
+<iframe src="example.com" allowfullscreen="allowfullscreen" mozallowfullscreen="mozallowfullscreen" msallowfullscreen="msallowfullscreen" oallowfullscreen="oallowfullscreen" webkitallowfullscreen="webkitallowfullscreen"></iframe>
|
|
|
```
|
|
|
|
|
|
### Why can't player autoplay in some mobile browsers?
|