Skip to content

Commit 3ee1916

Browse files
authored
feat: Add enablePictureInPicture option (#168)
* feat: Add enablePictureInPicture option * add disablePictureInPicture option too * origin trial note * typo * Enable docPiP * fix weird padding * update deps * version note * versions in options guide * typos
1 parent 5f2e65a commit 3ee1916

File tree

8 files changed

+275
-126
lines changed

8 files changed

+275
-126
lines changed

package-lock.json

Lines changed: 176 additions & 121 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,10 @@
4343
"shortid": "^2.2.14",
4444
"styled-components": "^5.3.5",
4545
"typescript": "^2.9.2",
46-
"video.js": "^7.20.1",
46+
"video.js": "^8.3.0",
4747
"videojs-mux": "^4.6.6",
48-
"videojs-playlist": "^4.3.1",
49-
"videojs-playlist-ui": "^4.1.0"
48+
"videojs-playlist": "^5.1.0",
49+
"videojs-playlist-ui": "^4.2.0"
5050
},
5151
"devDependencies": {
5252
"bluebird": "^3.7.2",

src/components/HomeComponents/AdvancedExample/PlayerPlaylist.jsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ const PlaylistWrapper = styled.div`
9090

9191
const Playlist = () => (
9292
<PlaylistWrapper>
93-
<div className="vjs-playlist vjs-fluid" />
93+
<div className="vjs-playlist" />
9494
</PlaylistWrapper>
9595
);
9696

src/components/HomeComponents/AdvancedExample/index.jsx

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,10 @@ class AdvancedExample extends React.Component {
115115
}
116116

117117
componentDidMount() {
118-
this.player = videojs(this.videoEl, {}, () => {
118+
this.player = videojs(this.videoEl, {
119+
aspectRatio: '21:9',
120+
enableDocumentPictureInPicture: true
121+
}, () => {
119122
if (this.player.hasPlugin('mux')) {
120123
this.player.mux({
121124
data: {

src/components/HomeComponents/Hero.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ const HomeHero = props => (
115115
{ src: props.heroTheme.video, type: 'application/x-mpegurl' },
116116
]}
117117
poster={props.heroTheme.poster}
118+
enableDocumentPictureInPicture='true'
118119
onPlay={props.onPlay}
119120
playsInline
120121
/>

src/mdx-pages/guides/options.mdx

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,28 @@ See the file `sandbox/responsive.html.example` for an example of a responsive pl
193193
194194
This option is inherited from the [`Component` base class](#component-options).
195195

196+
### `disablePictureInPicture`
197+
198+
> Type: `boolean`
199+
200+
If `true`, switching the video element into picture-in-picture is disabled. Default is `false`.
201+
202+
This has no effect on Firefox, which implements a proprietary picture-in-picture mode which does not implement the standard picture-in-picture API.
203+
204+
This does not disable the document picture-in-picture mode which allows the player element to put into a PiP window.
205+
206+
### `enableDocumentPictureInPicture`
207+
208+
> Type: `boolean`
209+
210+
_Since 8.3.0_
211+
212+
If `true`, the [documentPictureInPicture API](https://developer.chrome.com/docs/web-platform/document-picture-in-picture/) will be used for picture-in-picture, if available. Defaults to `false`, but may default to `true` when the feature has become established.
213+
214+
Currently this is available in Chrome 111+ as an origin trial.
215+
216+
This is a different picture-in-picture mode than has previously been available, where the entire player element is windowed rather than just the video itself. Since there are scenarios where it would be desirable to allow PiP on the player but not PiP on the video alone (such as ads, overlays), the `disablePictureInPicture` option **only** disables the old-style picture-in-picture mode on the video.
217+
196218
### `fluid`
197219

198220
> Type: `boolean`
@@ -373,10 +395,14 @@ If set to an HTML Element, that element would replace the disposed player instea
373395

374396
> Type: `Object`
375397
398+
_Since 8.2.0_
399+
376400
### `skipButtons.forward`
377401

378402
> Type: `number`
379403
404+
_Since 8.2.0_
405+
380406
If specified, Video.js displays a control allowing the
381407
user to jump forward in a video by the specified number of seconds.
382408

@@ -396,6 +422,8 @@ videojs('my-player', {
396422

397423
> Type: `number`
398424
425+
_Since 8.2.0_
426+
399427
If specified, Video.js displays a control allowing the
400428
user to jump back in a video by the specified number of seconds.
401429

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
---
2+
title: Picture-in-Picture Options
3+
category: advanced
4+
description: Picture-in-picture modes available to a Video.js player.
5+
---
6+
7+
Picture-in-picture (PiP) is a mode where the video is shown in a window on top of the browser, so the video can be watched while multitasking. Browsers have different PiP capabilities and the options available differ.
8+
9+
## Picture-in-Picture Types
10+
11+
- Video element PiP
12+
- Document PiP
13+
- Browser native - the browser's proprietary PiP implementation that is not controllable by API
14+
15+
### Video element PiP
16+
17+
This picture-in-picture mode is now available on most browsers but notably not Firefox. The video element can be put into a separate window.
18+
19+
This mode has limitations which may make it unsuitable for some use cases. Since only the video is in the PiP window, Video.js player controls will not be displayed, nor will emulated text tracks or any overlays or interactive elements. This mode is also not useful if the video source will change, especially for advertising. If needed, it [can be disabled][disable-elpip].
20+
21+
By default this mode is enabled if the browser supports the [picture-in-picture API][pip-api]. If the Document PiP mode is enabled on a browser that supports it, that will take precedence.
22+
23+
### Document PiP
24+
25+
_Added in v8.3.0_
26+
27+
[Document picture-in-picture][doc-pip] is an improved approach where the whole player element can be placed in a PiP window rather than just the video. This allows player controls, text tracks, overlays to be used.
28+
29+
Currently this is supported on Chrome 111 and above as an [origin trial][origin-trial]. The player at [videojs.com](/) will use this mode on supported browsers.
30+
31+
At this time this mode defaults to off, but [can be simply enabled with a player option][enable-docpip]. If enabled, and supported by the browser, this takes prcedence over the video picture-in-picture mode.
32+
33+
34+
### Browser native PiP
35+
36+
Firefox does not implement the picture-in-picture API. Instead it has a proprietary picture-in-picture mode. It displays a PiP button on top of the video.
37+
38+
It is not possible to customize or remove this button programatically, nor is it possible to initiate PiP from a custom control. The Video.js picture-in-picture options have no effect.
39+
40+
## Options
41+
42+
The video element PiP (vPiP) [`disablePictureInPicture`][disable-elpip] and document PiP (docPiP) [`enableDocumentPictureInPicture`][enable-docpip] options work independently of each other, so it's possible to use the improved document PiP mode on browsers that support it while disabling the video element PiP mode on browsers that don't.
43+
44+
| disablePictureInPicture | enableDocumentPictureInPicture | Effect* |
45+
| ----------------------- | ------------------------------ | ------ |
46+
| `false` (default) | `false` (default) | vPiP used on browsers that support it. |
47+
| `false` (default) | `true` | docPiP will be used if the browser supports it, otherwise vPiP used on browsers that support it. |
48+
| `true` | `true` | docPiP will be used if the browser supports it. vPiP will not be used. |
49+
| `true` | `false` (default) | Neither docPiP not vPiP will be used. |
50+
51+
_* None of these options can have any effect on Firefox's behaviour._
52+
53+
[pip-api]: https://developer.mozilla.org/en-US/docs/Web/API/Picture-in-Picture_API
54+
[doc-pip]: https://developer.chrome.com/docs/web-platform/document-picture-in-picture/
55+
[origin-trial]: https://developer.chrome.com/docs/web-platform/origin-trials/
56+
[disable-elpip]: /guides/options/#disablepictureinpicture
57+
[enable-docpip]: /guides/options/#enabledocumentpictureinpicture

src/templates/HomeTemplate.jsx

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Sponsors from '../components/HomeComponents/Sponsors';
1111
import Implementation from '../components/HomeComponents/Implementation';
1212
import AdvancedExample from '../components/HomeComponents/AdvancedExample';
1313
import GetInvolved from '../components/HomeComponents/GetInvolved';
14+
import { Helmet } from 'react-helmet';
1415

1516
const IndexPage = props => {
1617
const themeName = props.pageContext.theme;
@@ -23,6 +24,10 @@ const IndexPage = props => {
2324
keywords={['HTML5 video', 'player', 'hls', 'adaptive-bitrate']}
2425
description="The world's most popular open source HTML5 player framework"
2526
/>
27+
<Helmet>
28+
{/* Origin trial for documentPictureInPicture */}
29+
<meta http-equiv="origin-trial" content="AtSClXdNOoAPsggUV+nqh187coO6axCtgTdtFue+P9rz9xqRA5qjlz0AB92Edaxh9imwk/NJueqxdO9QmkqrswUAAABzeyJvcmlnaW4iOiJodHRwczovL3ZpZGVvanMuY29tOjQ0MyIsImZlYXR1cmUiOiJEb2N1bWVudFBpY3R1cmVJblBpY3R1cmVBUEkiLCJleHBpcnkiOjE2OTQxMzExOTksImlzU3ViZG9tYWluIjp0cnVlfQ==" />
30+
</Helmet>
2631
<Hero
2732
heroTheme={heroTheme}
2833
transitionDuration={props.transitionDuration}

0 commit comments

Comments
 (0)