-
Notifications
You must be signed in to change notification settings - Fork 7.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Combine captions and subtitles tracks control (#4028)
- Loading branch information
1 parent
f95815b
commit 74eb5d4
Showing
10 changed files
with
289 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
<!DOCTYPE html> | ||
<html lang="en-GB"> | ||
<head> | ||
<meta charset="utf-8" /> | ||
<title>Video.js Sandbox</title> | ||
|
||
<!-- Add ES5 shim and sham for IE8 --> | ||
<script src="../build/temp/ie8/videojs-ie8.js"></script> | ||
|
||
<!-- Load the source files --> | ||
<link href="../build/temp/video-js.css" rel="stylesheet" type="text/css"> | ||
<script src="../build/temp/video.js"></script> | ||
<script src="../node_modules/videojs-flash/dist/videojs-flash.js"></script> | ||
|
||
<!-- Set the location of the flash SWF --> | ||
<script> | ||
videojs.options.flash.swf = '../build/temp/video-js.swf'; | ||
</script> | ||
</head> | ||
<body> | ||
<div style="background-color:#eee; border: 1px solid #777; padding: 10px; margin-bottom: 20px; font-size: .8em; line-height: 1.5em; font-family: Verdana, sans-serif;"> | ||
<p>You can use /sandbox/ for writing and testing your own code. Nothing in /sandbox/ will get checked into the repo, except files that end in .example (so don't edit or add those files). To get started make a copy of index.html.example and rename it to index.html.</p> | ||
<pre>cp sandbox/index.html.example sandbox/index.html</pre> | ||
<pre>npm run start</pre> | ||
<pre>open http://localhost:9999/sandbox/index.html</pre> | ||
</div> | ||
|
||
<video id="vid1" class="video-js vjs-default-skin" lang="en" controls preload="auto" width="640" height="264" poster="http://vjs.zencdn.net/v/oceans.png"> | ||
<source src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/ed_hd.mp4" type="video/mp4"> | ||
<source src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/ed_hd.ogg" type="video/ogg"> | ||
<track kind="captions" src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/captions.en.vtt" srclang="en" label="English"></track><!-- Tracks need an ending tag thanks to IE9 --> | ||
<track kind="subtitles" src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/captions.ar.vtt" srclang="ar" label="Arabic"></track><!-- Tracks need an ending tag thanks to IE9 --> | ||
<track kind="subtitles" src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/captions.sv.vtt" srclang="sv" label="Swedish"></track><!-- Tracks need an ending tag thanks to IE9 --> | ||
<track kind="subtitles" src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/captions.ru.vtt" srclang="ru" label="Russian"></track><!-- Tracks need an ending tag thanks to IE9 --> | ||
<track kind="subtitles" src="//d2zihajmogu5jn.cloudfront.net/elephantsdream/captions.ja.vtt" srclang="ja" label="Japanese"></track><!-- Tracks need an ending tag thanks to IE9 --> | ||
<p class="vjs-no-js">To view this video please enable JavaScript, and consider upgrading to a web browser that <a href="http://videojs.com/html5-video-support/" target="_blank">supports HTML5 video</a></p> | ||
</video> | ||
<p>This player has the captions-only CpationsButton, the subtiles-only subtitlesButton and the subsCapsButton which shows both kinds. Typically you'll use either just the subsCapsButton alone, or one or both of the captionsButton and subtitlesButton.</p> | ||
<script> | ||
var vid = document.getElementById("vid1"); | ||
var player = videojs(vid, { | ||
controlBar: { | ||
children: [ | ||
'playToggle', | ||
'volumePanel', | ||
'currentTimeDisplay', | ||
'timeDivider', | ||
'durationDisplay', | ||
'progressControl', | ||
'liveDisplay', | ||
'remainingTimeDisplay', | ||
'customControlSpacer', | ||
'playbackRateMenuButton', | ||
'chaptersButton', | ||
'descriptionsButton', | ||
'subtitlesButton', | ||
'captionsButton', | ||
'subsCapsButton', | ||
'audioTrackButton', | ||
'fullscreenToggle' | ||
] | ||
} | ||
}); | ||
console.log(player.language()); | ||
</script> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
// North America uses 'CC' icon | ||
.video-js:lang(en) .vjs-subs-caps-button .vjs-icon-placeholder, | ||
.video-js:lang(fr-CA) .vjs-subs-caps-button .vjs-icon-placeholder { | ||
@extend .vjs-icon-captions; | ||
} | ||
|
||
// ROW uses 'subtitles' | ||
// Double selector because @extend puts these rules above the captions icon | ||
.video-js .vjs-subs-caps-button .vjs-icon-placeholder, | ||
.video-js.video-js:lang(en-GB) .vjs-subs-caps-button .vjs-icon-placeholder, | ||
.video-js.video-js:lang(en-IE) .vjs-subs-caps-button .vjs-icon-placeholder, | ||
.video-js.video-js:lang(en-AU) .vjs-subs-caps-button .vjs-icon-placeholder, | ||
.video-js.video-js:lang(en-NZ) .vjs-subs-caps-button .vjs-icon-placeholder { | ||
@extend .vjs-icon-subtitles; | ||
} | ||
|
||
.video-js .vjs-subs-caps-button + .vjs-menu .vjs-captions-menu-item .vjs-menu-item-text:after { | ||
content: " \f10d"; | ||
font-family: VideoJS; | ||
vertical-align: bottom; | ||
font-size: 1.5em; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
102 changes: 102 additions & 0 deletions
102
src/js/control-bar/text-track-controls/subs-caps-button.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/** | ||
* @file sub-caps-button.js | ||
*/ | ||
import TextTrackButton from './text-track-button.js'; | ||
import Component from '../../component.js'; | ||
import CaptionSettingsMenuItem from './caption-settings-menu-item.js'; | ||
import toTitleCase from '../../utils/to-title-case.js'; | ||
/** | ||
* The button component for toggling and selecting captions and/or subtitles | ||
* | ||
* @extends TextTrackButton | ||
*/ | ||
class SubsCapsButton extends TextTrackButton { | ||
|
||
constructor(player, options = {}) { | ||
super(player, options); | ||
|
||
// Although North America uses "captions" in most cases for | ||
// "captions and subtitles" other locales use "subtitles" | ||
this.label_ = 'subtitles'; | ||
if (['en', 'en-us', 'en-ca', 'fr-ca'].indexOf(this.player_.language_) > -1) { | ||
this.label_ = 'captions'; | ||
} | ||
this.menuButton_.controlText(toTitleCase(this.label_)); | ||
|
||
} | ||
|
||
/** | ||
* Builds the default DOM `className`. | ||
* | ||
* @return {string} | ||
* The DOM `className` for this object. | ||
*/ | ||
buildCSSClass() { | ||
return `vjs-subs-caps-button ${super.buildCSSClass()}`; | ||
} | ||
|
||
/** | ||
* Update caption menu items | ||
* | ||
* @param {EventTarget~Event} [event] | ||
* The `addtrack` or `removetrack` event that caused this function to be | ||
* called. | ||
* | ||
* @listens TextTrackList#addtrack | ||
* @listens TextTrackList#removetrack | ||
*/ | ||
update(event) { | ||
let threshold = 2; | ||
|
||
super.update(); | ||
|
||
// if native, then threshold is 1 because no settings button | ||
if (this.player().tech_ && this.player().tech_.featuresNativeTextTracks) { | ||
threshold = 1; | ||
} | ||
|
||
if (this.items && this.items.length > threshold) { | ||
this.show(); | ||
} else { | ||
this.hide(); | ||
} | ||
} | ||
|
||
/** | ||
* Create caption/subtitles menu items | ||
* | ||
* @return {CaptionSettingsMenuItem[]} | ||
* The array of current menu items. | ||
*/ | ||
createItems() { | ||
let items = []; | ||
|
||
if (!(this.player().tech_ && this.player().tech_.featuresNativeTextTracks)) { | ||
items.push(new CaptionSettingsMenuItem(this.player_, {kind: this.label_})); | ||
} | ||
|
||
items = super.createItems(items); | ||
return items; | ||
} | ||
|
||
} | ||
|
||
/** | ||
* `kind`s of TextTrack to look for to associate it with this menu. | ||
* | ||
* @type {array} | ||
* @private | ||
*/ | ||
SubsCapsButton.prototype.kinds_ = ['captions', 'subtitles']; | ||
|
||
/** | ||
* The text that should display over the `SubsCapsButton`s controls. | ||
* | ||
* | ||
* @type {string} | ||
* @private | ||
*/ | ||
SubsCapsButton.prototype.controlText_ = 'Subtitles'; | ||
|
||
Component.registerComponent('SubsCapsButton', SubsCapsButton); | ||
export default SubsCapsButton; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.