-
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: add built-in Picture-in-Picture button (#6002)
Adds a new PictureInPictureToggle component in the controls bar of the player. It depends on videojs-font 3.2.0 (videojs/font#41) for icons. Final spec piece from #5824.
- Loading branch information
1 parent
204ff46
commit 116d84a
Showing
10 changed files
with
132 additions
and
4 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
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
.video-js .vjs-picture-in-picture-control { | ||
cursor: pointer; | ||
@include flex(none); | ||
|
||
& .vjs-icon-placeholder { | ||
@extend .vjs-icon-picture-in-picture-enter; | ||
} | ||
} | ||
// Switch to the exit icon when the player is in Picture-in-Picture | ||
.video-js.vjs-picture-in-picture .vjs-picture-in-picture-control .vjs-icon-placeholder { | ||
@extend .vjs-icon-picture-in-picture-exit; | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
/** | ||
* @file picture-in-picture-toggle.js | ||
*/ | ||
import Button from '../button.js'; | ||
import Component from '../component.js'; | ||
import document from 'global/document'; | ||
|
||
/** | ||
* Toggle Picture-in-Picture mode | ||
* | ||
* @extends Button | ||
*/ | ||
class PictureInPictureToggle extends Button { | ||
|
||
/** | ||
* Creates an instance of this class. | ||
* | ||
* @param {Player} player | ||
* The `Player` that this class should be attached to. | ||
* | ||
* @param {Object} [options] | ||
* The key/value store of player options. | ||
*/ | ||
constructor(player, options) { | ||
super(player, options); | ||
this.on(player, 'pictureinpicturechange', this.handlePictureInPictureChange); | ||
|
||
// TODO: Activate button on player loadedmetadata event. | ||
// TODO: Deactivate button on player emptied event. | ||
// TODO: Deactivate button if disablepictureinpicture attribute is present. | ||
if (!document.pictureInPictureEnabled) { | ||
this.disable(); | ||
} | ||
} | ||
|
||
/** | ||
* Builds the default DOM `className`. | ||
* | ||
* @return {string} | ||
* The DOM `className` for this object. | ||
*/ | ||
buildCSSClass() { | ||
return `vjs-picture-in-picture-control ${super.buildCSSClass()}`; | ||
} | ||
|
||
/** | ||
* Handles pictureinpicturechange on the player and change control text accordingly. | ||
* | ||
* @param {EventTarget~Event} [event] | ||
* The {@link Player#pictureinpicturechange} event that caused this function to be | ||
* called. | ||
* | ||
* @listens Player#pictureinpicturechange | ||
*/ | ||
handlePictureInPictureChange(event) { | ||
if (this.player_.isInPictureInPicture()) { | ||
this.controlText('Exit Picture-in-Picture'); | ||
} else { | ||
this.controlText('Picture-in-Picture'); | ||
} | ||
} | ||
|
||
/** | ||
* This gets called when an `PictureInPictureToggle` is "clicked". See | ||
* {@link ClickableComponent} for more detailed information on what a click can be. | ||
* | ||
* @param {EventTarget~Event} [event] | ||
* The `keydown`, `tap`, or `click` event that caused this function to be | ||
* called. | ||
* | ||
* @listens tap | ||
* @listens click | ||
*/ | ||
handleClick(event) { | ||
if (!this.player_.isInPictureInPicture()) { | ||
this.player_.requestPictureInPicture(); | ||
} else { | ||
this.player_.exitPictureInPicture(); | ||
} | ||
} | ||
|
||
} | ||
|
||
/** | ||
* The text that should display over the `PictureInPictureToggle`s controls. Added for localization. | ||
* | ||
* @type {string} | ||
* @private | ||
*/ | ||
PictureInPictureToggle.prototype.controlText_ = 'Picture-in-Picture'; | ||
|
||
Component.registerComponent('PictureInPictureToggle', PictureInPictureToggle); | ||
export default PictureInPictureToggle; |
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