Skip to content

Commit

Permalink
feat(ui): Add Loop, PIP, Cast, AirPlay buttons to control panel (shak…
Browse files Browse the repository at this point in the history
…a-project#3255)

These menu items are now available to be placed in the control panel of the UI.

Issue shaka-project#2676
  • Loading branch information
nbcl committed Mar 30, 2021
1 parent 198a6d4 commit 4f0ded7
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 1 deletion.
7 changes: 7 additions & 0 deletions docs/tutorials/ui-customization.md
Expand Up @@ -60,6 +60,13 @@ The following elements can be added to the UI bar using this configuration value
* fast_forward: adds a button that fast forwards the presentation on click; that is, it
starts playing the presentation at an increased speed
* spacer: adds a chunk of empty space between the adjacent elements.
* picture_in_picture: adds a button that enables/disables picture-in-picture mode on browsers
that support it. Button is invisible on other browsers.
* loop: adds a button that controls if the currently selected video is played in a loop.
* airplay: adds a button that opens a AirPlay dialog. The button is visible only if the browser
supports AirPlay.
* cast: adds a button that opens a Chromecast dialog. The button is visible only if there is
at least one Chromecast device on the same network available for casting.
<!-- TODO: If we add more buttons that can be put in the order this way, list them here. -->

Similarly, the 'overflowMenuButtons' configuration option can be used to control
Expand Down
5 changes: 5 additions & 0 deletions ui/airplay_button.js
Expand Up @@ -10,6 +10,7 @@ goog.provide('shaka.ui.AirPlayButton');
goog.require('goog.asserts');
goog.require('shaka.Player');
goog.require('shaka.ui.Constants');
goog.require('shaka.ui.Controls');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Locales');
Expand Down Expand Up @@ -46,6 +47,7 @@ shaka.ui.AirPlayButton = class extends shaka.ui.Element {

const label = shaka.util.Dom.createHTMLElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
this.airplayNameSpan_ = shaka.util.Dom.createHTMLElement('span');
label.appendChild(this.airplayNameSpan_);

Expand Down Expand Up @@ -157,3 +159,6 @@ shaka.ui.AirPlayButton.Factory = class {

shaka.ui.OverflowMenu.registerElement(
'airplay', new shaka.ui.AirPlayButton.Factory());

shaka.ui.Controls.registerElement(
'airplay', new shaka.ui.AirPlayButton.Factory());
5 changes: 5 additions & 0 deletions ui/cast_button.js
Expand Up @@ -9,6 +9,7 @@ goog.provide('shaka.ui.CastButton');

goog.require('shaka.cast.CastProxy');
goog.require('shaka.ui.Constants');
goog.require('shaka.ui.Controls');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Locales');
Expand Down Expand Up @@ -51,6 +52,7 @@ shaka.ui.CastButton = class extends shaka.ui.Element {

const label = shaka.util.Dom.createHTMLElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
this.castNameSpan_ = shaka.util.Dom.createHTMLElement('span');
label.appendChild(this.castNameSpan_);

Expand Down Expand Up @@ -179,3 +181,6 @@ shaka.ui.CastButton.Factory = class {

shaka.ui.OverflowMenu.registerElement(
'cast', new shaka.ui.CastButton.Factory());

shaka.ui.Controls.registerElement(
'cast', new shaka.ui.CastButton.Factory());
3 changes: 2 additions & 1 deletion ui/enums.js
Expand Up @@ -36,7 +36,8 @@ shaka.ui.Enums.MaterialDesignIcons = {
'PLAY': 'play_arrow',
'PLAYBACK_RATE': 'slow_motion_video',
'PAUSE': 'pause',
'LOOP': 'loop',
'LOOP': 'repeat',
'UNLOOP': 'repeat_on',
'AIRPLAY': 'airplay',
'REPLAY': 'replay',
};
5 changes: 5 additions & 0 deletions ui/less/containers.less
Expand Up @@ -170,6 +170,11 @@
}
}

/* Buttons hide certain items if they are found inside the control panel */
.shaka-controls-button-panel .shaka-overflow-menu-only {
display: none;
}

/* The container for the giant play button. Sits above (Y axis) the
* other video controls and seek bar, in the middle of the video frame, on top
* of (Z axis) the video. */
Expand Down
10 changes: 10 additions & 0 deletions ui/loop_button.js
Expand Up @@ -8,6 +8,7 @@
goog.provide('shaka.ui.LoopButton');

goog.require('shaka.ui.Constants');
goog.require('shaka.ui.Controls');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Locales');
Expand Down Expand Up @@ -44,6 +45,7 @@ shaka.ui.LoopButton = class extends shaka.ui.Element {

const label = shaka.util.Dom.createHTMLElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
this.nameSpan_ = shaka.util.Dom.createHTMLElement('span');
this.nameSpan_.textContent = this.localization.resolve(LocIds.LOOP);
label.appendChild(this.nameSpan_);
Expand Down Expand Up @@ -133,6 +135,7 @@ shaka.ui.LoopButton = class extends shaka.ui.Element {
*/
updateLocalizedStrings_() {
const LocIds = shaka.ui.Locales.Ids;
const Icons = shaka.ui.Enums.MaterialDesignIcons;

this.nameSpan_.textContent =
this.localization.resolve(LocIds.LOOP);
Expand All @@ -141,6 +144,10 @@ shaka.ui.LoopButton = class extends shaka.ui.Element {

this.currentState_.textContent = this.localization.resolve(labelText);

const icon = this.video.loop ? Icons.UNLOOP : Icons.LOOP;

this.icon_.textContent = icon;

const ariaText = this.video.loop ?
LocIds.EXIT_LOOP_MODE : LocIds.ENTER_LOOP_MODE;

Expand All @@ -163,3 +170,6 @@ shaka.ui.LoopButton.Factory = class {

shaka.ui.OverflowMenu.registerElement(
'loop', new shaka.ui.LoopButton.Factory());

shaka.ui.Controls.registerElement(
'loop', new shaka.ui.LoopButton.Factory());
5 changes: 5 additions & 0 deletions ui/pip_button.js
Expand Up @@ -8,6 +8,7 @@
goog.provide('shaka.ui.PipButton');

goog.require('shaka.ui.Constants');
goog.require('shaka.ui.Controls');
goog.require('shaka.ui.Element');
goog.require('shaka.ui.Enums');
goog.require('shaka.ui.Locales');
Expand Down Expand Up @@ -48,6 +49,7 @@ shaka.ui.PipButton = class extends shaka.ui.Element {

const label = shaka.util.Dom.createHTMLElement('label');
label.classList.add('shaka-overflow-button-label');
label.classList.add('shaka-overflow-menu-only');
this.pipNameSpan_ = shaka.util.Dom.createHTMLElement('span');
this.pipNameSpan_.textContent =
this.localization.resolve(LocIds.PICTURE_IN_PICTURE);
Expand Down Expand Up @@ -235,3 +237,6 @@ shaka.ui.PipButton.Factory = class {

shaka.ui.OverflowMenu.registerElement(
'picture_in_picture', new shaka.ui.PipButton.Factory());

shaka.ui.Controls.registerElement(
'picture_in_picture', new shaka.ui.PipButton.Factory());

0 comments on commit 4f0ded7

Please sign in to comment.