diff --git a/demo/index.html b/demo/index.html index 1214d38..f352dd5 100644 --- a/demo/index.html +++ b/demo/index.html @@ -20,7 +20,10 @@ video: { url: 'http://devtest.qiniudn.com/若能绽放光芒.mp4', pic: 'http://devtest.qiniudn.com/若能绽放光芒.png', - thumbnails: 'http://devtest.qiniudn.com/thumbnails.jpg' + thumbnails: 'http://devtest.qiniudn.com/thumbnails.jpg', + }, + subtitle: { + url: 'http://devtest.qiniudn.com/若能绽放光芒2.vtt' }, danmaku: { id: '9E2E3368B56CDBB4', @@ -58,6 +61,13 @@ type: 'auto', thumbnails: 'http://devtest.qiniudn.com/thumbnails.jpg' }, + subtitle: { + url: 'http://devtest.qiniudn.com/若能绽放光芒2.vtt', + type: 'webvtt', + fontSize: '25px', + bottom: '10%', + color: '#b7daff' + }, danmaku: { id: '9E2E3368B56CDBB4', api: 'https://api.prprpr.me/dplayer/', diff --git a/package.json b/package.json index f6a6049..f7b83aa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "dplayer", - "version": "1.11.0", + "version": "1.12.0", "description": "Wow, such a lovely HTML5 danmaku video player", "main": "dist/DPlayer.min.js", "style": "dist/DPlayer.min.css", diff --git a/src/DPlayer.js b/src/DPlayer.js index c5b2e04..23eac11 100644 --- a/src/DPlayer.js +++ b/src/DPlayer.js @@ -10,6 +10,7 @@ import Thumbnails from './thumbnails'; import Events from './events'; import FullScreen from './fullscreen'; import User from './user'; +import Subtitle from './subtitle'; let index = 0; @@ -996,6 +997,10 @@ class DPlayer { } this.volume(this.user.get('volume'), true); + + if (this.options.subtitle) { + this.subtitle = new Subtitle(this.container.getElementsByClassName('dplayer-subtitle')[0], this.video, this.options.subtitle); + } } switchQuality (index) { @@ -1011,7 +1016,7 @@ class DPlayer { const paused = this.video.paused; this.video.pause(); - const videoHTML = html.video(false, null, this.options.screenshot, 'auto', this.quality.url); + const videoHTML = html.video(false, null, this.options.screenshot, 'auto', this.quality.url, this.options.subtitle); const videoEle = new DOMParser().parseFromString(videoHTML, 'text/html').body.firstChild; const parent = this.container.getElementsByClassName('dplayer-video-wrap')[0]; parent.insertBefore(videoEle, parent.getElementsByTagName('div')[0]); diff --git a/src/DPlayer.scss b/src/DPlayer.scss index 5676b4f..a88e504 100644 --- a/src/DPlayer.scss +++ b/src/DPlayer.scss @@ -247,6 +247,17 @@ } } + .dplayer-subtitle { + position: absolute; + bottom: 40px; + width: 90%; + left: 5%; + text-align: center; + color: #fff; + text-shadow: 0.5px 0.5px 0.5px rgba(0, 0, 0, 0.5); + font-size: 20px; + } + .dplayer-bezel { position: absolute; left: 0; diff --git a/src/html.js b/src/html.js index 87559e3..a1a74fd 100644 --- a/src/html.js +++ b/src/html.js @@ -1,19 +1,17 @@ const svg = require('./svg.js'); const html = { - main: (options, index, tran) => { - let videos = ``; - videos += html.video(true, options.video.pic, options.screenshot, options.preload, options.video.url); - return ` + main: (options, index, tran) => `