Compare commits
350 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| dfc09b8e04 | |||
| 6438baaddc | |||
| 8fc6c2ba52 | |||
| 95092edc93 | |||
| c4b3e0672e | |||
| e8e2b8ba39 | |||
| 2e40b91ec1 | |||
| 97d9228bed | |||
| 0f14865d56 | |||
| c94ab2a39f | |||
| ab89e055de | |||
| ac6e3dba5a | |||
| d9d2c4a219 | |||
| 1890a9378d | |||
| ac88e6e190 | |||
| 15cbae8a19 | |||
| aaf096d96d | |||
| 93f5acbffd | |||
| 9c717275d2 | |||
| 0249772f01 | |||
| 5d699d5f47 | |||
| 34d79a5443 | |||
| 1e761e237a | |||
| 36ad132c82 | |||
| c9055f391b | |||
| 99c95363b4 | |||
| c90526bf07 | |||
| 97a6e72e10 | |||
| f100caba81 | |||
| 80aa6ffe43 | |||
| 0694e58650 | |||
| e644eeb5b6 | |||
| 5ddd9e02de | |||
| a064f0b4fd | |||
| b9dbcc30fa | |||
| 7ab34c7d2e | |||
| 17caa3c57b | |||
| 2e6361898b | |||
| a1b2c0419f | |||
| 9b81e776fb | |||
| 7a4a7dece8 | |||
| f0d3e8c3b9 | |||
| ad68d9484f | |||
| c3fd822857 | |||
| e147f3a754 | |||
| b694e7d3ab | |||
| b2fff4c33f | |||
| 9c1060d9b0 | |||
| a91652287b | |||
| 2cf44c236d | |||
| 243db9eda3 | |||
| b675ba1f35 | |||
| e9367ee85e | |||
| d9b7928ce6 | |||
| cdacae6697 | |||
| 2bd08cdc28 | |||
| 5fefabe3bd | |||
| e281078441 | |||
| 9bb75f6f52 | |||
| 3b7a24456d | |||
| c885d59270 | |||
| 9f30d54963 | |||
| b247093495 | |||
| 9ca7b861a9 | |||
| 2eccf0dd05 | |||
| 566b957e65 | |||
| a8456f4ca7 | |||
| 0f3098040d | |||
| 21539be3f2 | |||
| c22f5c4b39 | |||
| f4b47a9275 | |||
| 266b70d9d0 | |||
| 6e68ad6d15 | |||
| c202551e6d | |||
| 5b7a025d26 | |||
| 26bcf83960 | |||
| e4acff4f8d | |||
| 568ddf2390 | |||
| ce91945544 | |||
| 11fed8d1b5 | |||
| 4c3bf25b8a | |||
| 215fc3677a | |||
| 4d3b6b882e | |||
| 83eda174af | |||
| 1c29cb890e | |||
| 438ebe5013 | |||
| 4335a2a0d1 | |||
| 825fd292ae | |||
| 80990c98c8 | |||
| 44d3a17870 | |||
| 54110f8358 | |||
| 522135adaf | |||
| 153b8dc6bb | |||
| d1bc70ea06 | |||
| df61e5cdd2 | |||
| bf9a557868 | |||
| 537ffce4e0 | |||
| b38a481b20 | |||
| 7e1d461882 | |||
| c634d3696e | |||
| 0189e90fce | |||
| dbd2136bac | |||
| eb628c8e4f | |||
| 38cb20706f | |||
| c730866efe | |||
| d0e3c7c6d0 | |||
| d9daf2c618 | |||
| b1da599b5d | |||
| b798368ba6 | |||
| fa4868a26d | |||
| 6bf6c3f0f4 | |||
| 32e8cce527 | |||
| c125c1a2c0 | |||
| d311722cd0 | |||
| 1d51b28701 | |||
| dc54eba8f8 | |||
| a84fc396e8 | |||
| 8b57104f83 | |||
| ff066f0c2a | |||
| a64a84f2fe | |||
| 1f0a74f3d5 | |||
| 44739a17d0 | |||
| 464acd1a36 | |||
| fe536252aa | |||
| 52be5ae889 | |||
| 24319e5c31 | |||
| c44351507f | |||
| 052e426810 | |||
| c577eb01ce | |||
| 263e88f6b3 | |||
| 4ab8a54a11 | |||
| ad72ebd4bb | |||
| e40c63b9e7 | |||
| f927d26ce7 | |||
| fe24c73c11 | |||
| 2475b2a82b | |||
| 4ccc629488 | |||
| 6782737009 | |||
| 4d3e188401 | |||
| cd9cbfbd1e | |||
| 7dd7c13065 | |||
| 6be125db87 | |||
| 1c79ce70c9 | |||
| db2997ef21 | |||
| 10c88f6e49 | |||
| 6d9d315ca7 | |||
| 973527cb84 | |||
| 0ff47fe3ea | |||
| 5fdc0aae66 | |||
| d97257a5a9 | |||
| 279f051905 | |||
| 88ffd0f138 | |||
| 11618353ea | |||
| e948bfd585 | |||
| 2bbebd811b | |||
| 3fb85664d2 | |||
| b9ea9fba9a | |||
| a0303969c2 | |||
| fa78df3749 | |||
| df5b7a008d | |||
| 80813b0406 | |||
| e8d2f23b81 | |||
| 0e181133c1 | |||
| 8f27611911 | |||
| 2c8a337f26 | |||
| c24e52d97d | |||
| 574f40949c | |||
| cf3848fbd5 | |||
| a19ad69038 | |||
| d6f20e2756 | |||
| e2fc20ca76 | |||
| 37c3f7109d | |||
| 99d5211a33 | |||
| b97f143195 | |||
| e8da4326b6 | |||
| 67f908aa8d | |||
| 65eb5c1b8b | |||
| 7d484c6e09 | |||
| 8252e13eb9 | |||
| 1a9b860e68 | |||
| cede7d0f35 | |||
| fe26d383f1 | |||
| df4bc268dc | |||
| e49da6c13f | |||
| 67b7262764 | |||
| 88528ef979 | |||
| b6175b1ca9 | |||
| aa20ebaa9c | |||
| 779e45c11b | |||
| 5d5a6eabaa | |||
| 03c9b53232 | |||
| ebaded66b4 | |||
| c232eb2478 | |||
| 7559cc6897 | |||
| 69d0d6d7ee | |||
| 3e9336b15d | |||
| 5c78ecc15d | |||
| 06db3f702d | |||
| a2a82a96a6 | |||
| a86bbae851 | |||
| fac134dd95 | |||
| 515ae32160 | |||
| df8f040795 | |||
| 64a23992f0 | |||
| f5baff6e6b | |||
| 8bdd90a2a8 | |||
| 5536e97482 | |||
| de47071256 | |||
| 87072cb690 | |||
| d9565e9250 | |||
| f80b568e67 | |||
| 7fed689f9a | |||
| 3f48df8f10 | |||
| cc55092ca6 | |||
| 3331d9d01d | |||
| 62d80e6b76 | |||
| 7dc4d9cd22 | |||
| 8fb8ae1260 | |||
| 90304369f4 | |||
| 922456c46c | |||
| eaeccd66ae | |||
| 7a43649c13 | |||
| 525bbf313e | |||
| cfaebe9bf2 | |||
| b57b7b2153 | |||
| 48bf368316 | |||
| 8f94ce86a0 | |||
| 10a9cf08f1 | |||
| 286d0d1794 | |||
| 95f6fa2731 | |||
| 1aeef81288 | |||
| 211ad6c8f5 | |||
| 468b20d227 | |||
| f6bc42c2bc | |||
| 2c01b8ba76 | |||
| 4e1df8677f | |||
| 6953a12e2a | |||
| 1d0db89194 | |||
| 297f297d18 | |||
| 059205c378 | |||
| f94e53ffb1 | |||
| a4f1fdec5d | |||
| 75374eb154 | |||
| 3ad118c026 | |||
| 0bc6b1f1b3 | |||
| 4ea458e1a3 | |||
| aacb172017 | |||
| dbf768b1bd | |||
| b96fcfc8ac | |||
| 18b4d26bee | |||
| 7f4b74e2d4 | |||
| a8f8486cf4 | |||
| a343e58e53 | |||
| 0892d69ba2 | |||
| ba511b51c7 | |||
| e090581913 | |||
| aaa56caa9c | |||
| c8db1e55dd | |||
| 58079393e6 | |||
| 0b44f2d897 | |||
| 2371619486 | |||
| 13a54b5dbe | |||
| fa0861ff2e | |||
| 748aa5179f | |||
| 56a485bac6 | |||
| 9488de30e5 | |||
| e3dfd16096 | |||
| c230ccce86 | |||
| db22a8e9c4 | |||
| 3a3358e2b4 | |||
| 248005e8e0 | |||
| dae272ef66 | |||
| 2679c5898e | |||
| efb7401e6d | |||
| 60a0f0c979 | |||
| 5d168d0e14 | |||
| f964e34d8c | |||
| 021ba0b8e9 | |||
| 96d371546c | |||
| e1780a4df0 | |||
| e5e169a1e2 | |||
| 5eda498516 | |||
| 599b33e55f | |||
| 3a8332bdb3 | |||
| 44b5d9f6b9 | |||
| 24deff0e2d | |||
| 0933b48c2a | |||
| 71578e07ec | |||
| 671325dd17 | |||
| 53a3d06103 | |||
| ad1989e45e | |||
| f9ac98bc6d | |||
| 544ab0086b | |||
| 13bf80d372 | |||
| e2fb922d73 | |||
| a6cc85c437 | |||
| d061be5d2b | |||
| dc2feedd79 | |||
| f8e4ba36e5 | |||
| f3d5389587 | |||
| d9ffb10b93 | |||
| e63ad7c74b | |||
| 1186377b25 | |||
| 8616895e57 | |||
| 2cf5a22c85 | |||
| 763eb2df80 | |||
| 8bbf66a0fb | |||
| 676b46e4a7 | |||
| 82a119c67f | |||
| 6fd4389887 | |||
| 1e1a548459 | |||
| 8db9b53a8f | |||
| ba33fd8277 | |||
| 8071feda18 | |||
| a49b73cd01 | |||
| 8226493a9e | |||
| 38a8a0e8a1 | |||
| ead6601394 | |||
| e61ebd8d05 | |||
| 6eeca8b5d1 | |||
| bf51ce4414 | |||
| 5ad614e251 | |||
| 93c890603d | |||
| 29fb4dfc2b | |||
| 7de9fd1d65 | |||
| 566c059832 | |||
| 0c9572f0a1 | |||
| c99607c85a | |||
| e2010bcd1a | |||
| 3bf1c59bd6 | |||
| e9f1b55f51 | |||
| 4f5152f526 | |||
| de9b53045a | |||
| e59fe1aacf | |||
| df458c5e7a | |||
| e206554146 | |||
| e422806c44 | |||
| b6ddf144f4 | |||
| 86406ee59a | |||
| 81c5477f1d | |||
| 1f1d74ba50 | |||
| bb546fe43f | |||
| 9e1218547b | |||
| 715b88c09b | |||
| 7b9ef7d757 | |||
| d64ed4ba5a | |||
| ffd864ed39 | |||
| afc969bac3 | |||
| e1ff516219 | |||
| 8efa46aeab |
@@ -0,0 +1,30 @@
|
|||||||
|
{
|
||||||
|
"parser": "babel-eslint",
|
||||||
|
"extends": ["airbnb-base", "prettier"],
|
||||||
|
"plugins": ["simple-import-sort", "import"],
|
||||||
|
"env": {
|
||||||
|
"browser": true,
|
||||||
|
"es6": true
|
||||||
|
},
|
||||||
|
"globals": {
|
||||||
|
"Plyr": false,
|
||||||
|
"jQuery": false
|
||||||
|
},
|
||||||
|
"rules": {
|
||||||
|
"import/no-cycle": "warn",
|
||||||
|
"padding-line-between-statements": [
|
||||||
|
"error",
|
||||||
|
{
|
||||||
|
"blankLine": "never",
|
||||||
|
"prev": ["singleline-const", "singleline-let", "singleline-var"],
|
||||||
|
"next": ["singleline-const", "singleline-let", "singleline-var"]
|
||||||
|
}
|
||||||
|
],
|
||||||
|
"sort-imports": "off",
|
||||||
|
"import/order": "off",
|
||||||
|
"simple-import-sort/sort": "error"
|
||||||
|
},
|
||||||
|
"parserOptions": {
|
||||||
|
"sourceType": "module"
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,40 +0,0 @@
|
|||||||
{
|
|
||||||
"parser": "babel-eslint",
|
|
||||||
"extends": ["airbnb-base", "prettier"],
|
|
||||||
"env": {
|
|
||||||
"browser": true,
|
|
||||||
"es6": true
|
|
||||||
},
|
|
||||||
"globals": { "Plyr": false, "jQuery": false },
|
|
||||||
"rules": {
|
|
||||||
"no-const-assign": 1,
|
|
||||||
"no-shadow": 0,
|
|
||||||
"no-this-before-super": 1,
|
|
||||||
"no-undef": 1,
|
|
||||||
"no-unreachable": 1,
|
|
||||||
"no-unused-vars": 1,
|
|
||||||
"constructor-super": 1,
|
|
||||||
"valid-typeof": 1,
|
|
||||||
"indent": [2, 4, { "SwitchCase": 1 }],
|
|
||||||
"quotes": [2, "single", "avoid-escape"],
|
|
||||||
"semi": [2, "always"],
|
|
||||||
"eqeqeq": [2, "always"],
|
|
||||||
"one-var": [2, "never"],
|
|
||||||
"comma-dangle": [2, "always-multiline"],
|
|
||||||
"no-restricted-globals": [
|
|
||||||
"error",
|
|
||||||
{
|
|
||||||
"name": "event",
|
|
||||||
"message": "Use local parameter instead."
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"name": "error",
|
|
||||||
"message": "Use local parameter instead."
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"no-param-reassign": [2, { "props": false }]
|
|
||||||
},
|
|
||||||
"parserOptions": {
|
|
||||||
"sourceType": "module"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
# These are supported funding model platforms
|
||||||
|
|
||||||
|
github: sampotts
|
||||||
|
patreon: plyr
|
||||||
@@ -0,0 +1,55 @@
|
|||||||
|
---
|
||||||
|
name: Bug report
|
||||||
|
about: Report an issue or unexpected behaviour with Plyr
|
||||||
|
---
|
||||||
|
|
||||||
|
<!--
|
||||||
|
|
||||||
|
Before creating the issue, please make sure that...
|
||||||
|
|
||||||
|
* You aren't getting any errors in your own code, causing the problem.
|
||||||
|
* You are using the latest version of Plyr.
|
||||||
|
* There isn't already an open issue for your problem.
|
||||||
|
* You are following the documentation correctly (https://github.com/sampotts/plyr/)
|
||||||
|
* Your problem doesn't happen if you remove Plyr and use native HTML5 media (when applicable).
|
||||||
|
|
||||||
|
For problems with autoplay, see our FAQ (https://github.com/sampotts/plyr/wiki/FAQ)
|
||||||
|
|
||||||
|
If you have multiple unrelated problems, create separate issues rather than combining them into one.
|
||||||
|
|
||||||
|
Note that leaving sections blank or being vague will make it difficult for us to troubleshoot and we may close the issue.
|
||||||
|
-->
|
||||||
|
|
||||||
|
### Expected behaviour
|
||||||
|
|
||||||
|
### Actual behaviour
|
||||||
|
|
||||||
|
### Steps to reproduce
|
||||||
|
|
||||||
|
### Environment
|
||||||
|
|
||||||
|
- Browser:
|
||||||
|
- Version:
|
||||||
|
- Operating System:
|
||||||
|
- Version:
|
||||||
|
|
||||||
|
### Console errors (if any)
|
||||||
|
|
||||||
|
### Link to where the bug is happening
|
||||||
|
|
||||||
|
<!--
|
||||||
|
This link can be either to our demo at https://plyr.io/ if the problem can be observed there, or to a code playground with a **minimal** test case that demonstrates the problem.
|
||||||
|
|
||||||
|
You can use one of our prepared templates to get started creating the test case:
|
||||||
|
|
||||||
|
* HTML5 video: https://codepen.io/pen?template=bKeqpr
|
||||||
|
* HTML5 audio: https://codepen.io/pen?template=rKLywR
|
||||||
|
* YouTube: https://codepen.io/pen?template=GGqbbJ
|
||||||
|
* Vimeo: https://codepen.io/pen?template=bKeXNq
|
||||||
|
* Dash.js integration: https://codepen.io/pen?template=zaBgBy
|
||||||
|
* Hls.js integration: https://codepen.io/pen?template=oyLKQb
|
||||||
|
* Shaka Player integration: https://codepen.io/pen?template=ZRpzZO
|
||||||
|
|
||||||
|
It's important that you keep the issue description and replication demo **minimal**. If your replication includes frameworks, libraries or customizations, this makes it much harder to understand the problem and find the bug. For more help on how to create the demo, see https://github.com/sampotts/plyr/wiki/Writing-helpful-issue-descriptions
|
||||||
|
|
||||||
|
-->
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: New feature
|
||||||
|
about: Request new functionality
|
||||||
|
---
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Please describe the behaviour that you want to add, and why. Be as clear as possible to avoid confusion.
|
||||||
|
|
||||||
|
If you want to request multiple features that aren't directly related, then create one issue per feature.
|
||||||
|
-->
|
||||||
@@ -0,0 +1,10 @@
|
|||||||
|
---
|
||||||
|
name: Improvement
|
||||||
|
about: Request a change that isn't a bug or new feature
|
||||||
|
---
|
||||||
|
|
||||||
|
<!--
|
||||||
|
Please describe the behaviour that you want to change, and why. Be as clear as possible to avoid confusion.
|
||||||
|
|
||||||
|
If you want to request multiple changes that aren't directly related, then create one issue per change.
|
||||||
|
-->
|
||||||
@@ -1,17 +1,3 @@
|
|||||||
<!---
|
PLEASE USE OUR SPECIFIC ISSUE TEMPLATES for bug reports, features and improvement suggestions.
|
||||||
Please use this issue template as it makes replicating and fixing the issue easier!
|
|
||||||
--->
|
|
||||||
|
|
||||||
### Expected behaviour
|
Our issue tracker is not for support questions. If you need help, follow our support instructions: https://github.com/sampotts/plyr/blob/master/contributing.md#support
|
||||||
|
|
||||||
### Actual behaviour
|
|
||||||
|
|
||||||
### Environment
|
|
||||||
|
|
||||||
- Browser:
|
|
||||||
- Version:
|
|
||||||
- Operating System:
|
|
||||||
- Version:
|
|
||||||
|
|
||||||
### Steps to reproduce
|
|
||||||
-
|
|
||||||
|
|||||||
@@ -4,5 +4,5 @@
|
|||||||
|
|
||||||
### Checklist
|
### Checklist
|
||||||
- [ ] Use `develop` as the base branch
|
- [ ] Use `develop` as the base branch
|
||||||
- [ ] Exclude the gulp build from the PR
|
- [ ] Exclude the gulp build (`/dist` changes) from the PR
|
||||||
- [ ] Test on [supported browsers](https://github.com/sampotts/plyr#browser-support)
|
- [ ] Test on [supported browsers](https://github.com/sampotts/plyr#browser-support)
|
||||||
|
|||||||
+2
-4
@@ -1,11 +1,9 @@
|
|||||||
node_modules
|
node_modules
|
||||||
.DS_Store
|
.DS_Store
|
||||||
aws.json
|
credentials.json
|
||||||
*.mp4
|
*.mp4
|
||||||
!dist/blank.mp4
|
!dist/blank.mp4
|
||||||
index-*.html
|
|
||||||
npm-debug.log
|
npm-debug.log
|
||||||
|
yarn-error.log
|
||||||
*.webm
|
*.webm
|
||||||
/package-lock.json
|
|
||||||
.idea/
|
.idea/
|
||||||
|
|
||||||
|
|||||||
@@ -2,3 +2,11 @@ demo
|
|||||||
.github
|
.github
|
||||||
.vscode
|
.vscode
|
||||||
*.code-workspace
|
*.code-workspace
|
||||||
|
build.json
|
||||||
|
credentials.json
|
||||||
|
deploy.json
|
||||||
|
yarn.lock
|
||||||
|
package-lock.json
|
||||||
|
*.mp4
|
||||||
|
*.webm
|
||||||
|
!dist/blank.mp4
|
||||||
+2
-2
@@ -1,7 +1,7 @@
|
|||||||
{
|
{
|
||||||
"useTabs": false,
|
"useTabs": false,
|
||||||
"tabWidth": 4,
|
"tabWidth": 4,
|
||||||
"printWidth": 120,
|
|
||||||
"singleQuote": true,
|
"singleQuote": true,
|
||||||
"trailingComma": "all"
|
"trailingComma": "all",
|
||||||
|
"printWidth": 120
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
linters:
|
||||||
|
eslint:
|
||||||
|
files:
|
||||||
|
ignore:
|
||||||
|
- 'node_modules/*'
|
||||||
+5
-4
@@ -1,7 +1,8 @@
|
|||||||
language: node_js
|
language: node_js
|
||||||
node_js:
|
node_js: lts/*
|
||||||
- 'lts/*'
|
|
||||||
|
|
||||||
script:
|
script:
|
||||||
- npm run lint
|
- bash .travis/prevent-base-master.sh
|
||||||
- npm run build
|
- bash .travis/omit-dist.sh
|
||||||
|
- npm run lint
|
||||||
|
- npm run build
|
||||||
|
|||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ $TRAVIS_BRANCH == "develop" ] && $(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -qE "^(demo/)?dist/"); then
|
||||||
|
echo 'Build output ("dist" and "demo/dist") not permitted in develop' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
Executable
+5
@@ -0,0 +1,5 @@
|
|||||||
|
#!/bin/bash
|
||||||
|
if [ "$TRAVIS_PULL_REQUEST" != "false" ] && [ $TRAVIS_BRANCH == "master" ] && $(git diff --name-only $TRAVIS_COMMIT_RANGE | grep -q "^src/"); then
|
||||||
|
echo 'The base branch for pull requests must be "develop"' >&2
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
@@ -1,61 +0,0 @@
|
|||||||
# Contributing
|
|
||||||
|
|
||||||
We welcome bug reports, feature requests and pull requests. If you want to help us out, please follow these guidelines, in order to avoid redundant work.
|
|
||||||
|
|
||||||
## Commenting
|
|
||||||
When commenting, keep a civil tone and stay on topic. Don't ask for support (use [Stack Overflow](https://stackoverflow.com/) or [our Slack](https://bit.ly/plyr-chat) for that), or post "+1" or "I agree" type of comments. Use the emojis instead.
|
|
||||||
|
|
||||||
Asking for the status on issues is discouraged. Unless someone has explicitly said in an issue that it's work in progress, most likely that means no one is working on it. We have a lot to do, and it may not be a top priority for us.
|
|
||||||
|
|
||||||
We *may* moderate discussions. We do this to avoid threads being "hijacked", to avoid confusion in case the content is misleading or outdated, and to avoid bothering people with github notifications.
|
|
||||||
|
|
||||||
## Reporting issues
|
|
||||||
|
|
||||||
Our GitHub issue tracker is for bug reports and feature requests. Don't ask for support here. Use [Stack Overflow](https://stackoverflow.com/) or [our Slack](https://bit.ly/plyr-chat) for that.
|
|
||||||
|
|
||||||
Please verify that your issue hasn't already been answered by our [FAQ](https://github.com/sampotts/plyr/wiki/FAQ), and that there isn't already an open issue for it.
|
|
||||||
|
|
||||||
When applicable, check that your problem doesn't happen without Plyr (see [FAQ#1](https://github.com/sampotts/plyr/wiki/FAQ#1-does-plyr-work-with--)).
|
|
||||||
|
|
||||||
Verify that you are following the documentation, are using the latest version of Plyr, and aren't getting any errors in your own code, causing the issues.
|
|
||||||
|
|
||||||
Create one issue per problem or request (i.e. don't combine multiple problems to one git issue). Describe the issue as detailed as possible (see [Replication](#replication))
|
|
||||||
|
|
||||||
## Replication
|
|
||||||
|
|
||||||
In order to solve a problem, we first need to understand it. Please answer these questions when reporting issues or asking for help in [our Slack](https://bit.ly/plyr-chat).
|
|
||||||
|
|
||||||
* Does it happen only with specific options and/or specific browsers?
|
|
||||||
* Does is happen only with HTML5 video, audio, YouTube, Vimeo or a specific library?
|
|
||||||
* Does the issue happen on [our demo](https://plyr.io/)? If not, please recreate it with a **minimal** example online. You can use our Codepen templates to get started:
|
|
||||||
* [HTML5 video](https://codepen.io/pen?template=bKeqpr)
|
|
||||||
* [HTML5 audio](https://codepen.io/pen?template=rKLywR)
|
|
||||||
* [YouTube](https://codepen.io/pen?template=GGqbbJ)
|
|
||||||
* [Vimeo](https://codepen.io/pen?template=bKeXNq)
|
|
||||||
* [Dash.js integration](https://codepen.io/pen?template=zaBgBy)
|
|
||||||
* [Hls.js integration](https://codepen.io/pen?template=oyLKQb)
|
|
||||||
* [Shaka Player integration](https://codepen.io/pen?template=ZRpzZO)
|
|
||||||
|
|
||||||
It's important that you keep the issue description and replication demo **minimal**. If your replication includes frameworks, libraries or customizations, this makes it harder to debug and understand the issue. While it may be relevant to bring this up (ex: "I need Plyr to trigger the event sooner or it breaks Framework X"), please keep these out of your replication demo if they aren't strictly needed to reproduce the issue. If the issue is caused by something a library does that Plyr doesn't handle, it's more helpful for us if you find out what it is, and replicate the same problem without the library. Otherwise any developer who is willing to help out with the issue has to understand the frameworks, libraries and customizations of *your* choice, or no one will try to fix your issue because it's too much work.
|
|
||||||
|
|
||||||
## Requesting features and improvements
|
|
||||||
|
|
||||||
If you are missing something in Plyr, you can create a GitHub issue for this as well. Since we prioritize fixing bugs first, and may have a lot of other suggestions and architectural changes to work on as well, these may not be at the top of our list.
|
|
||||||
|
|
||||||
If your suggestion is important or urgent to you, you may want to first ensure it's something we want to have in Plyr, and then contribute it as a pull request. [Our Slack](https://bit.ly/plyr-chat) is the best place for questions like this.
|
|
||||||
|
|
||||||
## Contributing features and documentation
|
|
||||||
|
|
||||||
* Fork Plyr, and create a new branch in your fork, based on the **develop** branch
|
|
||||||
|
|
||||||
* To test locally, you can use the demo. First make sure you have installed the dependencies with `npm install` or `yarn`. Run `gulp` to build while you are working, and run a local server from the repository root directory. If you have Python installed, this command should work: `python -m SimpleHTTPServer 8080`. Then go to `http://localhost:8080/demo/`
|
|
||||||
|
|
||||||
* Develop and test your modifications.
|
|
||||||
|
|
||||||
* Preferably commit your changes as independent logical chunks, with meaningful messages. Make sure you do not commit unnecessary files or changes, such as the build output, or logging and breakpoints you added for testing.
|
|
||||||
|
|
||||||
* If your modifications changes the documented behavior or add new features, document these changes in readme.md.
|
|
||||||
|
|
||||||
* When finished, push the changes to your GitHub repository and send a pull request to **develop**. Describe what your PR does.
|
|
||||||
|
|
||||||
* If the Travis build fails, or if you get a code review with change requests, you can fix these by pushing new or rebased commits to the branch.
|
|
||||||
-33
@@ -1,33 +0,0 @@
|
|||||||
{
|
|
||||||
"name": "plyr",
|
|
||||||
"description": "A simple HTML5 media player using custom controls",
|
|
||||||
"homepage": "http://plyr.io",
|
|
||||||
"keywords": [
|
|
||||||
"Audio",
|
|
||||||
"Video",
|
|
||||||
"HTML5 Audio",
|
|
||||||
"HTML5 Video"
|
|
||||||
],
|
|
||||||
"authors": [
|
|
||||||
"Sam Potts <sam@potts.es>"
|
|
||||||
],
|
|
||||||
"dependencies": {},
|
|
||||||
"main": [
|
|
||||||
"dist/plyr.css",
|
|
||||||
"dist/plyr.js",
|
|
||||||
"dist/plyr.svg",
|
|
||||||
"src/less/plyr.less",
|
|
||||||
"src/scss/plyr.scss",
|
|
||||||
"src/js/plyr.js"
|
|
||||||
],
|
|
||||||
"ignore": [
|
|
||||||
"node_modules",
|
|
||||||
"bower_components",
|
|
||||||
".gitignore"
|
|
||||||
],
|
|
||||||
"repository": {
|
|
||||||
"type": "git",
|
|
||||||
"url": "git://github.com/sampotts/plyr.git"
|
|
||||||
},
|
|
||||||
"license": "MIT"
|
|
||||||
}
|
|
||||||
+48
@@ -0,0 +1,48 @@
|
|||||||
|
{
|
||||||
|
"js": {
|
||||||
|
"plyr.js": {
|
||||||
|
"src": "./src/js/plyr.js",
|
||||||
|
"dist": "./dist/",
|
||||||
|
"formats": ["es", "umd"],
|
||||||
|
"namespace": "Plyr"
|
||||||
|
},
|
||||||
|
"plyr.polyfilled.js": {
|
||||||
|
"src": "./src/js/plyr.polyfilled.js",
|
||||||
|
"dist": "./dist/",
|
||||||
|
"formats": ["es", "umd"],
|
||||||
|
"namespace": "Plyr",
|
||||||
|
"polyfill": true
|
||||||
|
},
|
||||||
|
"demo.js": {
|
||||||
|
"src": "./demo/src/js/demo.js",
|
||||||
|
"dist": "./demo/dist/",
|
||||||
|
"formats": ["iife"],
|
||||||
|
"namespace": "Demo",
|
||||||
|
"polyfill": true
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"css": {
|
||||||
|
"plyr.css": {
|
||||||
|
"src": "./src/sass/plyr.scss",
|
||||||
|
"dist": "./dist/"
|
||||||
|
},
|
||||||
|
"demo.css": {
|
||||||
|
"src": "./demo/src/sass/bundles/demo.scss",
|
||||||
|
"dist": "./demo/dist/"
|
||||||
|
},
|
||||||
|
"error.css": {
|
||||||
|
"src": "./demo/src/sass/bundles/error.scss",
|
||||||
|
"dist": "./demo/dist/"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"sprite": {
|
||||||
|
"plyr.svg": {
|
||||||
|
"src": "./src/sprite/*.svg",
|
||||||
|
"dist": "./dist"
|
||||||
|
},
|
||||||
|
"demo.svg": {
|
||||||
|
"src": "./src/sprite/*.svg",
|
||||||
|
"dist": "./demo/dist"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,20 +0,0 @@
|
|||||||
{
|
|
||||||
"plyr": {
|
|
||||||
"sass": {
|
|
||||||
"plyr.css": "src/sass/plyr.scss"
|
|
||||||
},
|
|
||||||
"js": {
|
|
||||||
"plyr.js": "src/js/plyr.js",
|
|
||||||
"plyr.polyfilled.js": "src/js/plyr.polyfilled.js"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"demo": {
|
|
||||||
"sass": {
|
|
||||||
"demo.css": "demo/src/sass/bundles/demo.scss",
|
|
||||||
"error.css": "demo/src/sass/bundles/error.scss"
|
|
||||||
},
|
|
||||||
"js": {
|
|
||||||
"demo.js": "demo/src/js/demo.js"
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+286
-171
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,40 @@
|
|||||||
|
# Contributing
|
||||||
|
|
||||||
|
We welcome bug reports, feature requests and pull requests. If you want to help us out, please follow these guidelines, in order to avoid redundant work.
|
||||||
|
|
||||||
|
## Support
|
||||||
|
|
||||||
|
Before asking questions, read our [documentation](https://github.com/sampotts/plyr) and [FAQ](https://github.com/sampotts/plyr/wiki/FAQ).
|
||||||
|
|
||||||
|
If these doesn't answer your question
|
||||||
|
* Use [Stack Overflow](https://stackoverflow.com/) for questions that doesn't directly involve Plyr. This includes for example how to use Javascript, CSS or HTML5 media in general, and how to use other frameworks, libraries and technology.
|
||||||
|
* Use [our Slack](https://bit.ly/plyr-chat) if you need help using Plyr or have questions about Plyr.
|
||||||
|
|
||||||
|
## Commenting
|
||||||
|
When commenting, keep a civil tone and stay on topic. Don't ask for [support](#support), or post "+1" or "I agree" type of comments. Use the emojis instead.
|
||||||
|
|
||||||
|
Asking for the status on issues is discouraged. Unless someone has explicitly said in an issue that it's work in progress, most likely that means no one is working on it. We have a lot to do, and it may not be a top priority for us.
|
||||||
|
|
||||||
|
We *may* moderate discussions. We do this to avoid threads being "hijacked", to avoid confusion in case the content is misleading or outdated, and to avoid bothering people with github notifications.
|
||||||
|
|
||||||
|
## Creating issues
|
||||||
|
|
||||||
|
Please follow the instructions in our issue templates. Don't use github issues to ask for [support](#support).
|
||||||
|
|
||||||
|
## Contributing features and documentation
|
||||||
|
|
||||||
|
* If you want to add a feature or make critical changes, you may want to ensure that this is something we also want (so you don't waste your time). Ask us about this in the corresponding issue if there is one, or on [our Slack](https://bit.ly/plyr-chat) otherwise.
|
||||||
|
|
||||||
|
* Fork Plyr, and create a new branch in your fork, based on the **develop** branch
|
||||||
|
|
||||||
|
* To test locally, you can use the demo. First make sure you have installed the dependencies with `npm install` or `yarn`. Run `gulp` to build while you are working, and run a local server from the repository root directory. If you have Python installed, this command should work: `python -m SimpleHTTPServer 8080`. Then go to `http://localhost:8080/demo/`
|
||||||
|
|
||||||
|
* Develop and test your modifications.
|
||||||
|
|
||||||
|
* Preferably commit your changes as independent logical chunks, with meaningful messages. Make sure you do not commit unnecessary files or changes, such as the build output, or logging and breakpoints you added for testing.
|
||||||
|
|
||||||
|
* If your modifications changes the documented behavior or add new features, document these changes in readme.md.
|
||||||
|
|
||||||
|
* When finished, push the changes to your GitHub repository and send a pull request to **develop**. Describe what your PR does.
|
||||||
|
|
||||||
|
* If the Travis build fails, or if you get a code review with change requests, you can fix these by pushing new or rebased commits to the branch.
|
||||||
@@ -3,7 +3,9 @@
|
|||||||
This is the markup that is rendered for the Plyr controls. You can use the default controls or provide a customized version of markup based on your needs. You can pass the following to the `controls` option:
|
This is the markup that is rendered for the Plyr controls. You can use the default controls or provide a customized version of markup based on your needs. You can pass the following to the `controls` option:
|
||||||
|
|
||||||
- `Array` of options (this builds the default controls based on your choices)
|
- `Array` of options (this builds the default controls based on your choices)
|
||||||
|
- `Element` with the controls
|
||||||
- `String` containing the desired HTML
|
- `String` containing the desired HTML
|
||||||
|
- `false` (or empty string or array) to disable all controls
|
||||||
- `Function` that will be executed and should return one of the above
|
- `Function` that will be executed and should return one of the above
|
||||||
|
|
||||||
## Using default controls
|
## Using default controls
|
||||||
@@ -26,6 +28,7 @@ controls: [
|
|||||||
'settings', // Settings menu
|
'settings', // Settings menu
|
||||||
'pip', // Picture-in-picture (currently Safari only)
|
'pip', // Picture-in-picture (currently Safari only)
|
||||||
'airplay', // Airplay (currently Safari only)
|
'airplay', // Airplay (currently Safari only)
|
||||||
|
'download', // Show a download button with a link to either the current source or a custom URL you specify in your options
|
||||||
'fullscreen', // Toggle fullscreen
|
'fullscreen', // Toggle fullscreen
|
||||||
];
|
];
|
||||||
```
|
```
|
||||||
|
|||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+22226
-1497
File diff suppressed because it is too large
Load Diff
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 5.4 KiB |
Vendored
+1
-1
File diff suppressed because one or more lines are too long
+250
-163
@@ -1,190 +1,277 @@
|
|||||||
<!doctype html>
|
<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
|
<head>
|
||||||
|
<meta charset="utf-8" />
|
||||||
|
<title>Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player</title>
|
||||||
|
<meta
|
||||||
|
name="description"
|
||||||
|
property="og:description"
|
||||||
|
content="A simple HTML5 media player with custom controls and WebVTT captions."
|
||||||
|
/>
|
||||||
|
<meta name="author" content="Sam Potts" />
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
|
|
||||||
<head>
|
<!-- Icons -->
|
||||||
<meta charset="utf-8" />
|
<link rel="icon" href="https://cdn.plyr.io/static/icons/favicon.ico" />
|
||||||
<title>Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player</title>
|
<link rel="icon" type="image/png" href="https://cdn.plyr.io/static/icons/32x32.png" sizes="32x32" />
|
||||||
<meta name="description" property="og:description" content="A simple HTML5 media player with custom controls and WebVTT captions.">
|
<link rel="icon" type="image/png" href="https://cdn.plyr.io/static/icons/16x16.png" sizes="16x16" />
|
||||||
<meta name="author" content="Sam Potts">
|
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.plyr.io/static/icons/180x180.png" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
|
||||||
|
|
||||||
<!-- Icons -->
|
<!-- Open Graph -->
|
||||||
<link rel="icon" href="https://cdn.plyr.io/static/icons/favicon.ico">
|
<meta
|
||||||
<link rel="icon" type="image/png" href="https://cdn.plyr.io/static/icons/32x32.png" sizes="32x32">
|
property="og:title"
|
||||||
<link rel="icon" type="image/png" href="https://cdn.plyr.io/static/icons/16x16.png" sizes="16x16">
|
content="Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player"
|
||||||
<link rel="apple-touch-icon" sizes="180x180" href="https://cdn.plyr.io/static/icons/180x180.png">
|
/>
|
||||||
|
<meta property="og:site_name" content="Plyr" />
|
||||||
|
<meta property="og:url" content="https://plyr.io" />
|
||||||
|
<meta property="og:image" content="https://cdn.plyr.io/static/icons/1200x630.png" />
|
||||||
|
|
||||||
<!-- Opengraph -->
|
<!-- Twitter -->
|
||||||
<meta property="og:title" content="Plyr - A simple, customizable HTML5 Video, Audio, YouTube and Vimeo player">
|
<meta name="twitter:card" content="summary" />
|
||||||
<meta property="og:site_name" content="Plyr">
|
<meta name="twitter:site" content="@sam_potts" />
|
||||||
<meta property="og:url" content="https://plyr.io">
|
<meta name="twitter:creator" content="@sam_potts" />
|
||||||
<meta property="og:image" content="https://cdn.plyr.io/static/icons/1200x630.png">
|
<meta name="twitter:card" content="summary_large_image" />
|
||||||
|
|
||||||
<!-- Twitter -->
|
<!-- Docs styles -->
|
||||||
<meta name="twitter:card" content="summary">
|
<link rel="stylesheet" href="dist/demo.css" />
|
||||||
<meta name="twitter:site" content="@sam_potts">
|
|
||||||
<meta name="twitter:creator" content="@sam_potts">
|
|
||||||
<meta name="twitter:card" content="summary_large_image">
|
|
||||||
|
|
||||||
<!-- Docs styles -->
|
<!-- Preload -->
|
||||||
<link rel="stylesheet" href="dist/demo.css?v=2">
|
<link
|
||||||
|
rel="preload"
|
||||||
|
as="font"
|
||||||
|
crossorigin
|
||||||
|
type="font/woff2"
|
||||||
|
href="https://cdn.plyr.io/static/fonts/gordita-medium.woff2"
|
||||||
|
/>
|
||||||
|
<link
|
||||||
|
rel="preload"
|
||||||
|
as="font"
|
||||||
|
crossorigin
|
||||||
|
type="font/woff2"
|
||||||
|
href="https://cdn.plyr.io/static/fonts/gordita-bold.woff2"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Preload -->
|
<!-- Google Analytics-->
|
||||||
<link rel="preload" as="font" crossorigin type="font/woff2" href="https://cdn.plyr.io/static/fonts/gordita-medium.woff2">
|
<script async src="https://www.googletagmanager.com/gtag/js?id=UA-132699580-1"></script>
|
||||||
<link rel="preload" as="font" crossorigin type="font/woff2" href="https://cdn.plyr.io/static/fonts/gordita-bold.woff2">
|
<script>
|
||||||
</head>
|
window.dataLayer = window.dataLayer || [];
|
||||||
|
function gtag() {
|
||||||
|
dataLayer.push(arguments);
|
||||||
|
}
|
||||||
|
gtag('js', new Date());
|
||||||
|
gtag('config', 'UA-132699580-1');
|
||||||
|
</script>
|
||||||
|
</head>
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
<div class="grid">
|
<div class="grid">
|
||||||
<header>
|
<header>
|
||||||
<h1>Plyr</h1>
|
<h1>Pl<span>a</span>y<span>e</span>r</h1>
|
||||||
<p>A simple, accessible and customisable media player for
|
<p>
|
||||||
<button type="button" class="faux-link" data-source="video">
|
A simple, accessible and customisable media player for
|
||||||
<svg class="icon">
|
<button type="button" class="faux-link" data-source="video">
|
||||||
<title>HTML5</title>
|
<svg class="icon">
|
||||||
<path d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"></path>
|
<title>HTML5</title>
|
||||||
</svg>Video</button>,
|
<path
|
||||||
<button type="button" class="faux-link" data-source="audio">
|
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
||||||
<svg class="icon">
|
></path></svg
|
||||||
<title>HTML5</title>
|
>Video</button
|
||||||
<path d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"></path>
|
>,
|
||||||
</svg>Audio</button>,
|
<button type="button" class="faux-link" data-source="audio">
|
||||||
<button type="button" class="faux-link" data-source="youtube">
|
<svg class="icon">
|
||||||
<svg class="icon" role="presentation">
|
<title>HTML5</title>
|
||||||
<title>YouTube</title>
|
<path
|
||||||
<path d="M15.8,4.8c-0.2-1.3-0.8-2.2-2.2-2.4C11.4,2,8,2,8,2S4.6,2,2.4,2.4C1,2.6,0.3,3.5,0.2,4.8C0,6.1,0,8,0,8
|
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
||||||
|
></path></svg
|
||||||
|
>Audio</button
|
||||||
|
>,
|
||||||
|
<button type="button" class="faux-link" data-source="youtube">
|
||||||
|
<svg class="icon" role="presentation">
|
||||||
|
<title>YouTube</title>
|
||||||
|
<path
|
||||||
|
d="M15.8,4.8c-0.2-1.3-0.8-2.2-2.2-2.4C11.4,2,8,2,8,2S4.6,2,2.4,2.4C1,2.6,0.3,3.5,0.2,4.8C0,6.1,0,8,0,8
|
||||||
s0,1.9,0.2,3.2c0.2,1.3,0.8,2.2,2.2,2.4C4.6,14,8,14,8,14s3.4,0,5.6-0.4c1.4-0.3,2-1.1,2.2-2.4C16,9.9,16,8,16,8S16,6.1,15.8,4.8z
|
s0,1.9,0.2,3.2c0.2,1.3,0.8,2.2,2.2,2.4C4.6,14,8,14,8,14s3.4,0,5.6-0.4c1.4-0.3,2-1.1,2.2-2.4C16,9.9,16,8,16,8S16,6.1,15.8,4.8z
|
||||||
M6,11V5l5,3L6,11z"></path>
|
M6,11V5l5,3L6,11z"
|
||||||
</svg>YouTube</button> and
|
></path></svg
|
||||||
<button type="button" class="faux-link" data-source="vimeo">
|
>YouTube
|
||||||
<svg class="icon" role="presentation">
|
</button>
|
||||||
<title>Vimeo</title>
|
and
|
||||||
<path d="M16,4.3c-0.1,1.6-1.2,3.7-3.3,6.4c-2.2,2.8-4,4.2-5.5,4.2c-0.9,0-1.7-0.9-2.4-2.6C4,9.9,3.4,5,2,5
|
<button type="button" class="faux-link" data-source="vimeo">
|
||||||
|
<svg class="icon" role="presentation">
|
||||||
|
<title>Vimeo</title>
|
||||||
|
<path
|
||||||
|
d="M16,4.3c-0.1,1.6-1.2,3.7-3.3,6.4c-2.2,2.8-4,4.2-5.5,4.2c-0.9,0-1.7-0.9-2.4-2.6C4,9.9,3.4,5,2,5
|
||||||
C1.9,5,1.5,5.3,0.8,5.8L0,4.8c0.8-0.7,3.5-3.4,4.7-3.5C5.9,1.2,6.7,2,7,3.8c0.3,2,0.8,6.1,1.8,6.1c0.9,0,2.5-3.4,2.6-4
|
C1.9,5,1.5,5.3,0.8,5.8L0,4.8c0.8-0.7,3.5-3.4,4.7-3.5C5.9,1.2,6.7,2,7,3.8c0.3,2,0.8,6.1,1.8,6.1c0.9,0,2.5-3.4,2.6-4
|
||||||
c0.1-0.9-0.3-1.9-2.3-1.1c0.8-2.6,2.3-3.8,4.5-3.8C15.3,1.1,16.1,2.2,16,4.3z"></path>
|
c0.1-0.9-0.3-1.9-2.3-1.1c0.8-2.6,2.3-3.8,4.5-3.8C15.3,1.1,16.1,2.2,16,4.3z"
|
||||||
</svg>Vimeo</button>
|
></path></svg
|
||||||
</p>
|
>Vimeo
|
||||||
|
</button>
|
||||||
|
</p>
|
||||||
|
|
||||||
<p>Premium video monitization from
|
<p>
|
||||||
<a href="https://vi.ai/publisher-video-monetization/?aid=plyrio" target="_blank" class="no-border">
|
Premium video monitization from
|
||||||
<img src="https://cdn.plyr.io/static/vi-logo-24x24.svg" alt="ai.vi">
|
<a href="https://vi.ai/publisher-video-monetization/?aid=plyrio" target="_blank" class="no-border">
|
||||||
<span class="sr-only">ai.vi</span>
|
<img src="https://cdn.plyr.io/static/vi-logo-24x24.svg" alt="ai.vi" />
|
||||||
</a>
|
<span class="sr-only">ai.vi</span>
|
||||||
</p>
|
</a>
|
||||||
|
</p>
|
||||||
|
|
||||||
<div class="call-to-action">
|
<div class="call-to-action">
|
||||||
<span class="button--with-count">
|
<a href="https://github.com/sampotts/plyr" target="_blank" class="button js-shr">
|
||||||
<a href="https://github.com/sampotts/plyr" target="_blank" class="button" data-shr-network="github">
|
|
||||||
<svg class="icon" role="presentation">
|
<svg class="icon" role="presentation">
|
||||||
<title>GitHub</title>
|
<title>GitHub</title>
|
||||||
<path d="M8,0.2c-4.4,0-8,3.6-8,8c0,3.5,2.3,6.5,5.5,7.6
|
<path
|
||||||
C5.9,15.9,6,15.6,6,15.4c0-0.2,0-0.7,0-1.4C3.8,14.5,3.3,13,3.3,13c-0.4-0.9-0.9-1.2-0.9-1.2c-0.7-0.5,0.1-0.5,0.1-0.5
|
d="M8,0.2c-4.4,0-8,3.6-8,8c0,3.5,2.3,6.5,5.5,7.6
|
||||||
c0.8,0.1,1.2,0.8,1.2,0.8C4.4,13.4,5.6,13,6,12.8c0.1-0.5,0.3-0.9,0.5-1.1c-1.8-0.2-3.6-0.9-3.6-4c0-0.9,0.3-1.6,0.8-2.1
|
C5.9,15.9,6,15.6,6,15.4c0-0.2,0-0.7,0-1.4C3.8,14.5,3.3,13,3.3,13c-0.4-0.9-0.9-1.2-0.9-1.2c-0.7-0.5,0.1-0.5,0.1-0.5
|
||||||
c-0.1-0.2-0.4-1,0.1-2.1c0,0,0.7-0.2,2.2,0.8c0.6-0.2,1.3-0.3,2-0.3c0.7,0,1.4,0.1,2,0.3c1.5-1,2.2-0.8,2.2-0.8
|
c0.8,0.1,1.2,0.8,1.2,0.8C4.4,13.4,5.6,13,6,12.8c0.1-0.5,0.3-0.9,0.5-1.1c-1.8-0.2-3.6-0.9-3.6-4c0-0.9,0.3-1.6,0.8-2.1
|
||||||
c0.4,1.1,0.2,1.9,0.1,2.1c0.5,0.6,0.8,1.3,0.8,2.1c0,3.1-1.9,3.7-3.7,3.9C9.7,12,10,12.5,10,13.2c0,1.1,0,1.9,0,2.2
|
c-0.1-0.2-0.4-1,0.1-2.1c0,0,0.7-0.2,2.2,0.8c0.6-0.2,1.3-0.3,2-0.3c0.7,0,1.4,0.1,2,0.3c1.5-1,2.2-0.8,2.2-0.8
|
||||||
c0,0.2,0.1,0.5,0.6,0.4c3.2-1.1,5.5-4.1,5.5-7.6C16,3.8,12.4,0.2,8,0.2z"></path>
|
c0.4,1.1,0.2,1.9,0.1,2.1c0.5,0.6,0.8,1.3,0.8,2.1c0,3.1-1.9,3.7-3.7,3.9C9.7,12,10,12.5,10,13.2c0,1.1,0,1.9,0,2.2
|
||||||
|
c0,0.2,0.1,0.5,0.6,0.4c3.2-1.1,5.5-4.1,5.5-7.6C16,3.8,12.4,0.2,8,0.2z"
|
||||||
|
></path>
|
||||||
</svg>
|
</svg>
|
||||||
Download on GitHub
|
Download on GitHub
|
||||||
</a>
|
</a>
|
||||||
</span>
|
</div>
|
||||||
</div>
|
</header>
|
||||||
</header>
|
|
||||||
|
|
||||||
<main>
|
<main>
|
||||||
<video controls crossorigin playsinline poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg" id="player">
|
<div id="container">
|
||||||
<!-- Video files -->
|
<video
|
||||||
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" type="video/mp4" size="576">
|
controls
|
||||||
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4" type="video/mp4" size="720">
|
crossorigin
|
||||||
<source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4" type="video/mp4" size="1080">
|
playsinline
|
||||||
<!-- <source src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1440p.mp4" type="video/mp4" size="1440"> -->
|
poster="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg"
|
||||||
|
id="player"
|
||||||
|
>
|
||||||
|
<!-- Video files -->
|
||||||
|
<source
|
||||||
|
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4"
|
||||||
|
type="video/mp4"
|
||||||
|
size="576"
|
||||||
|
/>
|
||||||
|
<source
|
||||||
|
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4"
|
||||||
|
type="video/mp4"
|
||||||
|
size="720"
|
||||||
|
/>
|
||||||
|
<source
|
||||||
|
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4"
|
||||||
|
type="video/mp4"
|
||||||
|
size="1080"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Caption files -->
|
<!-- Caption files -->
|
||||||
<track kind="captions" label="English" srclang="en" src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt"
|
<track
|
||||||
default>
|
kind="captions"
|
||||||
<track kind="captions" label="Français" srclang="fr" src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt">
|
label="English"
|
||||||
|
srclang="en"
|
||||||
|
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt"
|
||||||
|
default
|
||||||
|
/>
|
||||||
|
<track
|
||||||
|
kind="captions"
|
||||||
|
label="Français"
|
||||||
|
srclang="fr"
|
||||||
|
src="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt"
|
||||||
|
/>
|
||||||
|
|
||||||
<!-- Fallback for browsers that don't support the <video> element -->
|
<!-- Fallback for browsers that don't support the <video> element -->
|
||||||
<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download>Download</a>
|
<a href="https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4" download
|
||||||
</video>
|
>Download</a
|
||||||
|
>
|
||||||
|
</video>
|
||||||
|
</div>
|
||||||
|
|
||||||
<ul>
|
<ul>
|
||||||
<li class="plyr__cite plyr__cite--video" hidden>
|
<li class="plyr__cite plyr__cite--video" hidden>
|
||||||
<small>
|
<small>
|
||||||
<svg class="icon">
|
<svg class="icon">
|
||||||
<title>HTML5</title>
|
<title>HTML5</title>
|
||||||
<path d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"></path>
|
<path
|
||||||
</svg>
|
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
||||||
<a href="https://itunes.apple.com/au/movie/view-from-a-blue-moon/id1041586323" target="_blank">View From A Blue Moon</a> © Brainfarm
|
></path>
|
||||||
</small>
|
</svg>
|
||||||
</li>
|
<a
|
||||||
<li class="plyr__cite plyr__cite--audio" hidden>
|
href="https://itunes.apple.com/au/movie/view-from-a-blue-moon/id1041586323"
|
||||||
<small>
|
target="_blank"
|
||||||
<svg class="icon" title="HTML5">
|
>View From A Blue Moon</a
|
||||||
<title>HTML5</title>
|
>
|
||||||
<path d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"></path>
|
© Brainfarm
|
||||||
</svg>
|
</small>
|
||||||
<a href="http://www.kishibashi.com/" target="_blank">Kishi Bashi – “It All Began With A Burst”</a> © Kishi Bashi
|
</li>
|
||||||
</small>
|
<li class="plyr__cite plyr__cite--audio" hidden>
|
||||||
</li>
|
<small>
|
||||||
<li class="plyr__cite plyr__cite--youtube" hidden>
|
<svg class="icon" title="HTML5">
|
||||||
<small>
|
<title>HTML5</title>
|
||||||
<a href="https://www.youtube.com/watch?v=bTqVqk7FSmY" target="_blank">View From A Blue Moon</a> on
|
<path
|
||||||
<span class="color--youtube">
|
d="M14.738.326C14.548.118 14.28 0 14 0H2c-.28 0-.55.118-.738.326S.98.81 1.004 1.09l1 11c.03.317.208.603.48.767l5 3c.16.095.338.143.516.143s.356-.048.515-.143l5-3c.273-.164.452-.45.48-.767l1-11c.026-.28-.067-.557-.257-.764zM12 4H6v2h6v5.72l-4 1.334-4-1.333V9h2v1.28l2 .666 2-.667V8H4V2h8v2z"
|
||||||
<svg class="icon" role="presentation">
|
></path>
|
||||||
<title>YouTube</title>
|
</svg>
|
||||||
<path d="M15.8,4.8c-0.2-1.3-0.8-2.2-2.2-2.4C11.4,2,8,2,8,2S4.6,2,2.4,2.4C1,2.6,0.3,3.5,0.2,4.8C0,6.1,0,8,0,8
|
<a href="http://www.kishibashi.com/" target="_blank"
|
||||||
|
>Kishi Bashi – “It All Began With A Burst”</a
|
||||||
|
>
|
||||||
|
© Kishi Bashi
|
||||||
|
</small>
|
||||||
|
</li>
|
||||||
|
<li class="plyr__cite plyr__cite--youtube" hidden>
|
||||||
|
<small>
|
||||||
|
<a href="https://www.youtube.com/watch?v=bTqVqk7FSmY" target="_blank"
|
||||||
|
>View From A Blue Moon</a
|
||||||
|
>
|
||||||
|
on
|
||||||
|
<span class="color--youtube">
|
||||||
|
<svg class="icon" role="presentation">
|
||||||
|
<title>YouTube</title>
|
||||||
|
<path
|
||||||
|
d="M15.8,4.8c-0.2-1.3-0.8-2.2-2.2-2.4C11.4,2,8,2,8,2S4.6,2,2.4,2.4C1,2.6,0.3,3.5,0.2,4.8C0,6.1,0,8,0,8
|
||||||
s0,1.9,0.2,3.2c0.2,1.3,0.8,2.2,2.2,2.4C4.6,14,8,14,8,14s3.4,0,5.6-0.4c1.4-0.3,2-1.1,2.2-2.4C16,9.9,16,8,16,8S16,6.1,15.8,4.8z
|
s0,1.9,0.2,3.2c0.2,1.3,0.8,2.2,2.2,2.4C4.6,14,8,14,8,14s3.4,0,5.6-0.4c1.4-0.3,2-1.1,2.2-2.4C16,9.9,16,8,16,8S16,6.1,15.8,4.8z
|
||||||
M6,11V5l5,3L6,11z"></path>
|
M6,11V5l5,3L6,11z"
|
||||||
</svg>YouTube
|
></path></svg
|
||||||
</span>
|
>YouTube
|
||||||
</small>
|
</span>
|
||||||
</li>
|
</small>
|
||||||
<li class="plyr__cite plyr__cite--vimeo" hidden>
|
</li>
|
||||||
<small>
|
<li class="plyr__cite plyr__cite--vimeo" hidden>
|
||||||
<a href="https://vimeo.com/76979871" target="_blank">The New Vimeo Player</a> on
|
<small>
|
||||||
<span class="color--vimeo">
|
<a href="https://vimeo.com/76979871" target="_blank">The New Vimeo Player</a> on
|
||||||
<svg class="icon" role="presentation">
|
<span class="color--vimeo">
|
||||||
<title>Vimeo</title>
|
<svg class="icon" role="presentation">
|
||||||
<path d="M16,4.3c-0.1,1.6-1.2,3.7-3.3,6.4c-2.2,2.8-4,4.2-5.5,4.2c-0.9,0-1.7-0.9-2.4-2.6C4,9.9,3.4,5,2,5
|
<title>Vimeo</title>
|
||||||
|
<path
|
||||||
|
d="M16,4.3c-0.1,1.6-1.2,3.7-3.3,6.4c-2.2,2.8-4,4.2-5.5,4.2c-0.9,0-1.7-0.9-2.4-2.6C4,9.9,3.4,5,2,5
|
||||||
C1.9,5,1.5,5.3,0.8,5.8L0,4.8c0.8-0.7,3.5-3.4,4.7-3.5C5.9,1.2,6.7,2,7,3.8c0.3,2,0.8,6.1,1.8,6.1c0.9,0,2.5-3.4,2.6-4
|
C1.9,5,1.5,5.3,0.8,5.8L0,4.8c0.8-0.7,3.5-3.4,4.7-3.5C5.9,1.2,6.7,2,7,3.8c0.3,2,0.8,6.1,1.8,6.1c0.9,0,2.5-3.4,2.6-4
|
||||||
c0.1-0.9-0.3-1.9-2.3-1.1c0.8-2.6,2.3-3.8,4.5-3.8C15.3,1.1,16.1,2.2,16,4.3z"></path>
|
c0.1-0.9-0.3-1.9-2.3-1.1c0.8-2.6,2.3-3.8,4.5-3.8C15.3,1.1,16.1,2.2,16,4.3z"
|
||||||
</svg>Vimeo
|
></path></svg
|
||||||
</span>
|
>Vimeo
|
||||||
</small>
|
</span>
|
||||||
</li>
|
</small>
|
||||||
</ul>
|
</li>
|
||||||
</main>
|
</ul>
|
||||||
</div>
|
</main>
|
||||||
|
</div>
|
||||||
|
|
||||||
<aside>
|
<aside>
|
||||||
<svg class="icon">
|
<svg class="icon">
|
||||||
<title>Twitter</title>
|
<title>Twitter</title>
|
||||||
<path d="M16,3c-0.6,0.3-1.2,0.4-1.9,0.5c0.7-0.4,1.2-1,1.4-1.8c-0.6,0.4-1.3,0.6-2.1,0.8c-0.6-0.6-1.5-1-2.4-1
|
<path
|
||||||
|
d="M16,3c-0.6,0.3-1.2,0.4-1.9,0.5c0.7-0.4,1.2-1,1.4-1.8c-0.6,0.4-1.3,0.6-2.1,0.8c-0.6-0.6-1.5-1-2.4-1
|
||||||
C9.3,1.5,7.8,3,7.8,4.8c0,0.3,0,0.5,0.1,0.7C5.2,5.4,2.7,4.1,1.1,2.1c-0.3,0.5-0.4,1-0.4,1.7c0,1.1,0.6,2.1,1.5,2.7
|
C9.3,1.5,7.8,3,7.8,4.8c0,0.3,0,0.5,0.1,0.7C5.2,5.4,2.7,4.1,1.1,2.1c-0.3,0.5-0.4,1-0.4,1.7c0,1.1,0.6,2.1,1.5,2.7
|
||||||
c-0.5,0-1-0.2-1.5-0.4c0,0,0,0,0,0c0,1.6,1.1,2.9,2.6,3.2C3,9.4,2.7,9.4,2.4,9.4c-0.2,0-0.4,0-0.6-0.1c0.4,1.3,1.6,2.3,3.1,2.3
|
c-0.5,0-1-0.2-1.5-0.4c0,0,0,0,0,0c0,1.6,1.1,2.9,2.6,3.2C3,9.4,2.7,9.4,2.4,9.4c-0.2,0-0.4,0-0.6-0.1c0.4,1.3,1.6,2.3,3.1,2.3
|
||||||
c-1.1,0.9-2.5,1.4-4.1,1.4c-0.3,0-0.5,0-0.8,0c1.5,0.9,3.2,1.5,5,1.5c6,0,9.3-5,9.3-9.3c0-0.1,0-0.3,0-0.4C15,4.3,15.6,3.7,16,3z"></path>
|
c-1.1,0.9-2.5,1.4-4.1,1.4c-0.3,0-0.5,0-0.8,0c1.5,0.9,3.2,1.5,5,1.5c6,0,9.3-5,9.3-9.3c0-0.1,0-0.3,0-0.4C15,4.3,15.6,3.7,16,3z"
|
||||||
</svg>
|
></path>
|
||||||
<p>If you think Plyr's good,
|
</svg>
|
||||||
<a href="https://twitter.com/intent/tweet?text=A+simple+HTML5+media+player+with+custom+controls+and+WebVTT+captions.&url=http%3A%2F%2Fplyr.io&via=Sam_Potts"
|
<p>
|
||||||
target="_blank" data-shr-network="twitter">tweet it</a>
|
If you think Plyr's good,
|
||||||
</p>
|
<a
|
||||||
</aside>
|
href="https://twitter.com/intent/tweet?text=A+simple+HTML5+media+player+with+custom+controls+and+WebVTT+captions.&url=http%3A%2F%2Fplyr.io&via=Sam_Potts"
|
||||||
|
target="_blank"
|
||||||
|
class="js-shr"
|
||||||
|
>tweet it</a
|
||||||
|
>
|
||||||
|
👍
|
||||||
|
</p>
|
||||||
|
</aside>
|
||||||
|
|
||||||
<!-- Polyfills -->
|
<script src="dist/demo.js" crossorigin="anonymous"></script>
|
||||||
<script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=es6,Array.prototype.includes,CustomEvent,Object.entries,Object.values,URL"
|
</body>
|
||||||
crossorigin="anonymous"></script>
|
</html>
|
||||||
|
|
||||||
<!-- Plyr core script -->
|
|
||||||
<script src="../dist/plyr.js" crossorigin="anonymous"></script>
|
|
||||||
|
|
||||||
<!-- Sharing libary (https://shr.one) -->
|
|
||||||
<script src="https://cdn.shr.one/1.0.1/shr.js" crossorigin="anonymous"></script>
|
|
||||||
|
|
||||||
<!-- Rangetouch to fix <input type="range"> on touch devices (see https://rangetouch.com) -->
|
|
||||||
<script src="https://cdn.rangetouch.com/1.0.1/rangetouch.js" async crossorigin="anonymous"></script>
|
|
||||||
|
|
||||||
<!-- Docs script -->
|
|
||||||
<script src="dist/demo.js" crossorigin="anonymous"></script>
|
|
||||||
</body>
|
|
||||||
|
|
||||||
</html>
|
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
{
|
||||||
|
"name": "plyr-demo",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Demo for Plyr",
|
||||||
|
"homepage": "https://plyr.io",
|
||||||
|
"author": "Sam Potts <sam@potts.es>",
|
||||||
|
"dependencies": {
|
||||||
|
"core-js": "^3.1.3",
|
||||||
|
"custom-event-polyfill": "^1.0.7",
|
||||||
|
"raven-js": "^3.27.1",
|
||||||
|
"shr-buttons": "2.0.2",
|
||||||
|
"url-polyfill": "^1.1.5"
|
||||||
|
}
|
||||||
|
}
|
||||||
+83
-259
@@ -4,109 +4,49 @@
|
|||||||
// Please see readme.md in the root or github.com/sampotts/plyr
|
// Please see readme.md in the root or github.com/sampotts/plyr
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
|
import './tab-focus';
|
||||||
|
import 'custom-event-polyfill';
|
||||||
|
import 'url-polyfill';
|
||||||
|
|
||||||
import Raven from 'raven-js';
|
import Raven from 'raven-js';
|
||||||
|
import Shr from 'shr-buttons';
|
||||||
|
|
||||||
|
import Plyr from '../../../src/js/plyr';
|
||||||
|
import sources from './sources';
|
||||||
|
import toggleClass from './toggle-class';
|
||||||
|
|
||||||
(() => {
|
(() => {
|
||||||
const isLive = window.location.host === 'plyr.io';
|
const { host } = window.location;
|
||||||
|
const env = {
|
||||||
// Raven / Sentry
|
prod: host === 'plyr.io',
|
||||||
// For demo site (https://plyr.io) only
|
dev: host === 'dev.plyr.io',
|
||||||
if (isLive) {
|
};
|
||||||
Raven.config('https://d4ad9866ad834437a4754e23937071e4@sentry.io/305555').install();
|
|
||||||
}
|
|
||||||
|
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', () => {
|
||||||
Raven.context(() => {
|
Raven.context(() => {
|
||||||
if (window.shr) {
|
const selector = '#player';
|
||||||
window.shr.setup({
|
|
||||||
count: {
|
|
||||||
classname: 'button__count',
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Setup tab focus
|
// Setup share buttons
|
||||||
const tabClassName = 'tab-focus';
|
Shr.setup('.js-shr', {
|
||||||
|
count: {
|
||||||
// Remove class on blur
|
className: 'button__count',
|
||||||
document.addEventListener('focusout', event => {
|
},
|
||||||
event.target.classList.remove(tabClassName);
|
wrapper: {
|
||||||
});
|
className: 'button--with-count',
|
||||||
|
},
|
||||||
// Add classname to tabbed elements
|
|
||||||
document.addEventListener('keydown', event => {
|
|
||||||
if (event.keyCode !== 9) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Delay the adding of classname until the focus has changed
|
|
||||||
// This event fires before the focusin event
|
|
||||||
setTimeout(() => {
|
|
||||||
document.activeElement.classList.add(tabClassName);
|
|
||||||
}, 0);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Setup the player
|
// Setup the player
|
||||||
const player = new Plyr('#player', {
|
const player = new Plyr(selector, {
|
||||||
debug: true,
|
debug: true,
|
||||||
title: 'View From A Blue Moon',
|
title: 'View From A Blue Moon',
|
||||||
iconUrl: '../dist/plyr.svg',
|
iconUrl: 'dist/demo.svg',
|
||||||
keyboard: {
|
keyboard: {
|
||||||
global: true,
|
global: true,
|
||||||
},
|
},
|
||||||
tooltips: {
|
tooltips: {
|
||||||
controls: true,
|
controls: true,
|
||||||
},
|
},
|
||||||
/* controls: [
|
|
||||||
'play-large',
|
|
||||||
'restart',
|
|
||||||
'rewind',
|
|
||||||
'play',
|
|
||||||
'fast-forward',
|
|
||||||
'progress',
|
|
||||||
'current-time',
|
|
||||||
'duration',
|
|
||||||
'mute',
|
|
||||||
'volume',
|
|
||||||
'captions',
|
|
||||||
'settings',
|
|
||||||
'pip',
|
|
||||||
'airplay',
|
|
||||||
'fullscreen',
|
|
||||||
], */
|
|
||||||
/* i18n: {
|
|
||||||
restart: '重新開始',
|
|
||||||
rewind: '快退{seektime}秒',
|
|
||||||
play: '播放',
|
|
||||||
pause: '暫停',
|
|
||||||
fastForward: '快進{seektime}秒',
|
|
||||||
seek: '尋求',
|
|
||||||
played: '發揮',
|
|
||||||
buffered: '緩衝的',
|
|
||||||
currentTime: '當前時間戳',
|
|
||||||
duration: '長短',
|
|
||||||
volume: '音量',
|
|
||||||
mute: '靜音',
|
|
||||||
unmute: '取消靜音',
|
|
||||||
enableCaptions: '開啟字幕',
|
|
||||||
disableCaptions: '關閉字幕',
|
|
||||||
enterFullscreen: '進入全螢幕',
|
|
||||||
exitFullscreen: '退出全螢幕',
|
|
||||||
frameTitle: '球員為{title}',
|
|
||||||
captions: '字幕',
|
|
||||||
settings: '設定',
|
|
||||||
speed: '速度',
|
|
||||||
normal: '正常',
|
|
||||||
quality: '質量',
|
|
||||||
loop: '循環',
|
|
||||||
start: 'Start',
|
|
||||||
end: 'End',
|
|
||||||
all: 'All',
|
|
||||||
reset: '重啟',
|
|
||||||
disabled: '殘',
|
|
||||||
enabled: '啟用',
|
|
||||||
advertisement: '廣告',
|
|
||||||
}, */
|
|
||||||
captions: {
|
captions: {
|
||||||
active: true,
|
active: true,
|
||||||
},
|
},
|
||||||
@@ -114,9 +54,16 @@ import Raven from 'raven-js';
|
|||||||
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c',
|
google: 'AIzaSyDrNwtN3nLH_8rjCmu5Wq3ZCm4MNAVdc0c',
|
||||||
},
|
},
|
||||||
ads: {
|
ads: {
|
||||||
enabled: true,
|
enabled: env.prod || env.dev,
|
||||||
publisherId: '918848828995742',
|
publisherId: '918848828995742',
|
||||||
},
|
},
|
||||||
|
previewThumbnails: {
|
||||||
|
enabled: true,
|
||||||
|
src: [
|
||||||
|
'https://cdn.plyr.io/static/demo/thumbs/100p.vtt',
|
||||||
|
'https://cdn.plyr.io/static/demo/thumbs/240p.vtt',
|
||||||
|
],
|
||||||
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Expose for tinkering in the console
|
// Expose for tinkering in the console
|
||||||
@@ -124,131 +71,12 @@ import Raven from 'raven-js';
|
|||||||
|
|
||||||
// Setup type toggle
|
// Setup type toggle
|
||||||
const buttons = document.querySelectorAll('[data-source]');
|
const buttons = document.querySelectorAll('[data-source]');
|
||||||
const types = {
|
const types = Object.keys(sources);
|
||||||
video: 'video',
|
const historySupport = Boolean(window.history && window.history.pushState);
|
||||||
audio: 'audio',
|
let currentType = window.location.hash.substring(1);
|
||||||
youtube: 'youtube',
|
const hasCurrentType = !currentType.length;
|
||||||
vimeo: 'vimeo',
|
|
||||||
};
|
|
||||||
let currentType = window.location.hash.replace('#', '');
|
|
||||||
const historySupport = window.history && window.history.pushState;
|
|
||||||
|
|
||||||
// Toggle class on an element
|
|
||||||
function toggleClass(element, className, state) {
|
|
||||||
if (element) {
|
|
||||||
element.classList[state ? 'add' : 'remove'](className);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set a new source
|
|
||||||
function newSource(type, init) {
|
|
||||||
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
|
|
||||||
if (
|
|
||||||
!(type in types) ||
|
|
||||||
(!init && type === currentType) ||
|
|
||||||
(!currentType.length && type === types.video)
|
|
||||||
) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
switch (type) {
|
|
||||||
case types.video:
|
|
||||||
player.source = {
|
|
||||||
type: 'video',
|
|
||||||
title: 'View From A Blue Moon',
|
|
||||||
sources: [
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4',
|
|
||||||
type: 'video/mp4',
|
|
||||||
size: 576,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4',
|
|
||||||
type: 'video/mp4',
|
|
||||||
size: 720,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4',
|
|
||||||
type: 'video/mp4',
|
|
||||||
size: 1080,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1440p.mp4',
|
|
||||||
type: 'video/mp4',
|
|
||||||
size: 1440,
|
|
||||||
},
|
|
||||||
],
|
|
||||||
poster: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg',
|
|
||||||
tracks: [
|
|
||||||
{
|
|
||||||
kind: 'captions',
|
|
||||||
label: 'English',
|
|
||||||
srclang: 'en',
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
|
|
||||||
default: true,
|
|
||||||
},
|
|
||||||
{
|
|
||||||
kind: 'captions',
|
|
||||||
label: 'French',
|
|
||||||
srclang: 'fr',
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case types.audio:
|
|
||||||
player.source = {
|
|
||||||
type: 'audio',
|
|
||||||
title: 'Kishi Bashi – “It All Began With A Burst”',
|
|
||||||
sources: [
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3',
|
|
||||||
type: 'audio/mp3',
|
|
||||||
},
|
|
||||||
{
|
|
||||||
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg',
|
|
||||||
type: 'audio/ogg',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case types.youtube:
|
|
||||||
player.source = {
|
|
||||||
type: 'video',
|
|
||||||
sources: [
|
|
||||||
{
|
|
||||||
src: 'https://youtube.com/watch?v=bTqVqk7FSmY',
|
|
||||||
provider: 'youtube',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
case types.vimeo:
|
|
||||||
player.source = {
|
|
||||||
type: 'video',
|
|
||||||
sources: [
|
|
||||||
{
|
|
||||||
src: 'https://vimeo.com/76979871',
|
|
||||||
provider: 'vimeo',
|
|
||||||
},
|
|
||||||
],
|
|
||||||
};
|
|
||||||
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set the current type for next time
|
|
||||||
currentType = type;
|
|
||||||
|
|
||||||
|
function render(type) {
|
||||||
// Remove active classes
|
// Remove active classes
|
||||||
Array.from(buttons).forEach(button => toggleClass(button.parentElement, 'active', false));
|
Array.from(buttons).forEach(button => toggleClass(button.parentElement, 'active', false));
|
||||||
|
|
||||||
@@ -257,9 +85,31 @@ import Raven from 'raven-js';
|
|||||||
|
|
||||||
// Show cite
|
// Show cite
|
||||||
Array.from(document.querySelectorAll('.plyr__cite')).forEach(cite => {
|
Array.from(document.querySelectorAll('.plyr__cite')).forEach(cite => {
|
||||||
cite.setAttribute('hidden', '');
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
cite.hidden = true;
|
||||||
});
|
});
|
||||||
document.querySelector(`.plyr__cite--${type}`).removeAttribute('hidden');
|
|
||||||
|
document.querySelector(`.plyr__cite--${type}`).hidden = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set a new source
|
||||||
|
function setSource(type, init) {
|
||||||
|
// Bail if new type isn't known, it's the current type, or current type is empty (video is default) and new type is video
|
||||||
|
if (
|
||||||
|
!types.includes(type) ||
|
||||||
|
(!init && type === currentType) ||
|
||||||
|
(!currentType.length && type === 'video')
|
||||||
|
) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the new source
|
||||||
|
player.source = sources[type];
|
||||||
|
|
||||||
|
// Set the current type for next time
|
||||||
|
currentType = type;
|
||||||
|
|
||||||
|
render(type);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Bind to each button
|
// Bind to each button
|
||||||
@@ -267,7 +117,7 @@ import Raven from 'raven-js';
|
|||||||
button.addEventListener('click', () => {
|
button.addEventListener('click', () => {
|
||||||
const type = button.getAttribute('data-source');
|
const type = button.getAttribute('data-source');
|
||||||
|
|
||||||
newSource(type);
|
setSource(type);
|
||||||
|
|
||||||
if (historySupport) {
|
if (historySupport) {
|
||||||
window.history.pushState({ type }, '', `#${type}`);
|
window.history.pushState({ type }, '', `#${type}`);
|
||||||
@@ -277,59 +127,33 @@ import Raven from 'raven-js';
|
|||||||
|
|
||||||
// List for backwards/forwards
|
// List for backwards/forwards
|
||||||
window.addEventListener('popstate', event => {
|
window.addEventListener('popstate', event => {
|
||||||
if (event.state && 'type' in event.state) {
|
if (event.state && Object.keys(event.state).includes('type')) {
|
||||||
newSource(event.state.type);
|
setSource(event.state.type);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
// On load
|
// If there's no current type set, assume video
|
||||||
if (historySupport) {
|
if (hasCurrentType) {
|
||||||
const video = !currentType.length;
|
currentType = 'video';
|
||||||
|
|
||||||
// If there's no current type set, assume video
|
|
||||||
if (video) {
|
|
||||||
currentType = types.video;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Replace current history state
|
|
||||||
if (currentType in types) {
|
|
||||||
window.history.replaceState(
|
|
||||||
{
|
|
||||||
type: currentType,
|
|
||||||
},
|
|
||||||
'',
|
|
||||||
video ? '' : `#${currentType}`,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
// If it's not video, load the source
|
|
||||||
if (currentType !== types.video) {
|
|
||||||
newSource(currentType, true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Replace current history state
|
||||||
|
if (historySupport && types.includes(currentType)) {
|
||||||
|
window.history.replaceState({ type: currentType }, '', hasCurrentType ? '' : `#${currentType}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
// If it's not video, load the source
|
||||||
|
if (currentType !== 'video') {
|
||||||
|
setSource(currentType, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
render(currentType);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// Google analytics
|
// Raven / Sentry
|
||||||
// For demo site (https://plyr.io) only
|
// For demo site (https://plyr.io) only
|
||||||
/* eslint-disable */
|
if (env.prod) {
|
||||||
if (isLive) {
|
Raven.config('https://d4ad9866ad834437a4754e23937071e4@sentry.io/305555').install();
|
||||||
(function(i, s, o, g, r, a, m) {
|
|
||||||
i.GoogleAnalyticsObject = r;
|
|
||||||
i[r] =
|
|
||||||
i[r] ||
|
|
||||||
function() {
|
|
||||||
(i[r].q = i[r].q || []).push(arguments);
|
|
||||||
};
|
|
||||||
i[r].l = 1 * new Date();
|
|
||||||
a = s.createElement(o);
|
|
||||||
m = s.getElementsByTagName(o)[0];
|
|
||||||
a.async = 1;
|
|
||||||
a.src = g;
|
|
||||||
m.parentNode.insertBefore(a, m);
|
|
||||||
})(window, document, 'script', 'https://www.google-analytics.com/analytics.js', 'ga');
|
|
||||||
window.ga('create', 'UA-40881672-11', 'auto');
|
|
||||||
window.ga('send', 'pageview');
|
|
||||||
}
|
}
|
||||||
/* eslint-enable */
|
|
||||||
})();
|
})();
|
||||||
|
|||||||
@@ -0,0 +1,78 @@
|
|||||||
|
const sources = {
|
||||||
|
video: {
|
||||||
|
type: 'video',
|
||||||
|
title: 'View From A Blue Moon',
|
||||||
|
sources: [
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-576p.mp4',
|
||||||
|
type: 'video/mp4',
|
||||||
|
size: 576,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-720p.mp4',
|
||||||
|
type: 'video/mp4',
|
||||||
|
size: 720,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1080p.mp4',
|
||||||
|
type: 'video/mp4',
|
||||||
|
size: 1080,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-1440p.mp4',
|
||||||
|
type: 'video/mp4',
|
||||||
|
size: 1440,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
poster: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.jpg',
|
||||||
|
tracks: [
|
||||||
|
{
|
||||||
|
kind: 'captions',
|
||||||
|
label: 'English',
|
||||||
|
srclang: 'en',
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.en.vtt',
|
||||||
|
default: true,
|
||||||
|
},
|
||||||
|
{
|
||||||
|
kind: 'captions',
|
||||||
|
label: 'French',
|
||||||
|
srclang: 'fr',
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/View_From_A_Blue_Moon_Trailer-HD.fr.vtt',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
audio: {
|
||||||
|
type: 'audio',
|
||||||
|
title: 'Kishi Bashi – “It All Began With A Burst”',
|
||||||
|
sources: [
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.mp3',
|
||||||
|
type: 'audio/mp3',
|
||||||
|
},
|
||||||
|
{
|
||||||
|
src: 'https://cdn.plyr.io/static/demo/Kishi_Bashi_-_It_All_Began_With_a_Burst.ogg',
|
||||||
|
type: 'audio/ogg',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
youtube: {
|
||||||
|
type: 'video',
|
||||||
|
sources: [
|
||||||
|
{
|
||||||
|
src: 'https://youtube.com/watch?v=bTqVqk7FSmY',
|
||||||
|
provider: 'youtube',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
vimeo: {
|
||||||
|
type: 'video',
|
||||||
|
sources: [
|
||||||
|
{
|
||||||
|
src: 'https://vimeo.com/76979871',
|
||||||
|
provider: 'vimeo',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
export default sources;
|
||||||
@@ -0,0 +1,31 @@
|
|||||||
|
// Setup tab focus
|
||||||
|
const container = document.getElementById('container');
|
||||||
|
const tabClassName = 'tab-focus';
|
||||||
|
|
||||||
|
// Remove class on blur
|
||||||
|
document.addEventListener('focusout', event => {
|
||||||
|
if (!event.target.classList || container.contains(event.target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
event.target.classList.remove(tabClassName);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Add classname to tabbed elements
|
||||||
|
document.addEventListener('keydown', event => {
|
||||||
|
if (event.keyCode !== 9) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Delay the adding of classname until the focus has changed
|
||||||
|
// This event fires before the focusin event
|
||||||
|
setTimeout(() => {
|
||||||
|
const focused = document.activeElement;
|
||||||
|
|
||||||
|
if (!focused || !focused.classList || container.contains(focused)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
focused.classList.add(tabClassName);
|
||||||
|
}, 10);
|
||||||
|
});
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
// Toggle class on an element
|
||||||
|
const toggleClass = (element, className = '', toggle = false) =>
|
||||||
|
element && element.classList[toggle ? 'add' : 'remove'](className);
|
||||||
|
|
||||||
|
export default toggleClass;
|
||||||
@@ -6,11 +6,9 @@
|
|||||||
.button,
|
.button,
|
||||||
.button__count {
|
.button__count {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: $color-button-background;
|
|
||||||
border: 0;
|
border: 0;
|
||||||
border-radius: $border-radius-base;
|
border-radius: $border-radius-base;
|
||||||
box-shadow: 0 1px 1px rgba(#000, 0.1);
|
box-shadow: 0 1px 1px rgba(#000, 0.1);
|
||||||
color: $color-button-text;
|
|
||||||
display: inline-flex;
|
display: inline-flex;
|
||||||
padding: ($spacing-base * 0.75);
|
padding: ($spacing-base * 0.75);
|
||||||
position: relative;
|
position: relative;
|
||||||
@@ -21,14 +19,16 @@
|
|||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
.button {
|
.button {
|
||||||
|
background: $color-button-background;
|
||||||
|
color: $color-button-text;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
padding-left: $spacing-base;
|
padding-left: ($spacing-base * 1.25);
|
||||||
padding-right: $spacing-base;
|
padding-right: ($spacing-base * 1.25);
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
|
|
||||||
&:hover,
|
&:hover,
|
||||||
&:focus {
|
&:focus {
|
||||||
color: $gray-dark;
|
background: $color-button-background-hover;
|
||||||
|
|
||||||
// Remove the underline/border
|
// Remove the underline/border
|
||||||
&::after {
|
&::after {
|
||||||
@@ -38,7 +38,6 @@
|
|||||||
|
|
||||||
&:hover {
|
&:hover {
|
||||||
box-shadow: 0 2px 2px rgba(#000, 0.1);
|
box-shadow: 0 2px 2px rgba(#000, 0.1);
|
||||||
transform: translateY(-1px);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
&:focus {
|
&:focus {
|
||||||
@@ -50,7 +49,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
&:active {
|
&:active {
|
||||||
transform: translateY(1px);
|
top: 1px;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,12 +65,14 @@
|
|||||||
// Count bubble
|
// Count bubble
|
||||||
.button__count {
|
.button__count {
|
||||||
animation: fadein 0.2s ease;
|
animation: fadein 0.2s ease;
|
||||||
margin-left: ($spacing-base / 2);
|
background: $color-button-count-background;
|
||||||
|
color: $color-button-count-text;
|
||||||
|
margin-left: ($spacing-base * 0.75);
|
||||||
|
|
||||||
&::before {
|
&::before {
|
||||||
border: $arrow-size solid transparent;
|
border: $arrow-size solid transparent;
|
||||||
border-left-width: 0;
|
border-left-width: 0;
|
||||||
border-right-color: $color-button-background;
|
border-right-color: $color-button-count-background;
|
||||||
content: '';
|
content: '';
|
||||||
height: 0;
|
height: 0;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
|
|||||||
@@ -6,6 +6,13 @@ header {
|
|||||||
padding-bottom: $spacing-base;
|
padding-bottom: $spacing-base;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
|
|
||||||
|
h1 span {
|
||||||
|
animation: shrinkHide 1s cubic-bezier(0.175, 0.885, 0.32, 1.275) 2s forwards;
|
||||||
|
display: inline-block;
|
||||||
|
font-weight: $font-weight-light;
|
||||||
|
opacity: 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
.call-to-action {
|
.call-to-action {
|
||||||
margin-top: ($spacing-base * 1.5);
|
margin-top: ($spacing-base * 1.5);
|
||||||
}
|
}
|
||||||
@@ -15,5 +22,9 @@ header {
|
|||||||
max-width: 360px;
|
max-width: 360px;
|
||||||
padding-bottom: ($spacing-base * 2);
|
padding-bottom: ($spacing-base * 2);
|
||||||
text-align: left;
|
text-align: left;
|
||||||
|
|
||||||
|
p:first-of-type {
|
||||||
|
@include font-size($font-size-base + 1);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,5 +19,5 @@ label svg {
|
|||||||
|
|
||||||
a .icon,
|
a .icon,
|
||||||
.btn .icon {
|
.btn .icon {
|
||||||
margin-right: floor($spacing-base / 3);
|
margin-right: ($spacing-base / 2);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,6 @@ button.faux-link {
|
|||||||
a {
|
a {
|
||||||
border-bottom: 1px dotted currentColor;
|
border-bottom: 1px dotted currentColor;
|
||||||
color: $color-link;
|
color: $color-link;
|
||||||
font-weight: $font-weight-bold;
|
|
||||||
position: relative;
|
position: relative;
|
||||||
text-decoration: none;
|
text-decoration: none;
|
||||||
transition: all 0.2s ease;
|
transition: all 0.2s ease;
|
||||||
|
|||||||
@@ -2,16 +2,10 @@
|
|||||||
// Examples
|
// Examples
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// For non supported browsers
|
|
||||||
video {
|
|
||||||
max-width: 100%;
|
|
||||||
vertical-align: middle;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Example players
|
// Example players
|
||||||
.plyr {
|
.plyr {
|
||||||
border-radius: $border-radius-base;
|
border-radius: $border-radius-base;
|
||||||
box-shadow: 0 2px 5px rgba(#000, 0.2);
|
box-shadow: 0 2px 15px rgba(#000, 0.1);
|
||||||
margin: $spacing-base auto;
|
margin: $spacing-base auto;
|
||||||
|
|
||||||
&.plyr--audio {
|
&.plyr--audio {
|
||||||
@@ -34,17 +28,9 @@ video {
|
|||||||
|
|
||||||
// Style full supported player
|
// Style full supported player
|
||||||
.plyr__cite {
|
.plyr__cite {
|
||||||
display: none;
|
color: $color-gray-5;
|
||||||
margin-top: $spacing-base;
|
|
||||||
|
|
||||||
.icon {
|
.icon {
|
||||||
margin-right: ceil($spacing-base / 6);
|
margin-right: ceil($spacing-base / 6);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.plyr--video:not(.plyr--youtube):not(.plyr--vimeo) ~ ul .plyr__cite--video,
|
|
||||||
.plyr--audio ~ ul .plyr__cite--audio,
|
|
||||||
.plyr--youtube ~ ul .plyr__cite--youtube,
|
|
||||||
.plyr--vimeo ~ ul .plyr__cite--vimeo {
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -35,11 +35,10 @@ main {
|
|||||||
aside {
|
aside {
|
||||||
align-items: center;
|
align-items: center;
|
||||||
background: #fff;
|
background: #fff;
|
||||||
color: $gray;
|
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
padding: ($spacing-base * 0.75);
|
padding: $spacing-base;
|
||||||
position: relative;
|
position: relative;
|
||||||
text-align: center;
|
text-align: center;
|
||||||
text-shadow: none;
|
text-shadow: none;
|
||||||
|
|||||||
@@ -11,3 +11,17 @@
|
|||||||
opacity: 1;
|
opacity: 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@keyframes shrinkHide {
|
||||||
|
0% {
|
||||||
|
opacity: 0.5;
|
||||||
|
width: 38px;
|
||||||
|
}
|
||||||
|
20% {
|
||||||
|
width: 45px;
|
||||||
|
}
|
||||||
|
100% {
|
||||||
|
opacity: 0;
|
||||||
|
width: 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -7,7 +7,8 @@
|
|||||||
font-family: 'Gordita';
|
font-family: 'Gordita';
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-light;
|
font-weight: $font-weight-light;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-light.woff2') format('woff2'), url('https://cdn.plyr.io/static/fonts/gordita-light.woff') format('woff');
|
src: url('https://cdn.plyr.io/static/fonts/gordita-light.woff2') format('woff2'),
|
||||||
|
url('https://cdn.plyr.io/static/fonts/gordita-light.woff') format('woff');
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
@@ -33,7 +34,8 @@
|
|||||||
font-family: 'Gordita';
|
font-family: 'Gordita';
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-bold.woff2') format('woff2'), url('https://cdn.plyr.io/static/fonts/gordita-bold.woff') format('woff');
|
src: url('https://cdn.plyr.io/static/fonts/gordita-bold.woff2') format('woff2'),
|
||||||
|
url('https://cdn.plyr.io/static/fonts/gordita-bold.woff') format('woff');
|
||||||
}
|
}
|
||||||
|
|
||||||
@font-face {
|
@font-face {
|
||||||
@@ -41,5 +43,6 @@
|
|||||||
font-family: 'Gordita';
|
font-family: 'Gordita';
|
||||||
font-style: normal;
|
font-style: normal;
|
||||||
font-weight: $font-weight-black;
|
font-weight: $font-weight-black;
|
||||||
src: url('https://cdn.plyr.io/static/fonts/gordita-black.woff2') format('woff2'), url('https://cdn.plyr.io/static/fonts/gordita-black.woff') format('woff');
|
src: url('https://cdn.plyr.io/static/fonts/gordita-black.woff2') format('woff2'),
|
||||||
|
url('https://cdn.plyr.io/static/fonts/gordita-black.woff') format('woff');
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@
|
|||||||
@return #{$rem}rem;
|
@return #{$rem}rem;
|
||||||
}
|
}
|
||||||
|
|
||||||
@mixin font-size($size: 16) {
|
@mixin font-size($size: $font-size-base) {
|
||||||
font-size: $size * 1px; // Fallback in px
|
font-size: $size * 1px; // Fallback in px
|
||||||
font-size: calculate-rem($size);
|
font-size: calculate-rem($size);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,31 +2,41 @@
|
|||||||
// Colors
|
// Colors
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
// Greyscale
|
// Grayscale
|
||||||
$gray-dark: #343f4a;
|
$color-gray-9: hsl(210, 15%, 16%);
|
||||||
$gray: #55646b;
|
$color-gray-8: lighten($color-gray-9, 9%);
|
||||||
$gray-light: #cbd0d3;
|
$color-gray-7: lighten($color-gray-8, 9%);
|
||||||
$gray-lighter: #dbe3e8;
|
$color-gray-6: lighten($color-gray-7, 9%);
|
||||||
$off-white: #f2f5f7;
|
$color-gray-5: lighten($color-gray-6, 9%);
|
||||||
|
$color-gray-4: lighten($color-gray-5, 9%);
|
||||||
|
$color-gray-3: lighten($color-gray-4, 9%);
|
||||||
|
$color-gray-2: lighten($color-gray-3, 9%);
|
||||||
|
$color-gray-1: lighten($color-gray-2, 9%);
|
||||||
|
$color-gray-0: lighten($color-gray-1, 9%);
|
||||||
|
|
||||||
|
// Branding
|
||||||
|
$color-brand-primary: hsl(198, 100%, 50%);
|
||||||
|
|
||||||
// Text
|
// Text
|
||||||
$color-text: #fff;
|
$color-text: $color-gray-7;
|
||||||
|
$color-headings: $color-brand-primary;
|
||||||
// Plyr
|
|
||||||
$color-brand-primary: #1aafff;
|
|
||||||
|
|
||||||
// Brands
|
// Brands
|
||||||
$color-twitter: #4baaf4;
|
$color-twitter: #4baaf4;
|
||||||
$color-youtube: #cc181e;
|
|
||||||
$color-vimeo: #19b7ed;
|
|
||||||
|
|
||||||
// Elements
|
// Elements
|
||||||
$color-link: #fff;
|
$color-link: $color-brand-primary;
|
||||||
$color-background: $color-brand-primary;
|
|
||||||
|
// Background
|
||||||
|
$color-background-from: hsl(198, 100%, 94%);
|
||||||
|
$color-background-to: hsl(198, 100%, 98%);
|
||||||
|
|
||||||
// Buttons
|
// Buttons
|
||||||
$color-button-background: #fff;
|
$color-button-background: $color-brand-primary;
|
||||||
$color-button-text: $gray;
|
$color-button-text: #fff;
|
||||||
|
$color-button-background-hover: hsl(198, 100%, 55%);
|
||||||
|
$color-button-count-background: #fff;
|
||||||
|
$color-button-count-text: $color-gray-6;
|
||||||
|
|
||||||
// Focus
|
// Focus
|
||||||
$tab-focus-default-color: #fff;
|
$tab-focus-default-color: #fff;
|
||||||
|
|||||||
@@ -9,4 +9,4 @@ $arrow-size: 5px;
|
|||||||
$border-radius-base: 4px;
|
$border-radius-base: 4px;
|
||||||
|
|
||||||
// Background
|
// Background
|
||||||
$page-background: linear-gradient(to left top, lighten($color-background, 10%), darken($color-background, 20%));
|
$page-background: linear-gradient(to left top, $color-background-from, $color-background-to);
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ $plyr-font-size-small: 12px;
|
|||||||
$plyr-font-size-time: 11px;
|
$plyr-font-size-time: 11px;
|
||||||
$plyr-font-size-badges: 9px;
|
$plyr-font-size-badges: 9px;
|
||||||
|
|
||||||
|
// Other
|
||||||
|
$plyr-font-smoothing: true;
|
||||||
|
|
||||||
|
// Colors
|
||||||
|
$plyr-color-main: $color-brand-primary;
|
||||||
|
|
||||||
// Captions
|
// Captions
|
||||||
$plyr-font-size-captions-base: $plyr-font-size-base;
|
$plyr-font-size-captions-base: $plyr-font-size-base;
|
||||||
$plyr-font-size-captions-small: $plyr-font-size-small;
|
$plyr-font-size-captions-small: $plyr-font-size-small;
|
||||||
|
|||||||
@@ -2,4 +2,4 @@
|
|||||||
// Colors
|
// Colors
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
$spacing-base: 20px;
|
$spacing-base: 16px;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@
|
|||||||
// Typography
|
// Typography
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
$font-sans-serif: 'Gordita', 'Avenir', 'Helvetica Neue', sans-serif;
|
$font-sans-serif: 'Gordita', 'Avenir', 'Helvetica Neue', sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji',
|
||||||
|
'Segoe UI Symbol';
|
||||||
|
|
||||||
$font-size-base: 15;
|
$font-size-base: 15;
|
||||||
$font-size-small: 13;
|
$font-size-small: 13;
|
||||||
|
|||||||
@@ -14,7 +14,6 @@ body {
|
|||||||
font-family: $font-sans-serif;
|
font-family: $font-sans-serif;
|
||||||
font-weight: $font-weight-medium;
|
font-weight: $font-weight-medium;
|
||||||
line-height: $line-height-base;
|
line-height: $line-height-base;
|
||||||
text-shadow: 0 1px 1px rgba(#000, 0.15);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
button,
|
button,
|
||||||
@@ -26,7 +25,7 @@ textarea {
|
|||||||
|
|
||||||
p,
|
p,
|
||||||
small {
|
small {
|
||||||
margin: 0 0 $spacing-base;
|
margin: 0 0 ($spacing-base * 1.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
small {
|
small {
|
||||||
|
|||||||
@@ -4,8 +4,9 @@
|
|||||||
|
|
||||||
h1 {
|
h1 {
|
||||||
@include font-size($font-size-h1);
|
@include font-size($font-size-h1);
|
||||||
|
color: $color-headings;
|
||||||
font-weight: $font-weight-bold;
|
font-weight: $font-weight-bold;
|
||||||
letter-spacing: $letter-spacing-headings;
|
letter-spacing: $letter-spacing-headings;
|
||||||
line-height: 1.2;
|
line-height: 1.2;
|
||||||
margin: 0 0 $spacing-base;
|
margin: 0 0 ($spacing-base * 1.5);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,28 @@
|
|||||||
|
# THIS IS AN AUTOGENERATED FILE. DO NOT EDIT THIS FILE DIRECTLY.
|
||||||
|
# yarn lockfile v1
|
||||||
|
|
||||||
|
|
||||||
|
core-js@^3.1.3:
|
||||||
|
version "3.1.3"
|
||||||
|
resolved "https://registry.yarnpkg.com/core-js/-/core-js-3.1.3.tgz#95700bca5f248f5f78c0ec63e784eca663ec4138"
|
||||||
|
integrity sha512-PWZ+ZfuaKf178BIAg+CRsljwjIMRV8MY00CbZczkR6Zk5LfkSkjGoaab3+bqRQWVITNZxQB7TFYz+CFcyuamvA==
|
||||||
|
|
||||||
|
custom-event-polyfill@^1.0.7:
|
||||||
|
version "1.0.7"
|
||||||
|
resolved "https://registry.yarnpkg.com/custom-event-polyfill/-/custom-event-polyfill-1.0.7.tgz#9bc993ddda937c1a30ccd335614c6c58c4f87aee"
|
||||||
|
integrity sha512-TDDkd5DkaZxZFM8p+1I3yAlvM3rSr1wbrOliG4yJiwinMZN8z/iGL7BTlDkrJcYTmgUSb4ywVCc3ZaUtOtC76w==
|
||||||
|
|
||||||
|
raven-js@^3.27.1:
|
||||||
|
version "3.27.1"
|
||||||
|
resolved "https://registry.yarnpkg.com/raven-js/-/raven-js-3.27.1.tgz#e187a12982061908ccbf935af0640c9043d7d666"
|
||||||
|
integrity sha512-r/9CwSbaGfBFjo4hGR45DAmrukUKkQ4HdMu80PlVLDY1t8f9b4aaZzTsFegaafu7EGhEYougWDJ9/IcTdYdLXQ==
|
||||||
|
|
||||||
|
shr-buttons@2.0.2:
|
||||||
|
version "2.0.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/shr-buttons/-/shr-buttons-2.0.2.tgz#a3c11b36067b8902afbff9845d0e023f9f76865f"
|
||||||
|
integrity sha512-UYaZjF5FK1NZrXjQF8YkWOzxM7Z210lv3TDsFMTTp7hbJrdybNPF4WX4k5a+dW25R97FMBZaSnMWvI9TpuCCoA==
|
||||||
|
|
||||||
|
url-polyfill@^1.1.5:
|
||||||
|
version "1.1.5"
|
||||||
|
resolved "https://registry.yarnpkg.com/url-polyfill/-/url-polyfill-1.1.5.tgz#bec79b72b5407dba6d8cced2e32e4ab273aa9fb1"
|
||||||
|
integrity sha512-9XjIJ6nwrU+nGd8t90Ze0Zs7t8A+SU0gqsqPttj6j3zAVe5q0HFcuv37nDBdVSPpi4aTHTfbUF/i+ZVD+o2EbA==
|
||||||
+12
@@ -0,0 +1,12 @@
|
|||||||
|
{
|
||||||
|
"cdn": {
|
||||||
|
"bucket": "plyr",
|
||||||
|
"domain": "cdn.plyr.io",
|
||||||
|
"region": "us-east-1"
|
||||||
|
},
|
||||||
|
"demo": {
|
||||||
|
"bucket": "plyr.io",
|
||||||
|
"domain": "plyr.io",
|
||||||
|
"region": "us-west-1"
|
||||||
|
}
|
||||||
|
}
|
||||||
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+8925
-7965
File diff suppressed because it is too large
Load Diff
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+9123
File diff suppressed because it is too large
Load Diff
Vendored
+14824
-13338
File diff suppressed because it is too large
Load Diff
Vendored
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
-1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+1
File diff suppressed because one or more lines are too long
Vendored
+15031
File diff suppressed because it is too large
Load Diff
Vendored
+1
-1
File diff suppressed because one or more lines are too long
|
Before Width: | Height: | Size: 4.9 KiB After Width: | Height: | Size: 5.4 KiB |
+412
-339
@@ -4,417 +4,490 @@
|
|||||||
/* global require, __dirname */
|
/* global require, __dirname */
|
||||||
/* eslint no-console: "off" */
|
/* eslint no-console: "off" */
|
||||||
|
|
||||||
const del = require('del');
|
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const gulp = require('gulp');
|
const gulp = require('gulp');
|
||||||
const gutil = require('gulp-util');
|
// ------------------------------------
|
||||||
const concat = require('gulp-concat');
|
// JavaScript
|
||||||
const filter = require('gulp-filter');
|
// ------------------------------------
|
||||||
const sass = require('gulp-sass');
|
const terser = require('gulp-terser');
|
||||||
const cleancss = require('gulp-clean-css');
|
|
||||||
const run = require('run-sequence');
|
|
||||||
const header = require('gulp-header');
|
|
||||||
const prefix = require('gulp-autoprefixer');
|
|
||||||
const gitbranch = require('git-branch');
|
|
||||||
const svgstore = require('gulp-svgstore');
|
|
||||||
const svgmin = require('gulp-svgmin');
|
|
||||||
const rename = require('gulp-rename');
|
|
||||||
const s3 = require('gulp-s3');
|
|
||||||
const replace = require('gulp-replace');
|
|
||||||
const open = require('gulp-open');
|
|
||||||
const size = require('gulp-size');
|
|
||||||
const rollup = require('gulp-better-rollup');
|
const rollup = require('gulp-better-rollup');
|
||||||
const babel = require('rollup-plugin-babel');
|
const babel = require('rollup-plugin-babel');
|
||||||
const sourcemaps = require('gulp-sourcemaps');
|
|
||||||
const uglify = require('gulp-uglify-es').default;
|
|
||||||
const commonjs = require('rollup-plugin-commonjs');
|
const commonjs = require('rollup-plugin-commonjs');
|
||||||
const resolve = require('rollup-plugin-node-resolve');
|
const resolve = require('rollup-plugin-node-resolve');
|
||||||
|
// ------------------------------------
|
||||||
const bundles = require('./bundles.json');
|
// CSS
|
||||||
|
// ------------------------------------
|
||||||
|
const sass = require('gulp-sass');
|
||||||
|
const clean = require('gulp-clean-css');
|
||||||
|
const prefix = require('gulp-autoprefixer');
|
||||||
|
// ------------------------------------
|
||||||
|
// Images
|
||||||
|
// ------------------------------------
|
||||||
|
const svgstore = require('gulp-svgstore');
|
||||||
|
const imagemin = require('gulp-imagemin');
|
||||||
|
// ------------------------------------
|
||||||
|
// Utils
|
||||||
|
// ------------------------------------
|
||||||
|
const del = require('del');
|
||||||
|
const filter = require('gulp-filter');
|
||||||
|
const header = require('gulp-header');
|
||||||
|
const gitbranch = require('git-branch');
|
||||||
|
const rename = require('gulp-rename');
|
||||||
|
const replace = require('gulp-replace');
|
||||||
|
const ansi = require('ansi-colors');
|
||||||
|
const log = require('fancy-log');
|
||||||
|
const open = require('gulp-open');
|
||||||
|
const plumber = require('gulp-plumber');
|
||||||
|
const size = require('gulp-size');
|
||||||
|
const sourcemaps = require('gulp-sourcemaps');
|
||||||
|
const through = require('through2');
|
||||||
|
// ------------------------------------
|
||||||
|
// Deployment
|
||||||
|
// ------------------------------------
|
||||||
|
const aws = require('aws-sdk');
|
||||||
|
const publish = require('gulp-awspublish');
|
||||||
|
const FastlyPurge = require('fastly-purge');
|
||||||
|
// ------------------------------------
|
||||||
|
// Configs
|
||||||
|
// ------------------------------------
|
||||||
const pkg = require('./package.json');
|
const pkg = require('./package.json');
|
||||||
|
const build = require('./build.json');
|
||||||
// Get AWS config
|
const deploy = require('./deploy.json');
|
||||||
let aws = {};
|
// ------------------------------------
|
||||||
try {
|
// Info from package
|
||||||
aws = require('./aws.json'); //eslint-disable-line
|
// ------------------------------------
|
||||||
} catch (e) {
|
const { browserslist: browsers, version } = pkg;
|
||||||
// Do nothing
|
|
||||||
}
|
|
||||||
|
|
||||||
const minSuffix = '.min';
|
const minSuffix = '.min';
|
||||||
|
|
||||||
|
// Get AWS config
|
||||||
|
Object.values(deploy).forEach(target => {
|
||||||
|
Object.assign(target, {
|
||||||
|
publisher: publish.create({
|
||||||
|
region: target.region,
|
||||||
|
params: {
|
||||||
|
Bucket: target.bucket,
|
||||||
|
},
|
||||||
|
credentials: new aws.SharedIniFileCredentials({ profile: 'plyr' }),
|
||||||
|
}),
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
// Paths
|
// Paths
|
||||||
const root = __dirname;
|
|
||||||
const paths = {
|
const paths = {
|
||||||
plyr: {
|
plyr: {
|
||||||
// Source paths
|
// Source paths
|
||||||
src: {
|
src: {
|
||||||
sass: path.join(root, 'src/sass/**/*.scss'),
|
sass: path.join(__dirname, 'src/sass/**/*.scss'),
|
||||||
js: path.join(root, 'src/js/**/*'),
|
js: path.join(__dirname, 'src/js/**/*.js'),
|
||||||
sprite: path.join(root, 'src/sprite/*.svg'),
|
sprite: path.join(__dirname, 'src/sprite/*.svg'),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Output paths
|
// Output paths
|
||||||
output: path.join(root, 'dist/'),
|
output: path.join(__dirname, 'dist/'),
|
||||||
},
|
},
|
||||||
demo: {
|
demo: {
|
||||||
// Source paths
|
// Source paths
|
||||||
src: {
|
src: {
|
||||||
sass: path.join(root, 'demo/src/sass/**/*.scss'),
|
sass: path.join(__dirname, 'demo/src/sass/**/*.scss'),
|
||||||
js: path.join(root, 'demo/src/js/**/*'),
|
js: path.join(__dirname, 'demo/src/js/**/*.js'),
|
||||||
},
|
},
|
||||||
|
|
||||||
// Output paths
|
// Output paths
|
||||||
output: path.join(root, 'demo/dist/'),
|
output: path.join(__dirname, 'demo/dist/'),
|
||||||
|
|
||||||
// Demo
|
// Demo
|
||||||
root: path.join(root, 'demo/'),
|
root: path.join(__dirname, 'demo/'),
|
||||||
},
|
},
|
||||||
upload: [
|
upload: [
|
||||||
path.join(root, `dist/*${minSuffix}.*`),
|
path.join(__dirname, `dist/*${minSuffix}.*`),
|
||||||
path.join(root, 'dist/*.css'),
|
path.join(__dirname, 'dist/*.css'),
|
||||||
path.join(root, 'dist/*.svg'),
|
path.join(__dirname, 'dist/*.svg'),
|
||||||
path.join(root, `demo/dist/*${minSuffix}.*`),
|
path.join(__dirname, `demo/dist/*${minSuffix}.*`),
|
||||||
path.join(root, 'demo/dist/*.css'),
|
path.join(__dirname, 'demo/dist/*.css'),
|
||||||
|
path.join(__dirname, 'demo/dist/*.svg'),
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
||||||
// Task arrays
|
// Task arrays
|
||||||
const tasks = {
|
const tasks = {
|
||||||
sass: [],
|
css: [],
|
||||||
js: [],
|
js: [],
|
||||||
sprite: [],
|
sprite: [],
|
||||||
clean: ['clean'],
|
clean: 'clean',
|
||||||
};
|
};
|
||||||
|
|
||||||
// Size plugin
|
// Size plugin
|
||||||
const sizeOptions = { showFiles: true, gzip: true };
|
const sizeOptions = { showFiles: true, gzip: true };
|
||||||
|
|
||||||
// Browserlist
|
|
||||||
const browsers = ['> 1%'];
|
|
||||||
|
|
||||||
// Babel config
|
|
||||||
const babelrc = {
|
|
||||||
presets: [[
|
|
||||||
'env',
|
|
||||||
{
|
|
||||||
targets: {
|
|
||||||
browsers,
|
|
||||||
},
|
|
||||||
useBuiltIns: true,
|
|
||||||
modules: false,
|
|
||||||
},
|
|
||||||
]],
|
|
||||||
plugins: ['external-helpers'],
|
|
||||||
babelrc: false,
|
|
||||||
exclude: 'node_modules/**',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Clean out /dist
|
// Clean out /dist
|
||||||
gulp.task('clean', () => {
|
gulp.task(tasks.clean, done => {
|
||||||
const dirs = [
|
const dirs = [paths.plyr.output, paths.demo.output].map(dir => path.join(dir, '**/*'));
|
||||||
paths.plyr.output,
|
|
||||||
paths.demo.output,
|
|
||||||
].map(dir => path.join(dir, '**/*'));
|
|
||||||
|
|
||||||
// Don't delete the mp4
|
// Don't delete the mp4
|
||||||
dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
|
dirs.push(`!${path.join(paths.plyr.output, '**/*.mp4')}`);
|
||||||
|
|
||||||
del(dirs);
|
del(dirs);
|
||||||
|
|
||||||
|
done();
|
||||||
});
|
});
|
||||||
|
|
||||||
const build = {
|
// JavaScript
|
||||||
js(files, bundle, options) {
|
Object.entries(build.js).forEach(([filename, entry]) => {
|
||||||
Object.keys(files).forEach(key => {
|
const { dist, formats, namespace, polyfill, src } = entry;
|
||||||
const name = `js:${key}`;
|
|
||||||
tasks.js.push(name);
|
|
||||||
const { output } = paths[bundle];
|
|
||||||
|
|
||||||
return gulp.task(name, () =>
|
formats.forEach(format => {
|
||||||
gulp
|
const name = `js:${filename}:${format}`;
|
||||||
.src(bundles[bundle].js[key])
|
const extension = format === 'es' ? 'mjs' : 'js';
|
||||||
.pipe(sourcemaps.init())
|
tasks.js.push(name);
|
||||||
.pipe(concat(key))
|
|
||||||
.pipe(
|
|
||||||
rollup(
|
|
||||||
{
|
|
||||||
plugins: [
|
|
||||||
resolve(),
|
|
||||||
commonjs(),
|
|
||||||
babel(babelrc),
|
|
||||||
],
|
|
||||||
},
|
|
||||||
options,
|
|
||||||
),
|
|
||||||
)
|
|
||||||
.pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
|
|
||||||
.pipe(sourcemaps.write(''))
|
|
||||||
.pipe(gulp.dest(output))
|
|
||||||
.pipe(filter('**/*.js'))
|
|
||||||
.pipe(uglify())
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(rename({ suffix: minSuffix }))
|
|
||||||
.pipe(sourcemaps.write(''))
|
|
||||||
.pipe(gulp.dest(output)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
sass(files, bundle) {
|
|
||||||
Object.keys(files).forEach(key => {
|
|
||||||
const name = `sass:${key}`;
|
|
||||||
tasks.sass.push(name);
|
|
||||||
|
|
||||||
return gulp.task(name, () =>
|
gulp.task(name, () =>
|
||||||
gulp
|
|
||||||
.src(bundles[bundle].sass[key])
|
|
||||||
.pipe(sass())
|
|
||||||
.on('error', gutil.log)
|
|
||||||
.pipe(concat(key))
|
|
||||||
.pipe(prefix(browsers, { cascade: false }))
|
|
||||||
.pipe(cleancss())
|
|
||||||
.pipe(size(sizeOptions))
|
|
||||||
.pipe(gulp.dest(paths[bundle].output)),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
},
|
|
||||||
sprite(bundle) {
|
|
||||||
const name = `svg:sprite:${bundle}`;
|
|
||||||
tasks.sprite.push(name);
|
|
||||||
|
|
||||||
// Process Icons
|
|
||||||
return gulp.task(name, () =>
|
|
||||||
gulp
|
gulp
|
||||||
.src(paths[bundle].src.sprite)
|
.src(src)
|
||||||
|
.pipe(plumber())
|
||||||
|
.pipe(sourcemaps.init())
|
||||||
.pipe(
|
.pipe(
|
||||||
svgmin({
|
rollup(
|
||||||
plugins: [{
|
{
|
||||||
removeDesc: true,
|
plugins: [
|
||||||
}],
|
resolve(),
|
||||||
|
commonjs(),
|
||||||
|
babel({
|
||||||
|
presets: [
|
||||||
|
[
|
||||||
|
'@babel/env',
|
||||||
|
{
|
||||||
|
// debug: true,
|
||||||
|
useBuiltIns: polyfill ? 'usage' : false,
|
||||||
|
corejs: polyfill ? 3 : undefined,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
babelrc: false,
|
||||||
|
exclude: [/\/core-js\//],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: namespace,
|
||||||
|
format,
|
||||||
|
},
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.pipe(header('typeof navigator === "object" && ')) // "Support" SSR (#935)
|
||||||
|
.pipe(
|
||||||
|
rename({
|
||||||
|
extname: `.${extension}`,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
.pipe(svgstore())
|
.pipe(gulp.dest(dist))
|
||||||
.pipe(rename({ basename: bundle }))
|
.pipe(filter(`**/*.${extension}`))
|
||||||
|
.pipe(terser())
|
||||||
|
.pipe(rename({ suffix: minSuffix }))
|
||||||
.pipe(size(sizeOptions))
|
.pipe(size(sizeOptions))
|
||||||
.pipe(gulp.dest(paths[bundle].output)),
|
.pipe(sourcemaps.write(''))
|
||||||
|
.pipe(gulp.dest(dist)),
|
||||||
);
|
);
|
||||||
},
|
});
|
||||||
};
|
});
|
||||||
|
|
||||||
// Plyr core files
|
// CSS
|
||||||
build.js(bundles.plyr.js, 'plyr', { name: 'Plyr', format: 'umd' });
|
Object.entries(build.css).forEach(([filename, entry]) => {
|
||||||
build.sass(bundles.plyr.sass, 'plyr');
|
const { dist, src } = entry;
|
||||||
build.sprite('plyr');
|
const name = `css:${filename}`;
|
||||||
|
tasks.css.push(name);
|
||||||
|
|
||||||
// Demo files
|
gulp.task(name, () =>
|
||||||
build.sass(bundles.demo.sass, 'demo');
|
gulp
|
||||||
build.js(bundles.demo.js, 'demo', { format: 'iife' });
|
.src(src)
|
||||||
|
.pipe(plumber())
|
||||||
|
.pipe(sass())
|
||||||
|
.pipe(
|
||||||
|
prefix(browsers, {
|
||||||
|
cascade: false,
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.pipe(clean())
|
||||||
|
.pipe(size(sizeOptions))
|
||||||
|
.pipe(gulp.dest(dist)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// SVG Sprites
|
||||||
|
Object.entries(build.sprite).forEach(([filename, entry]) => {
|
||||||
|
const { dist, src } = entry;
|
||||||
|
const name = `sprite:${filename}`;
|
||||||
|
tasks.sprite.push(name);
|
||||||
|
|
||||||
|
gulp.task(name, () =>
|
||||||
|
gulp
|
||||||
|
.src(src)
|
||||||
|
.pipe(plumber())
|
||||||
|
.pipe(imagemin())
|
||||||
|
.pipe(svgstore())
|
||||||
|
.pipe(rename({ basename: path.parse(filename).name }))
|
||||||
|
.pipe(size(sizeOptions))
|
||||||
|
.pipe(gulp.dest(dist)),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
// Build all JS
|
// Build all JS
|
||||||
gulp.task('js', () => {
|
gulp.task('js', () => gulp.parallel(...tasks.js));
|
||||||
run(tasks.js);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch for file changes
|
// Watch for file changes
|
||||||
gulp.task('watch', () => {
|
gulp.task('watch', () => {
|
||||||
// Plyr core
|
// Plyr core
|
||||||
gulp.watch(paths.plyr.src.js, tasks.js);
|
gulp.watch(paths.plyr.src.js, gulp.parallel(...tasks.js));
|
||||||
gulp.watch(paths.plyr.src.sass, tasks.sass);
|
gulp.watch(paths.plyr.src.sass, gulp.parallel(...tasks.css));
|
||||||
gulp.watch(paths.plyr.src.sprite, tasks.sprite);
|
gulp.watch(paths.plyr.src.sprite, gulp.parallel(...tasks.sprite));
|
||||||
|
|
||||||
// Demo
|
// Demo
|
||||||
gulp.watch(paths.demo.src.js, tasks.js);
|
gulp.watch(paths.demo.src.js, gulp.parallel(...tasks.js));
|
||||||
gulp.watch(paths.demo.src.sass, tasks.sass);
|
gulp.watch(paths.demo.src.sass, gulp.parallel(...tasks.css));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Build distribution
|
// Build distribution
|
||||||
gulp.task('build', () => {
|
gulp.task('build', gulp.series(tasks.clean, gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite)));
|
||||||
run(tasks.clean, tasks.js, tasks.sass, tasks.sprite);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Default gulp task
|
// Default gulp task
|
||||||
gulp.task('default', () => {
|
gulp.task('default', gulp.series('build', 'watch'));
|
||||||
run('build', 'watch');
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish a version to CDN and demo
|
// Publish a version to CDN and demo
|
||||||
// --------------------------------------------
|
// --------------------------------------------
|
||||||
// If aws is setup
|
// Get deployment config
|
||||||
if (Object.keys(aws).includes('cdn') && Object.keys(aws).includes('demo')) {
|
let credentials = {};
|
||||||
const { version } = pkg;
|
try {
|
||||||
|
credentials = require('./credentials.json'); //eslint-disable-line
|
||||||
// Get branch info
|
} catch (e) {
|
||||||
const branch = {
|
// Do nothing
|
||||||
current: gitbranch.sync(),
|
|
||||||
master: 'master',
|
|
||||||
develop: 'develop',
|
|
||||||
};
|
|
||||||
const allowed = [
|
|
||||||
branch.master,
|
|
||||||
branch.develop,
|
|
||||||
];
|
|
||||||
|
|
||||||
const maxAge = 31536000; // 1 year
|
|
||||||
const options = {
|
|
||||||
cdn: {
|
|
||||||
headers: {
|
|
||||||
'Cache-Control': `max-age=${maxAge}`,
|
|
||||||
Vary: 'Accept-Encoding',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
demo: {
|
|
||||||
uploadPath: branch.current === branch.develop ? 'beta/' : null,
|
|
||||||
headers: {
|
|
||||||
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
|
||||||
Vary: 'Accept-Encoding',
|
|
||||||
},
|
|
||||||
},
|
|
||||||
symlinks(ver, filename) {
|
|
||||||
return {
|
|
||||||
headers: {
|
|
||||||
// http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
|
|
||||||
'x-amz-website-redirect-location': `/${ver}/${filename}`,
|
|
||||||
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
|
||||||
},
|
|
||||||
};
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
const regex = '(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
|
|
||||||
const semver = new RegExp(`v${regex}`, 'gi');
|
|
||||||
const localPath = new RegExp('(../)?dist', 'gi');
|
|
||||||
const versionPath = `https://${aws.cdn.domain}/${version}`;
|
|
||||||
const cdnpath = new RegExp(`${aws.cdn.domain}/${regex}/`, 'gi');
|
|
||||||
|
|
||||||
gulp.task('version', () => {
|
|
||||||
console.log(`Updating versions to '${version}'...`);
|
|
||||||
|
|
||||||
// Replace versioned URLs in source
|
|
||||||
const files = [
|
|
||||||
'plyr.js',
|
|
||||||
'plyr.polyfilled.js',
|
|
||||||
'defaults.js',
|
|
||||||
];
|
|
||||||
|
|
||||||
return gulp
|
|
||||||
.src(files.map(file => path.join(root, `src/js/${file}`)))
|
|
||||||
.pipe(replace(semver, `v${version}`))
|
|
||||||
.pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
|
|
||||||
.pipe(gulp.dest(path.join(root, 'src/js/')));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish version to CDN bucket
|
|
||||||
gulp.task('cdn', () => {
|
|
||||||
if (!allowed.includes(branch.current)) {
|
|
||||||
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Uploading '${version}' to ${aws.cdn.domain}...`);
|
|
||||||
|
|
||||||
// Upload to CDN
|
|
||||||
return (
|
|
||||||
gulp
|
|
||||||
.src(paths.upload)
|
|
||||||
.pipe(
|
|
||||||
rename(p => {
|
|
||||||
p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
|
|
||||||
p.dirname = p.dirname.replace('.', version); // eslint-disable-line
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
// Remove min suffix from source map URL
|
|
||||||
.pipe(replace(/sourceMappingURL=([\w-?.]+)/, (match, p1) => `sourceMappingURL=${p1.replace(minSuffix, '')}`))
|
|
||||||
.pipe(
|
|
||||||
size({
|
|
||||||
showFiles: true,
|
|
||||||
gzip: true,
|
|
||||||
}),
|
|
||||||
)
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(s3(aws.cdn, options.cdn))
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Publish to demo bucket
|
|
||||||
gulp.task('demo', () => {
|
|
||||||
if (!allowed.includes(branch.current)) {
|
|
||||||
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
console.log(`Uploading '${version}' demo to ${aws.demo.domain}...`);
|
|
||||||
|
|
||||||
// Replace versioned files in readme.md
|
|
||||||
gulp
|
|
||||||
.src([`${root}/readme.md`])
|
|
||||||
.pipe(replace(cdnpath, `${aws.cdn.domain}/${version}/`))
|
|
||||||
.pipe(gulp.dest(root));
|
|
||||||
|
|
||||||
// Replace local file paths with remote paths in demo HTML
|
|
||||||
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
|
|
||||||
const index = `${paths.demo.root}index.html`;
|
|
||||||
const error = `${paths.demo.root}error.html`;
|
|
||||||
const pages = [index];
|
|
||||||
|
|
||||||
if (branch.current === branch.master) {
|
|
||||||
pages.push(error);
|
|
||||||
}
|
|
||||||
|
|
||||||
gulp
|
|
||||||
.src(pages)
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(s3(aws.demo, options.demo));
|
|
||||||
|
|
||||||
// Only update CDN for master (prod)
|
|
||||||
if (branch.current !== branch.master) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Upload error.html to cdn (as well as demo site)
|
|
||||||
return gulp
|
|
||||||
.src([error])
|
|
||||||
.pipe(replace(localPath, versionPath))
|
|
||||||
.pipe(s3(aws.cdn, options.demo));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Update symlinks for latest
|
|
||||||
/* gulp.task("symlinks", function () {
|
|
||||||
console.log("Updating symlinks...");
|
|
||||||
|
|
||||||
return gulp.src(paths.upload)
|
|
||||||
.pipe(through.obj(function (chunk, enc, callback) {
|
|
||||||
if (chunk.stat.isFile()) {
|
|
||||||
// Get the filename
|
|
||||||
var filename = chunk.path.split("/").reverse()[0];
|
|
||||||
|
|
||||||
// Create the 0 byte redirect files to upload
|
|
||||||
createFile(filename, "")
|
|
||||||
.pipe(rename(function (path) {
|
|
||||||
path.dirname = path.dirname.replace(".", "latest");
|
|
||||||
}))
|
|
||||||
// Upload to S3 with correct headers
|
|
||||||
.pipe(s3(aws.cdn, options.symlinks(version, filename)));
|
|
||||||
}
|
|
||||||
|
|
||||||
callback(null, chunk);
|
|
||||||
}));
|
|
||||||
}); */
|
|
||||||
|
|
||||||
// Open the demo site to check it's sweet
|
|
||||||
gulp.task('open', () => {
|
|
||||||
console.log(`Opening ${aws.demo.domain}...`);
|
|
||||||
|
|
||||||
// A file must be specified or gulp will skip the task
|
|
||||||
// Doesn't matter which file since we set the URL above
|
|
||||||
// Weird, I know...
|
|
||||||
return gulp.src([`${paths.demo.root}index.html`]).pipe(
|
|
||||||
open('', {
|
|
||||||
url: `http://${aws.demo.domain}`,
|
|
||||||
}),
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Do everything
|
|
||||||
gulp.task('publish', callback => {
|
|
||||||
run('version', tasks.clean, tasks.js, tasks.sass, tasks.sprite, 'cdn', 'demo', callback);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Get branch info
|
||||||
|
const branch = {
|
||||||
|
current: gitbranch.sync(),
|
||||||
|
master: 'master',
|
||||||
|
beta: 'beta',
|
||||||
|
};
|
||||||
|
|
||||||
|
const maxAge = 31536000; // 1 year
|
||||||
|
const options = {
|
||||||
|
cdn: {
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': `max-age=${maxAge}`,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
demo: {
|
||||||
|
uploadPath: branch.current === branch.beta ? 'beta' : null,
|
||||||
|
headers: {
|
||||||
|
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
symlinks(ver, filename) {
|
||||||
|
return {
|
||||||
|
headers: {
|
||||||
|
// http://stackoverflow.com/questions/2272835/amazon-s3-object-redirect
|
||||||
|
'x-amz-website-redirect-location': `/${ver}/${filename}`,
|
||||||
|
'Cache-Control': 'no-cache, no-store, must-revalidate, max-age=0',
|
||||||
|
},
|
||||||
|
};
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
const regex =
|
||||||
|
'(?:0|[1-9][0-9]*)\\.(?:0|[1-9][0-9]*).(?:0|[1-9][0-9]*)(?:-[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?(?:\\+[\\da-z\\-]+(?:.[\\da-z\\-]+)*)?';
|
||||||
|
const semver = new RegExp(`v${regex}`, 'gi');
|
||||||
|
const localPath = new RegExp('(../)?dist', 'gi');
|
||||||
|
const versionPath = `https://${deploy.cdn.domain}/${version}`;
|
||||||
|
const cdnpath = new RegExp(`${deploy.cdn.domain}/${regex}/`, 'gi');
|
||||||
|
|
||||||
|
const renameFile = rename(p => {
|
||||||
|
p.basename = p.basename.replace(minSuffix, ''); // eslint-disable-line
|
||||||
|
p.dirname = p.dirname.replace('.', version); // eslint-disable-line
|
||||||
|
});
|
||||||
|
|
||||||
|
// Check we're on the correct branch to deploy
|
||||||
|
const canDeploy = () => {
|
||||||
|
const allowed = [branch.master, branch.beta];
|
||||||
|
|
||||||
|
if (!allowed.includes(branch.current)) {
|
||||||
|
console.error(`Must be on ${allowed.join(', ')} to publish! (current: ${branch.current})`);
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
};
|
||||||
|
|
||||||
|
gulp.task('version', done => {
|
||||||
|
if (!canDeploy()) {
|
||||||
|
done();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { domain } = deploy.cdn;
|
||||||
|
|
||||||
|
log(`Uploading ${ansi.green.bold(version)} to ${ansi.cyan(domain)}...`);
|
||||||
|
|
||||||
|
// Replace versioned URLs in source
|
||||||
|
const files = ['plyr.js', 'plyr.polyfilled.js', 'config/defaults.js'];
|
||||||
|
|
||||||
|
return gulp
|
||||||
|
.src(files.map(file => path.join(__dirname, `src/js/${file}`)), { base: '.' })
|
||||||
|
.pipe(replace(semver, `v${version}`))
|
||||||
|
.pipe(replace(cdnpath, `${domain}/${version}/`))
|
||||||
|
.pipe(gulp.dest('./'));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Publish version to CDN bucket
|
||||||
|
gulp.task('cdn', done => {
|
||||||
|
if (!canDeploy()) {
|
||||||
|
done();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { domain, publisher } = deploy.cdn;
|
||||||
|
|
||||||
|
if (!publisher) {
|
||||||
|
throw new Error('No publisher instance. Check AWS configuration.');
|
||||||
|
}
|
||||||
|
|
||||||
|
log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`);
|
||||||
|
|
||||||
|
// Upload to CDN
|
||||||
|
return (
|
||||||
|
gulp
|
||||||
|
.src(paths.upload)
|
||||||
|
.pipe(renameFile)
|
||||||
|
// Remove min suffix from source map URL
|
||||||
|
.pipe(
|
||||||
|
replace(
|
||||||
|
/sourceMappingURL=([\w-?.]+)/,
|
||||||
|
(match, filename) => `sourceMappingURL=${filename.replace(minSuffix, '')}`,
|
||||||
|
),
|
||||||
|
)
|
||||||
|
.pipe(size(sizeOptions))
|
||||||
|
.pipe(replace(localPath, versionPath))
|
||||||
|
.pipe(publisher.publish(options.cdn.headers))
|
||||||
|
.pipe(publish.reporter())
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Purge the fastly cache incase any 403/404 are cached
|
||||||
|
gulp.task('purge', () => {
|
||||||
|
if (!Object.keys(credentials).includes('fastly')) {
|
||||||
|
throw new Error('Fastly credentials required to purge cache.');
|
||||||
|
}
|
||||||
|
|
||||||
|
const { fastly } = credentials;
|
||||||
|
const list = [];
|
||||||
|
|
||||||
|
return gulp
|
||||||
|
.src(paths.upload)
|
||||||
|
.pipe(
|
||||||
|
through.obj((file, enc, cb) => {
|
||||||
|
const filename = file.path.split('/').pop();
|
||||||
|
list.push(`${versionPath}/${filename.replace(minSuffix, '')}`);
|
||||||
|
cb(null);
|
||||||
|
}),
|
||||||
|
)
|
||||||
|
.on('end', () => {
|
||||||
|
const purge = new FastlyPurge(fastly.token);
|
||||||
|
|
||||||
|
list.forEach(url => {
|
||||||
|
log(`Purging ${ansi.cyan(url)}...`);
|
||||||
|
|
||||||
|
purge.url(url, (error, result) => {
|
||||||
|
if (error) {
|
||||||
|
log.error(error);
|
||||||
|
} else if (result) {
|
||||||
|
log(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
// Publish to demo bucket
|
||||||
|
gulp.task('demo', done => {
|
||||||
|
if (!canDeploy()) {
|
||||||
|
done();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { publisher } = deploy.demo;
|
||||||
|
const { domain } = deploy.cdn;
|
||||||
|
|
||||||
|
if (!publisher) {
|
||||||
|
throw new Error('No publisher instance. Check AWS configuration.');
|
||||||
|
}
|
||||||
|
|
||||||
|
log(`Uploading ${ansi.green.bold(pkg.version)} to ${ansi.cyan(domain)}...`);
|
||||||
|
|
||||||
|
// Replace versioned files in readme.md
|
||||||
|
gulp.src([`${__dirname}/readme.md`])
|
||||||
|
.pipe(replace(cdnpath, `${domain}/${version}/`))
|
||||||
|
.pipe(gulp.dest(__dirname));
|
||||||
|
|
||||||
|
// Replace local file paths with remote paths in demo HTML
|
||||||
|
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
|
||||||
|
const index = `${paths.demo.root}index.html`;
|
||||||
|
const error = `${paths.demo.root}error.html`;
|
||||||
|
const pages = [index];
|
||||||
|
|
||||||
|
if (branch.current === branch.master) {
|
||||||
|
pages.push(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
return gulp
|
||||||
|
.src(pages)
|
||||||
|
.pipe(replace(localPath, versionPath))
|
||||||
|
.pipe(publisher.publish(options.demo.headers))
|
||||||
|
.pipe(publish.reporter());
|
||||||
|
});
|
||||||
|
|
||||||
|
gulp.task('error', done => {
|
||||||
|
// Only update CDN for master (prod)
|
||||||
|
if (!canDeploy() || branch.current !== branch.master) {
|
||||||
|
done();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const { publisher } = deploy.cdn;
|
||||||
|
|
||||||
|
if (!publisher) {
|
||||||
|
throw new Error('No publisher instance. Check AWS configuration.');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Replace local file paths with remote paths in demo HTML
|
||||||
|
// e.g. "../dist/plyr.js" to "https://cdn.plyr.io/x.x.x/plyr.js"
|
||||||
|
// Upload error.html to cdn
|
||||||
|
return gulp
|
||||||
|
.src(`${paths.demo.root}error.html`)
|
||||||
|
.pipe(replace(localPath, versionPath))
|
||||||
|
.pipe(publisher.publish(options.demo.headers))
|
||||||
|
.pipe(publish.reporter());
|
||||||
|
});
|
||||||
|
|
||||||
|
// Open the demo site to check it's ok
|
||||||
|
gulp.task('open', () => {
|
||||||
|
const { domain } = deploy.demo;
|
||||||
|
|
||||||
|
return gulp.src(__filename).pipe(
|
||||||
|
open({
|
||||||
|
uri: `https://${domain}/${branch.current === branch.beta ? 'beta' : ''}`,
|
||||||
|
}),
|
||||||
|
);
|
||||||
|
});
|
||||||
|
|
||||||
|
// Do everything
|
||||||
|
gulp.task(
|
||||||
|
'deploy',
|
||||||
|
gulp.series(
|
||||||
|
'version',
|
||||||
|
tasks.clean,
|
||||||
|
gulp.parallel(...tasks.js, ...tasks.css, ...tasks.sprite),
|
||||||
|
'cdn',
|
||||||
|
'demo',
|
||||||
|
'purge',
|
||||||
|
'open',
|
||||||
|
),
|
||||||
|
);
|
||||||
|
|||||||
+79
-63
@@ -1,80 +1,96 @@
|
|||||||
{
|
{
|
||||||
"name": "plyr",
|
"name": "plyr",
|
||||||
"version": "3.3.20",
|
"version": "3.5.5",
|
||||||
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
|
"description": "A simple, accessible and customizable HTML5, YouTube and Vimeo media player",
|
||||||
"homepage": "https://plyr.io",
|
"homepage": "https://plyr.io",
|
||||||
"main": "./dist/plyr.js",
|
"author": "Sam Potts <sam@potts.es>",
|
||||||
"browser": "./dist/plyr.min.js",
|
"main": "dist/plyr.js",
|
||||||
"sass": "./src/sass/plyr.scss",
|
"module": "dist/plyr.min.mjs",
|
||||||
"style": "./dist/plyr.css",
|
"jsnext:main": "dist/plyr.min.mjs",
|
||||||
"devDependencies": {
|
"browser": "dist/plyr.min.js",
|
||||||
"babel-core": "^6.26.3",
|
"sass": "src/sass/plyr.scss",
|
||||||
"babel-eslint": "^8.2.3",
|
"style": "dist/plyr.css",
|
||||||
"babel-plugin-external-helpers": "^6.22.0",
|
"keywords": [
|
||||||
"babel-preset-env": "^1.7.0",
|
"HTML5 Video",
|
||||||
"del": "^3.0.0",
|
"HTML5 Audio",
|
||||||
"eslint": "^4.19.1",
|
"Media Player",
|
||||||
"eslint-config-airbnb-base": "^12.1.0",
|
"DASH",
|
||||||
"eslint-config-prettier": "^2.9.0",
|
"Shaka",
|
||||||
"eslint-plugin-import": "^2.12.0",
|
"WordPress",
|
||||||
"git-branch": "^2.0.1",
|
"HLS"
|
||||||
"gulp": "^3.9.1",
|
],
|
||||||
"gulp-autoprefixer": "^5.0.0",
|
"license": "MIT",
|
||||||
"gulp-better-rollup": "^3.2.1",
|
|
||||||
"gulp-clean-css": "^3.9.4",
|
|
||||||
"gulp-concat": "^2.6.1",
|
|
||||||
"gulp-filter": "^5.1.0",
|
|
||||||
"gulp-header": "^2.0.5",
|
|
||||||
"gulp-open": "^3.0.1",
|
|
||||||
"gulp-postcss": "^7.0.1",
|
|
||||||
"gulp-rename": "^1.3.0",
|
|
||||||
"gulp-replace": "^1.0.0",
|
|
||||||
"gulp-s3": "^0.11.0",
|
|
||||||
"gulp-sass": "^4.0.1",
|
|
||||||
"gulp-size": "^3.0.0",
|
|
||||||
"gulp-sourcemaps": "^2.6.4",
|
|
||||||
"gulp-svgmin": "^1.2.4",
|
|
||||||
"gulp-svgstore": "^6.1.1",
|
|
||||||
"gulp-uglify-es": "^1.0.4",
|
|
||||||
"gulp-util": "^3.0.8",
|
|
||||||
"postcss-custom-properties": "^7.0.0",
|
|
||||||
"prettier-eslint": "^8.8.1",
|
|
||||||
"prettier-stylelint": "^0.4.2",
|
|
||||||
"rollup-plugin-babel": "^3.0.4",
|
|
||||||
"rollup-plugin-commonjs": "^9.1.3",
|
|
||||||
"rollup-plugin-node-resolve": "^3.3.0",
|
|
||||||
"run-sequence": "^2.2.1",
|
|
||||||
"stylelint": "^9.3.0",
|
|
||||||
"stylelint-config-prettier": "^3.3.0",
|
|
||||||
"stylelint-config-recommended": "^2.1.0",
|
|
||||||
"stylelint-config-sass-guidelines": "^5.0.0",
|
|
||||||
"stylelint-order": "^0.8.1",
|
|
||||||
"stylelint-scss": "^3.1.3",
|
|
||||||
"stylelint-selector-bem-pattern": "^2.0.0"
|
|
||||||
},
|
|
||||||
"keywords": ["HTML5 Video", "HTML5 Audio", "Media Player", "DASH", "Shaka", "WordPress", "HLS"],
|
|
||||||
"repository": {
|
"repository": {
|
||||||
"type": "git",
|
"type": "git",
|
||||||
"url": "git://github.com/sampotts/plyr.git"
|
"url": "git://github.com/sampotts/plyr.git"
|
||||||
},
|
},
|
||||||
"license": "MIT",
|
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/sampotts/plyr/issues"
|
"url": "https://github.com/sampotts/plyr/issues"
|
||||||
},
|
},
|
||||||
"directories": {
|
"browserslist": "> 1%",
|
||||||
"doc": "readme.md"
|
|
||||||
},
|
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"build": "gulp build",
|
"build": "gulp build",
|
||||||
"lint": "eslint src/js",
|
"lint": "eslint src/js && npm run-script remark",
|
||||||
"test": "echo \"Error: no test specified\" && exit 1"
|
"lint:fix": "eslint --fix src/js",
|
||||||
|
"remark": "remark -f --use 'validate-links=repository:\"sampotts/plyr\"' '{,!(node_modules),.?**/}*.md'",
|
||||||
|
"deploy": "yarn lint && gulp deploy"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"ansi-colors": "^4.0.1",
|
||||||
|
"aws-sdk": "^2.478.0",
|
||||||
|
"@babel/core": "^7.4.5",
|
||||||
|
"@babel/preset-env": "^7.4.5",
|
||||||
|
"babel-eslint": "^10.0.2",
|
||||||
|
"del": "^4.1.1",
|
||||||
|
"eslint": "^5.16.0",
|
||||||
|
"eslint-config-airbnb-base": "^13.1.0",
|
||||||
|
"eslint-config-prettier": "^5.0.0",
|
||||||
|
"eslint-plugin-import": "^2.17.3",
|
||||||
|
"eslint-plugin-simple-import-sort": "^4.0.0",
|
||||||
|
"fancy-log": "^1.3.3",
|
||||||
|
"fastly-purge": "^1.0.1",
|
||||||
|
"git-branch": "^2.0.1",
|
||||||
|
"gulp": "^4.0.2",
|
||||||
|
"gulp-autoprefixer": "^6.1.0",
|
||||||
|
"gulp-awspublish": "^4.0.0",
|
||||||
|
"gulp-better-rollup": "^4.0.1",
|
||||||
|
"gulp-clean-css": "^4.2.0",
|
||||||
|
"gulp-filter": "^6.0.0",
|
||||||
|
"gulp-header": "^2.0.7",
|
||||||
|
"gulp-imagemin": "^6.0.0",
|
||||||
|
"gulp-open": "^3.0.1",
|
||||||
|
"gulp-plumber": "^1.2.1",
|
||||||
|
"gulp-postcss": "^8.0.0",
|
||||||
|
"gulp-rename": "^1.4.0",
|
||||||
|
"gulp-replace": "^1.0.0",
|
||||||
|
"gulp-sass": "^4.0.2",
|
||||||
|
"gulp-size": "^3.0.0",
|
||||||
|
"gulp-sourcemaps": "^2.6.5",
|
||||||
|
"gulp-svgstore": "^7.0.1",
|
||||||
|
"gulp-terser": "^1.2.0",
|
||||||
|
"postcss-custom-properties": "^8.0.11",
|
||||||
|
"prettier-eslint": "^9.0.0",
|
||||||
|
"prettier-stylelint": "^0.4.2",
|
||||||
|
"remark-cli": "^6.0.1",
|
||||||
|
"remark-validate-links": "^8.0.3",
|
||||||
|
"rollup": "^1.15.6",
|
||||||
|
"rollup-plugin-babel": "^4.3.2",
|
||||||
|
"rollup-plugin-commonjs": "^10.0.0",
|
||||||
|
"rollup-plugin-node-resolve": "^5.0.3",
|
||||||
|
"stylelint": "^10.1.0",
|
||||||
|
"stylelint-config-prettier": "^5.2.0",
|
||||||
|
"stylelint-config-recommended": "^2.2.0",
|
||||||
|
"stylelint-config-sass-guidelines": "^6.0.0",
|
||||||
|
"stylelint-order": "^3.0.0",
|
||||||
|
"stylelint-scss": "^3.8.0",
|
||||||
|
"stylelint-selector-bem-pattern": "^2.1.0",
|
||||||
|
"through2": "^3.0.1"
|
||||||
},
|
},
|
||||||
"author": "Sam Potts <sam@potts.es>",
|
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"babel-polyfill": "^6.26.0",
|
"core-js": "^3.1.4",
|
||||||
"custom-event-polyfill": "^0.3.0",
|
"custom-event-polyfill": "^1.0.7",
|
||||||
"loadjs": "^3.5.4",
|
"loadjs": "^3.6.1",
|
||||||
"raven-js": "^3.26.3",
|
"rangetouch": "^2.0.0",
|
||||||
"url-polyfill": "^1.0.13"
|
"url-polyfill": "^1.1.5"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+29
-31
@@ -1,32 +1,30 @@
|
|||||||
{
|
{
|
||||||
"folders": [
|
"folders": [
|
||||||
{
|
{
|
||||||
"path": "."
|
"path": "."
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"settings": {
|
"settings": {
|
||||||
// Exclude from the editor
|
"search.exclude": {
|
||||||
"files.exclude": {
|
"**/node_modules": true,
|
||||||
"**/node_modules": true
|
"**/dist": true
|
||||||
},
|
},
|
||||||
// Exclude from search
|
// Linting
|
||||||
"search.exclude": {
|
"stylelint.enable": true,
|
||||||
"dist/": true,
|
"css.validate": false,
|
||||||
"demo/dist/": true
|
"scss.validate": false,
|
||||||
},
|
"javascript.validate.enable": false,
|
||||||
// Linting
|
|
||||||
"stylelint.enable": true,
|
// Prettier
|
||||||
"css.validate": false,
|
"prettier.eslintIntegration": true,
|
||||||
"scss.validate": false,
|
"prettier.stylelintIntegration": true,
|
||||||
"javascript.validate.enable": false,
|
|
||||||
// Prettier
|
// Formatting
|
||||||
"prettier.eslintIntegration": true,
|
"editor.tabSize": 4,
|
||||||
"prettier.stylelintIntegration": true,
|
"editor.insertSpaces": true,
|
||||||
// Formatting
|
"editor.formatOnSave": true,
|
||||||
"editor.tabSize": 4,
|
|
||||||
"editor.insertSpaces": true,
|
// Trim on save
|
||||||
"editor.formatOnSave": true,
|
"files.trimTrailingWhitespace": true
|
||||||
// Trim on save
|
}
|
||||||
"files.trimTrailingWhitespace": true
|
}
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -1,94 +1,77 @@
|
|||||||
# Plyr
|
Plyr is a simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers.
|
||||||
|
|
||||||
A simple, lightweight, accessible and customizable HTML5, YouTube and Vimeo media player that supports [_modern_](#browser-support) browsers.
|
[Checkout the demo](https://plyr.io) - [Donate](#donate) - [Slack](https://bit.ly/plyr-chat) - [](https://badge.fury.io/js/plyr)
|
||||||
|
|
||||||
[Checkout the demo](https://plyr.io) - [Donate to support Plyr](#donate) - [Chat on Slack](https://bit.ly/plyr-chat)
|
|
||||||
|
|
||||||
[](https://plyr.io)
|
[](https://plyr.io)
|
||||||
|
|
||||||
## Features
|
# Features
|
||||||
|
|
||||||
* **Accessible** - full support for VTT captions and screen readers
|
- 📼 **HTML Video & Audio, YouTube & Vimeo** - support for the major formats
|
||||||
* **[Customisable](#html)** - make the player look how you want with the markup you want
|
- 💪 **Accessible** - full support for VTT captions and screen readers
|
||||||
* **Good HTML** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no
|
- 🔧 **[Customisable](#html)** - make the player look how you want with the markup you want
|
||||||
|
- 😎 **Clean HTML** - uses the _right_ elements. `<input type="range">` for volume and `<progress>` for progress and well, `<button>`s for buttons. There's no
|
||||||
`<span>` or `<a href="#">` button hacks
|
`<span>` or `<a href="#">` button hacks
|
||||||
* **Responsive** - works with any screen size
|
- 📱 **Responsive** - works with any screen size
|
||||||
* **HTML Video & Audio** - support for both formats
|
- 💵 **[Monetization](#ads)** - make money from your videos
|
||||||
* **[Embedded Video](#embeds)** - support for YouTube and Vimeo video playback
|
- 📹 **[Streaming](#demos)** - support for hls.js, Shaka and dash.js streaming playback
|
||||||
* **[Monetization](#ads)** - make money from your videos
|
- 🎛 **[API](#api)** - toggle playback, volume, seeking, and more through a standardized API
|
||||||
* **[Streaming](#streaming)** - support for hls.js, Shaka and dash.js streaming playback
|
- 🎤 **[Events](#events)** - no messing around with Vimeo and YouTube APIs, all events are standardized across formats
|
||||||
* **[API](#api)** - toggle playback, volume, seeking, and more through a standardized API
|
- 🔎 **[Fullscreen](#fullscreen)** - supports native fullscreen with fallback to "full window" modes
|
||||||
* **[Events](#events)** - no messing around with Vimeo and YouTube APIs, all events are standardized across formats
|
- ⌨️ **[Shortcuts](#shortcuts)** - supports keyboard shortcuts
|
||||||
* **[Fullscreen](#fullscreen)** - supports native fullscreen with fallback to "full window" modes
|
- 🖥 **Picture-in-Picture** - supports picture-in-picture mode
|
||||||
* **[Shortcuts](#shortcuts)** - supports keyboard shortcuts
|
- 📱 **Playsinline** - supports the `playsinline` attribute
|
||||||
* **Picture-in-Picture** - supports Safari's picture-in-picture mode
|
- 🏎 **Speed controls** - adjust speed on the fly
|
||||||
* **Playsinline** - supports the `playsinline` attribute
|
- 📖 **Multiple captions** - support for multiple caption tracks
|
||||||
* **Speed controls** - adjust speed on the fly
|
- 🌎 **i18n support** - support for internationalization of controls
|
||||||
* **Multiple captions** - support for multiple caption tracks
|
- 👌 **[Preview thumbnails](#preview-thumbnails)** - support for displaying preview thumbnails
|
||||||
* **i18n support** - support for internationalization of controls
|
- 🤟 **No frameworks** - written in "vanilla" ES6 JavaScript, no jQuery required
|
||||||
* **No dependencies** - written in "vanilla" ES6 JavaScript, no jQuery required
|
- 💁♀️ **SASS** - to include in your build processes
|
||||||
* **SASS** - to include in your build processes
|
|
||||||
|
|
||||||
Oh and yes, it works with Bootstrap.
|
### Demos
|
||||||
|
|
||||||
## Changelog
|
|
||||||
|
|
||||||
Check out the [changelog](changelog.md) to see what's new with Plyr.
|
|
||||||
|
|
||||||
## Plugins & Components
|
|
||||||
|
|
||||||
Some awesome folks have made plugins for CMSs and Components for JavaScript frameworks:
|
|
||||||
|
|
||||||
| Type | Maintainer | Link |
|
|
||||||
| --------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
|
||||||
| WordPress | Brandon Lavigne ([@drrobotnik](https://github.com/drrobotnik)) | [https://wordpress.org/plugins/plyr/](https://wordpress.org/plugins/plyr/) |
|
|
||||||
| React | Jose Miguel Bejarano ([@xDae](https://github.com/xDae)) | [https://github.com/xDae/react-plyr](https://github.com/xDae/react-plyr) |
|
|
||||||
| Vue | Gabe Dunn ([@redxtech](https://github.com/redxtech)) | [https://github.com/redxtech/vue-plyr](https://github.com/redxtech/vue-plyr) |
|
|
||||||
| Neos | Jon Uhlmann ([@jonnitto](https://github.com/jonnitto)) | [https://packagist.org/packages/jonnitto/plyr](https://packagist.org/packages/jonnitto/plyr) |
|
|
||||||
| Kirby | Dominik Pschenitschni ([@dpschen](https://github.com/dpschen)) | [https://github.com/dpschen/kirby-plyrtag](https://github.com/dpschen/kirby-plyrtag) |
|
|
||||||
|
|
||||||
## Quick setup
|
|
||||||
|
|
||||||
Here's a quick run through on getting up and running. There's also a [demo on Codepen](http://codepen.io/sampotts/pen/jARJYp). You can grab all of the source with [NPM](https://www.npmjs.com/package/plyr) using `npm install plyr`.
|
|
||||||
|
|
||||||
### Try Plyr online
|
|
||||||
|
|
||||||
You can try Plyr in Codepen using our minimal templates: [HTML5 video](https://codepen.io/pen?template=bKeqpr), [HTML5 audio](https://codepen.io/pen?template=rKLywR), [YouTube](https://codepen.io/pen?template=GGqbbJ), [Vimeo](https://codepen.io/pen?template=bKeXNq). For Streaming we also have example integrations with: [Dash.js](https://codepen.io/pen?template=zaBgBy), [Hls.js](https://codepen.io/pen?template=oyLKQb) and [Shaka Player](https://codepen.io/pen?template=ZRpzZO)
|
You can try Plyr in Codepen using our minimal templates: [HTML5 video](https://codepen.io/pen?template=bKeqpr), [HTML5 audio](https://codepen.io/pen?template=rKLywR), [YouTube](https://codepen.io/pen?template=GGqbbJ), [Vimeo](https://codepen.io/pen?template=bKeXNq). For Streaming we also have example integrations with: [Dash.js](https://codepen.io/pen?template=zaBgBy), [Hls.js](https://codepen.io/pen?template=oyLKQb) and [Shaka Player](https://codepen.io/pen?template=ZRpzZO)
|
||||||
|
|
||||||
### HTML
|
# Quick setup
|
||||||
|
|
||||||
|
## HTML
|
||||||
|
|
||||||
Plyr extends upon the standard [HTML5 media element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) markup so that's all you need for those types.
|
Plyr extends upon the standard [HTML5 media element](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement) markup so that's all you need for those types.
|
||||||
|
|
||||||
#### HTML5 Video
|
### HTML5 Video
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<video poster="/path/to/poster.jpg" id="player" playsinline controls>
|
<video poster="/path/to/poster.jpg" id="player" playsinline controls>
|
||||||
<source src="/path/to/video.mp4" type="video/mp4">
|
<source src="/path/to/video.mp4" type="video/mp4" />
|
||||||
<source src="/path/to/video.webm" type="video/webm">
|
<source src="/path/to/video.webm" type="video/webm" />
|
||||||
|
|
||||||
<!-- Captions are optional -->
|
<!-- Captions are optional -->
|
||||||
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default>
|
<track kind="captions" label="English captions" src="/path/to/captions.vtt" srclang="en" default />
|
||||||
</video>
|
</video>
|
||||||
```
|
```
|
||||||
|
|
||||||
#### HTML5 Audio
|
### HTML5 Audio
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<audio id="player" controls>
|
<audio id="player" controls>
|
||||||
<source src="/path/to/audio.mp3" type="audio/mp3">
|
<source src="/path/to/audio.mp3" type="audio/mp3" />
|
||||||
<source src="/path/to/audio.ogg" type="audio/ogg">
|
<source src="/path/to/audio.ogg" type="audio/ogg" />
|
||||||
</audio>
|
</audio>
|
||||||
```
|
```
|
||||||
|
|
||||||
For YouTube and Vimeo players, Plyr uses progressive enhancement to enhance the default `<iframe>` embeds. Below are some examples. The `plyr__video-embed` classname will make the embed responsive. You can add the `autoplay`, `loop` and `playsinline` (YouTube only) query parameters to the URL and they will be set as config options automatically. For YouTube, the `origin` should be updated to reflect the domain you're hosting the embed on, or you can opt to omit it.
|
For YouTube and Vimeo players, Plyr uses progressive enhancement to enhance the default `<iframe>` embeds. Below are some examples. The `plyr__video-embed` classname will make the embed responsive. You can add the `autoplay`, `loop`, `hl` (YouTube only) and `playsinline` (YouTube only) query parameters to the URL and they will be set as config options automatically. For YouTube, the `origin` should be updated to reflect the domain you're hosting the embed on, or you can opt to omit it.
|
||||||
|
|
||||||
#### YouTube embed
|
### YouTube
|
||||||
|
|
||||||
We recommend [progressive enhancement](https://www.smashingmagazine.com/2009/04/progressive-enhancement-what-it-is-and-how-to-use-it/) with the embedded players. You can elect to use an `<iframe>` as the source element (which Plyr will progressively enhance) or a bog standard `<div>` with two essential data attributes - `data-plyr-provider` and `data-plyr-embed-id`.
|
We recommend [progressive enhancement](https://www.smashingmagazine.com/2009/04/progressive-enhancement-what-it-is-and-how-to-use-it/) with the embedded players. You can elect to use an `<iframe>` as the source element (which Plyr will progressively enhance) or a bog standard `<div>` with two essential data attributes - `data-plyr-provider` and `data-plyr-embed-id`.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<div class="plyr__video-embed" id="player">
|
<div class="plyr__video-embed" id="player">
|
||||||
<iframe src="https://www.youtube.com/embed/bTqVqk7FSmY?origin=https://plyr.io&iv_load_policy=3&modestbranding=1&playsinline=1&showinfo=0&rel=0&enablejsapi=1" allowfullscreen allowtransparency allow="autoplay"></iframe>
|
<iframe
|
||||||
|
src="https://www.youtube.com/embed/bTqVqk7FSmY?origin=https://plyr.io&iv_load_policy=3&modestbranding=1&playsinline=1&showinfo=0&rel=0&enablejsapi=1"
|
||||||
|
allowfullscreen
|
||||||
|
allowtransparency
|
||||||
|
allow="autoplay"
|
||||||
|
></iframe>
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -102,13 +85,18 @@ Or the `<div>` non progressively enhanced method:
|
|||||||
|
|
||||||
_Note_: The `data-plyr-embed-id` can either be the video ID or URL for the media.
|
_Note_: The `data-plyr-embed-id` can either be the video ID or URL for the media.
|
||||||
|
|
||||||
#### Vimeo embed
|
### Vimeo
|
||||||
|
|
||||||
Much the same as YouTube above.
|
Much the same as YouTube above.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<div class="plyr__video-embed" id="player">
|
<div class="plyr__video-embed" id="player">
|
||||||
<iframe src="https://player.vimeo.com/video/76979871?loop=false&byline=false&portrait=false&title=false&speed=true&transparent=0&gesture=media" allowfullscreen allowtransparency allow="autoplay"></iframe>
|
<iframe
|
||||||
|
src="https://player.vimeo.com/video/76979871?loop=false&byline=false&portrait=false&title=false&speed=true&transparent=0&gesture=media"
|
||||||
|
allowfullscreen
|
||||||
|
allowtransparency
|
||||||
|
allow="autoplay"
|
||||||
|
></iframe>
|
||||||
</div>
|
</div>
|
||||||
```
|
```
|
||||||
|
|
||||||
@@ -118,13 +106,23 @@ Or the `<div>` non progressively enhanced method:
|
|||||||
<div id="player" data-plyr-provider="vimeo" data-plyr-embed-id="76979871"></div>
|
<div id="player" data-plyr-provider="vimeo" data-plyr-embed-id="76979871"></div>
|
||||||
```
|
```
|
||||||
|
|
||||||
### JavaScript
|
## JavaScript
|
||||||
|
|
||||||
Include the `plyr.js` script before the closing `</body>` tag and then in your JS create a new instance of Plyr as below.
|
You can use Plyr as an ES6 module as follows:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
import Plyr from 'plyr';
|
||||||
|
|
||||||
|
const player = new Plyr('#player');
|
||||||
|
```
|
||||||
|
|
||||||
|
Alertnatively you can include the `plyr.js` script before the closing `</body>` tag and then in your JS create a new instance of Plyr as below.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="path/to/plyr.js"></script>
|
<script src="path/to/plyr.js"></script>
|
||||||
<script>const player = new Plyr('#player');</script>
|
<script>
|
||||||
|
const player = new Plyr('#player');
|
||||||
|
</script>
|
||||||
```
|
```
|
||||||
|
|
||||||
See [initialising](#initialising) for more information on advanced setups.
|
See [initialising](#initialising) for more information on advanced setups.
|
||||||
@@ -132,60 +130,60 @@ See [initialising](#initialising) for more information on advanced setups.
|
|||||||
You can use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript. There's 2 versions; one with and one without [polyfills](#polyfills). My recommendation would be to manage polyfills seperately as part of your application but to make life easier you can use the polyfilled build.
|
You can use our CDN (provided by [Fastly](https://www.fastly.com/)) for the JavaScript. There's 2 versions; one with and one without [polyfills](#polyfills). My recommendation would be to manage polyfills seperately as part of your application but to make life easier you can use the polyfilled build.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://cdn.plyr.io/3.3.20/plyr.js"></script>
|
<script src="https://cdn.plyr.io/3.5.5/plyr.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
...or...
|
...or...
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<script src="https://cdn.plyr.io/3.3.20/plyr.polyfilled.js"></script>
|
<script src="https://cdn.plyr.io/3.5.5/plyr.polyfilled.js"></script>
|
||||||
```
|
```
|
||||||
|
|
||||||
### CSS
|
## CSS
|
||||||
|
|
||||||
Include the `plyr.css` stylsheet into your `<head>`
|
Include the `plyr.css` stylsheet into your `<head>`.
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<link rel="stylesheet" href="path/to/plyr.css">
|
<link rel="stylesheet" href="path/to/plyr.css" />
|
||||||
```
|
```
|
||||||
|
|
||||||
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
|
If you want to use our CDN (provided by [Fastly](https://www.fastly.com/)) for the default CSS, you can use the following:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<link rel="stylesheet" href="https://cdn.plyr.io/3.3.20/plyr.css">
|
<link rel="stylesheet" href="https://cdn.plyr.io/3.5.5/plyr.css" />
|
||||||
```
|
```
|
||||||
|
|
||||||
### SVG Sprite
|
## SVG Sprite
|
||||||
|
|
||||||
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
|
The SVG sprite is loaded automatically from our CDN (provided by [Fastly](https://www.fastly.com/)). To change this, see the [options](#options) below. For
|
||||||
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.3.20/plyr.svg`.
|
reference, the CDN hosted SVG sprite can be found at `https://cdn.plyr.io/3.5.5/plyr.svg`.
|
||||||
|
|
||||||
## Ads
|
# Ads
|
||||||
|
|
||||||
Plyr has partnered up with [vi.ai](http://vi.ai/publisher-video-monetization/?aid=plyrio) to offer monetization options for your videos. Getting setup is easy:
|
Plyr has partnered up with [vi.ai](https://vi.ai/publisher-video-monetization/?aid=plyrio) to offer monetization options for your videos. Getting setup is easy:
|
||||||
|
|
||||||
* [Sign up for a vi.ai account](http://vi.ai/publisher-video-monetization/?aid=plyrio)
|
- [Sign up for a vi.ai account](https://vi.ai/publisher-video-monetization/?aid=plyrio)
|
||||||
* Grab your publisher ID from the code snippet
|
- Grab your publisher ID from the code snippet
|
||||||
* Enable ads in the [config options](#options) and enter your publisher ID
|
- Enable ads in the [config options](#options) and enter your publisher ID
|
||||||
|
|
||||||
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
|
Any questions regarding the ads can be sent straight to vi.ai and any issues with rendering raised through GitHub issues.
|
||||||
|
|
||||||
## Advanced
|
# Advanced
|
||||||
|
|
||||||
### SASS
|
## SASS
|
||||||
|
|
||||||
You can use `bundle.scss` file included in `/src` as part of your build and change variables to suit your design. The SASS require you to
|
You can use `bundle.scss` file included in `/src` as part of your build and change variables to suit your design. The SASS require you to
|
||||||
use the [autoprefixer](https://www.npmjs.com/package/gulp-autoprefixer) plugin (you be should already!) as all declarations use the W3C definitions.
|
use the [autoprefixer](https://www.npmjs.com/package/gulp-autoprefixer) plugin (you should be already!) as all declarations use the W3C definitions.
|
||||||
|
|
||||||
The HTML markup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options to match any custom CSS
|
The HTML markup uses the BEM methodology with `plyr` as the block, e.g. `.plyr__controls`. You can change the class hooks in the options to match any custom CSS
|
||||||
you write. Check out the JavaScript source for more on this.
|
you write. Check out the JavaScript source for more on this.
|
||||||
|
|
||||||
### SVG
|
## SVG
|
||||||
|
|
||||||
The icons used in the Plyr controls are loaded in an SVG sprite. The sprite is automatically loaded from our CDN by default. If you already have an icon build
|
The icons used in the Plyr controls are loaded in an SVG sprite. The sprite is automatically loaded from our CDN by default. If you already have an icon build
|
||||||
system in place, you can include the source plyr icons (see `/src/sprite` for source icons).
|
system in place, you can include the source plyr icons (see `/src/sprite` for source icons).
|
||||||
|
|
||||||
#### Using the `iconUrl` option
|
### Using the `iconUrl` option
|
||||||
|
|
||||||
You can however specify your own `iconUrl` option and Plyr will determine if the url is absolute and requires loading by AJAX/CORS due to current browser
|
You can however specify your own `iconUrl` option and Plyr will determine if the url is absolute and requires loading by AJAX/CORS due to current browser
|
||||||
limitations or if it's a relative path, just use the path directly.
|
limitations or if it's a relative path, just use the path directly.
|
||||||
@@ -195,34 +193,33 @@ If you're using the `<base>` tag on your site, you may need to use something lik
|
|||||||
More info on SVG sprites here: [http://css-tricks.com/svg-sprites-use-better-icon-fonts/](http://css-tricks.com/svg-sprites-use-better-icon-fonts/) and the AJAX
|
More info on SVG sprites here: [http://css-tricks.com/svg-sprites-use-better-icon-fonts/](http://css-tricks.com/svg-sprites-use-better-icon-fonts/) and the AJAX
|
||||||
technique here: [http://css-tricks.com/ajaxing-svg-sprite/](http://css-tricks.com/ajaxing-svg-sprite/)
|
technique here: [http://css-tricks.com/ajaxing-svg-sprite/](http://css-tricks.com/ajaxing-svg-sprite/)
|
||||||
|
|
||||||
### Cross Origin (CORS)
|
## Cross Origin (CORS)
|
||||||
|
|
||||||
You'll notice the `crossorigin` attribute on the example `<video>` elements. This is because the TextTrack captions are loaded from another domain. If your
|
You'll notice the `crossorigin` attribute on the example `<video>` elements. This is because the TextTrack captions are loaded from another domain. If your
|
||||||
TextTrack captions are also hosted on another domain, you will need to add this attribute and make sure your host has the correct headers setup. For more info
|
TextTrack captions are also hosted on another domain, you will need to add this attribute and make sure your host has the correct headers setup. For more info
|
||||||
on CORS checkout the MDN docs:
|
on CORS checkout the MDN docs:
|
||||||
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)
|
[https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS](https://developer.mozilla.org/en-US/docs/Web/HTTP/Access_control_CORS)
|
||||||
|
|
||||||
### Captions
|
## Captions
|
||||||
|
|
||||||
WebVTT captions are supported. To add a caption track, check the HTML example above and look for the `<track>` element. Be sure to
|
WebVTT captions are supported. To add a caption track, check the HTML example above and look for the `<track>` element. Be sure to
|
||||||
[validate your caption files](https://quuz.org/webvtt/).
|
[validate your caption files](https://quuz.org/webvtt/).
|
||||||
|
|
||||||
### JavaScript
|
## JavaScript
|
||||||
|
|
||||||
#### Initialising
|
### Initialising
|
||||||
|
|
||||||
You can specify a range of arguments for the constructor to use:
|
You can specify a range of arguments for the constructor to use:
|
||||||
|
|
||||||
* A CSS string selector that's compatible with [`querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector)
|
- A [CSS string selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors)
|
||||||
* A [`HTMLElement`](https://developer.mozilla.org/en/docs/Web/API/HTMLElement)
|
- A [`HTMLElement`](https://developer.mozilla.org/en/docs/Web/API/HTMLElement)
|
||||||
* A [`NodeList`](https://developer.mozilla.org/en-US/docs/Web/API/NodeList)
|
- A [jQuery](https://jquery.com) object
|
||||||
* A [jQuery](https://jquery.com) object
|
|
||||||
|
|
||||||
_Note_: If a `NodeList`, `Array`, or jQuery object are passed, the first element will be used for setup. To setup multiple players, see [setting up multiple players](#setting-up-multiple-players) below.
|
_Note_: If a `NodeList`, `Array`, or jQuery object are passed, the first element will be used for setup. To setup multiple players, see [multiple players](#multiple-players) below.
|
||||||
|
|
||||||
Here's some examples
|
#### Single player
|
||||||
|
|
||||||
Passing a [string selector](https://developer.mozilla.org/en-US/docs/Web/API/NodeList):
|
Passing a CSS string selector that's compatible with [`querySelector`](https://developer.mozilla.org/en-US/docs/Web/API/Document/querySelector):
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const player = new Plyr('#player');
|
const player = new Plyr('#player');
|
||||||
@@ -234,15 +231,13 @@ Passing a [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElemen
|
|||||||
const player = new Plyr(document.getElementById('player'));
|
const player = new Plyr(document.getElementById('player'));
|
||||||
```
|
```
|
||||||
|
|
||||||
Passing a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) (see note below):
|
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const player = new Plyr(document.querySelectorAll('.js-player'));
|
const player = new Plyr(document.querySelector('.js-player'));
|
||||||
```
|
```
|
||||||
|
|
||||||
The NodeList, HTMLElement or string selector can be the target `<video>`, `<audio>`, or `<div>` wrapper for embeds.
|
The HTMLElement or string selector can be the target `<video>`, `<audio>`, or `<div>` wrapper for embeds.
|
||||||
|
|
||||||
##### Setting up multiple players
|
#### Multiple players
|
||||||
|
|
||||||
You have two choices here. You can either use a simple array loop to map the constructor:
|
You have two choices here. You can either use a simple array loop to map the constructor:
|
||||||
|
|
||||||
@@ -250,7 +245,7 @@ You have two choices here. You can either use a simple array loop to map the con
|
|||||||
const players = Array.from(document.querySelectorAll('.js-player')).map(p => new Plyr(p));
|
const players = Array.from(document.querySelectorAll('.js-player')).map(p => new Plyr(p));
|
||||||
```
|
```
|
||||||
|
|
||||||
...or use a static method where you can pass a [string selector](https://developer.mozilla.org/en-US/docs/Web/API/NodeList), a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList) or an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of elements:
|
...or use a static method where you can pass a [CSS string selector](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Selectors), a [NodeList](https://developer.mozilla.org/en-US/docs/Web/API/NodeList), an [Array](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array) of [HTMLElement](https://developer.mozilla.org/en/docs/Web/API/HTMLElement), or a [JQuery](https://jquery.com) object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const players = Plyr.setup('.js-player');
|
const players = Plyr.setup('.js-player');
|
||||||
@@ -258,71 +253,76 @@ const players = Plyr.setup('.js-player');
|
|||||||
|
|
||||||
Both options will also return an array of instances in the order of they were in the DOM for the string selector or the source NodeList or Array.
|
Both options will also return an array of instances in the order of they were in the DOM for the string selector or the source NodeList or Array.
|
||||||
|
|
||||||
##### Passing options
|
#### Options
|
||||||
|
|
||||||
The second argument for the constructor is the [options](#options) object:
|
The second argument for the constructor is the [options](#options) object:
|
||||||
|
|
||||||
```javascript
|
```javascript
|
||||||
const player = new Plyr('#player', {
|
const player = new Plyr('#player', {
|
||||||
/* options */
|
title: 'Example Title',
|
||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
In all cases, the constructor will return a Plyr object that can be used with the [API](#api) methods. See the [API](#api) section for more info.
|
|
||||||
|
|
||||||
#### Options
|
|
||||||
|
|
||||||
Options can be passed as an object to the constructor as above or as JSON in `data-plyr-config` attribute on each of your target elements:
|
Options can be passed as an object to the constructor as above or as JSON in `data-plyr-config` attribute on each of your target elements:
|
||||||
|
|
||||||
```html
|
```html
|
||||||
<video src="/path/to/video.mp4" id="player" controls data-plyr-config='{ "title": "This is an example video", "volume": 1, "debug": true }'></video>
|
<video src="/path/to/video.mp4" id="player" controls data-plyr-config='{ "title": "Example Title" }'></video>
|
||||||
```
|
```
|
||||||
|
|
||||||
Note the single quotes encapsulating the JSON and double quotes on the object keys. Only string values need double quotes.
|
Note the single quotes encapsulating the JSON and double quotes on the object keys. Only string values need double quotes.
|
||||||
|
|
||||||
| Option | Type | Default | Description |
|
| Option | Type | Default | Description |
|
||||||
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| -------------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `enabled` | Boolean | `true` | Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below. |
|
| `enabled` | Boolean | `true` | Completely disable Plyr. This would allow you to do a User Agent check or similar to programmatically enable or disable Plyr for a certain UA. Example below. |
|
||||||
| `debug` | Boolean | `false` | Display debugging information in the console |
|
| `debug` | Boolean | `false` | Display debugging information in the console |
|
||||||
| `controls` | Array, Function or Element | `['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']` | If a function is passed, it is assumed your method will return either an element or HTML string for the controls. Three arguments will be passed to your function; `id` (the unique id for the player), `seektime` (the seektime step in seconds), and `title` (the media title). See [controls.md](controls.md) for more info on how the html needs to be structured. |
|
| `controls` | Array, Function or Element | `['play-large', 'play', 'progress', 'current-time', 'mute', 'volume', 'captions', 'settings', 'pip', 'airplay', 'fullscreen']` | If a function is passed, it is assumed your method will return either an element or HTML string for the controls. Three arguments will be passed to your function; `id` (the unique id for the player), `seektime` (the seektime step in seconds), and `title` (the media title). See [controls.md](controls.md) for more info on how the html needs to be structured. |
|
||||||
| `settings` | Array | `['captions', 'quality', 'speed', 'loop']` | If you're using the default controls are used then you can specify which settings to show in the menu |
|
| `settings` | Array | `['captions', 'quality', 'speed', 'loop']` | If you're using the default controls are used then you can specify which settings to show in the menu |
|
||||||
| `i18n` | Object | See [defaults.js](/src/js/config/defaults.js) | Used for internationalization (i18n) of the text within the UI. |
|
| `i18n` | Object | See [defaults.js](/src/js/config/defaults.js) | Used for internationalization (i18n) of the text within the UI. |
|
||||||
| `loadSprite` | Boolean | `true` | Load the SVG sprite specified as the `iconUrl` option (if a URL). If `false`, it is assumed you are handling sprite loading yourself. |
|
| `loadSprite` | Boolean | `true` | Load the SVG sprite specified as the `iconUrl` option (if a URL). If `false`, it is assumed you are handling sprite loading yourself. |
|
||||||
| `iconUrl` | String | `null` | Specify a URL or path to the SVG sprite. See the [SVG section](#svg) for more info. |
|
| `iconUrl` | String | `null` | Specify a URL or path to the SVG sprite. See the [SVG section](#svg) for more info. |
|
||||||
| `iconPrefix` | String | `plyr` | Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option. |
|
| `iconPrefix` | String | `plyr` | Specify the id prefix for the icons used in the default controls (e.g. "plyr-play" would be "plyr"). This is to prevent clashes if you're using your own SVG sprite but with the default controls. Most people can ignore this option. |
|
||||||
| `blankUrl` | String | `https://cdn.plyr.io/static/blank.mp4` | Specify a URL or path to a blank video file used to properly cancel network requests. |
|
| `blankVideo` | String | `https://cdn.plyr.io/static/blank.mp4` | Specify a URL or path to a blank video file used to properly cancel network requests. |
|
||||||
| `autoplay` | Boolean | `false` | Autoplay the media on load. This is generally advised against on UX grounds. It is also disabled by default in some browsers. If the `autoplay` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true. |
|
| `autoplay`² | Boolean | `false` | Autoplay the media on load. If the `autoplay` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true. |
|
||||||
| `autopause`¹ | Boolean | `true` | Only allow one player playing at once. |
|
| `autopause`¹ | Boolean | `true` | Only allow one player playing at once. |
|
||||||
| `seekTime` | Number | `10` | The time, in seconds, to seek when a user hits fast forward or rewind. |
|
| `seekTime` | Number | `10` | The time, in seconds, to seek when a user hits fast forward or rewind. |
|
||||||
| `volume` | Number | `1` | A number, between 0 and 1, representing the initial volume of the player. |
|
| `volume` | Number | `1` | A number, between 0 and 1, representing the initial volume of the player. |
|
||||||
| `muted` | Boolean | `false` | Whether to start playback muted. If the `muted` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true. |
|
| `muted` | Boolean | `false` | Whether to start playback muted. If the `muted` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true. |
|
||||||
| `clickToPlay` | Boolean | `true` | Click (or tap) of the video container will toggle play/pause. |
|
| `clickToPlay` | Boolean | `true` | Click (or tap) of the video container will toggle play/pause. |
|
||||||
| `disableContextMenu` | Boolean | `true` | Disable right click menu on video to <em>help</em> as very primitive obfuscation to prevent downloads of content. |
|
| `disableContextMenu` | Boolean | `true` | Disable right click menu on video to <em>help</em> as very primitive obfuscation to prevent downloads of content. |
|
||||||
| `hideControls` | Boolean | `true` | Hide video controls automatically after 2s of no mouse or focus movement, on control element blur (tab out), on playback start or entering fullscreen. As soon as the mouse is moved, a control element is focused or playback is paused, the controls reappear instantly. |
|
| `hideControls` | Boolean | `true` | Hide video controls automatically after 2s of no mouse or focus movement, on control element blur (tab out), on playback start or entering fullscreen. As soon as the mouse is moved, a control element is focused or playback is paused, the controls reappear instantly. |
|
||||||
| `resetOnEnd` | Boolean | false | Reset the playback to the start once playback is complete. |
|
| `resetOnEnd` | Boolean | false | Reset the playback to the start once playback is complete. |
|
||||||
| `keyboard` | Object | `{ focused: true, global: false }` | Enable [keyboard shortcuts](#shortcuts) for focused players only or globally |
|
| `keyboard` | Object | `{ focused: true, global: false }` | Enable [keyboard shortcuts](#shortcuts) for focused players only or globally |
|
||||||
| `tooltips` | Object | `{ controls: false, seek: true }` | `controls`: Display control labels as tooltips on `:hover` & `:focus` (by default, the labels are screen reader only). `seek`: Display a seek tooltip to indicate on click where the media would seek to. |
|
| `tooltips` | Object | `{ controls: false, seek: true }` | `controls`: Display control labels as tooltips on `:hover` & `:focus` (by default, the labels are screen reader only). `seek`: Display a seek tooltip to indicate on click where the media would seek to. |
|
||||||
| `duration` | Number | `null` | Specify a custom duration for media. |
|
| `duration` | Number | `null` | Specify a custom duration for media. |
|
||||||
| `displayDuration` | Boolean | `true` | Displays the duration of the media on the "metadataloaded" event (on startup) in the current time display. This will only work if the `preload` attribute is not set to `none` (or is not set at all) and you choose not to display the duration (see `controls` option). |
|
| `displayDuration` | Boolean | `true` | Displays the duration of the media on the "metadataloaded" event (on startup) in the current time display. This will only work if the `preload` attribute is not set to `none` (or is not set at all) and you choose not to display the duration (see `controls` option). |
|
||||||
| `invertTime` | Boolean | `true` | Display the current time as a countdown rather than an incremental counter. |
|
| `invertTime` | Boolean | `true` | Display the current time as a countdown rather than an incremental counter. |
|
||||||
| `toggleInvert` | Boolean | `true` | Allow users to click to toggle the above. |
|
| `toggleInvert` | Boolean | `true` | Allow users to click to toggle the above. |
|
||||||
| `listeners` | Object | `null` | Allows binding of event listeners to the controls before the default handlers. See the `defaults.js` for available listeners. If your handler prevents default on the event (`event.preventDefault()`), the default handler will not fire. |
|
| `listeners` | Object | `null` | Allows binding of event listeners to the controls before the default handlers. See the `defaults.js` for available listeners. If your handler prevents default on the event (`event.preventDefault()`), the default handler will not fire. |
|
||||||
| `captions` | Object | `{ active: false, language: 'auto', update: false }` | `active`: Toggles if captions should be active by default. `language`: Sets the default language to load (if available). 'auto' uses the browser language. `update`: Listen to changes to tracks and update menu. This is needed for some streaming libraries, but can result in unselectable language options). |
|
| `captions` | Object | `{ active: false, language: 'auto', update: false }` | `active`: Toggles if captions should be active by default. `language`: Sets the default language to load (if available). 'auto' uses the browser language. `update`: Listen to changes to tracks and update menu. This is needed for some streaming libraries, but can result in unselectable language options). |
|
||||||
| `fullscreen` | Object | `{ enabled: true, fallback: true, iosNative: false }` | `enabled`: Toggles whether fullscreen should be enabled. `fallback`: Allow fallback to a full-window solution. `iosNative`: whether to use native iOS fullscreen when entering fullscreen (no custom controls) |
|
| `fullscreen` | Object | `{ enabled: true, fallback: true, iosNative: false }` | `enabled`: Toggles whether fullscreen should be enabled. `fallback`: Allow fallback to a full-window solution (`true`/`false`/`'force'`). `iosNative`: whether to use native iOS fullscreen when entering fullscreen (no custom controls) |
|
||||||
| `ratio` | String | `16:9` | The aspect ratio you want to use for embedded players. |
|
| `ratio` | String | `null` | Force an aspect ratio for all videos. The format is `'w:h'` - e.g. `'16:9'` or `'4:3'`. If this is not specified then the default for HTML5 and Vimeo is to use the native resolution of the video. As dimensions are not available from YouTube via SDK, 16:9 is forced as a sensible default. |
|
||||||
| `storage` | Object | `{ enabled: true, key: 'plyr' }` | `enabled`: Allow use of local storage to store user settings. `key`: The key name to use. |
|
| `storage` | Object | `{ enabled: true, key: 'plyr' }` | `enabled`: Allow use of local storage to store user settings. `key`: The key name to use. |
|
||||||
| `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] }` | `selected`: The default speed for playback. `options`: Options to display in the menu. Most browsers will refuse to play slower than 0.5. |
|
| `speed` | Object | `{ selected: 1, options: [0.5, 0.75, 1, 1.25, 1.5, 1.75, 2] }` | `selected`: The default speed for playback. `options`: Options to display in the menu. Most browsers will refuse to play slower than 0.5. |
|
||||||
| `quality` | Object | `{ default: 'default', options: ['hd2160', 'hd1440', 'hd1080', 'hd720', 'large', 'medium', 'small', 'tiny', 'default'] }` | Currently only supported by YouTube. `default` is the default quality level, determined by YouTube. `options` are the options to display. |
|
| `quality` | Object | `{ default: 576, options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240] }` | `default` is the default quality level (if it exists in your sources). `options` are the options to display. This is used to filter the available sources. |
|
||||||
| `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. |
|
| `loop` | Object | `{ active: false }` | `active`: Whether to loop the current video. If the `loop` attribute is present on a `<video>` or `<audio>` element, this will be automatically set to true This is an object to support future functionality. |
|
||||||
| `ads` | Object | `{ enabled: false, publisherId: '' }` | `enabled`: Whether to enable vi.ai ads. `publisherId`: Your unique vi.ai publisher ID. |
|
| `ads` | Object | `{ enabled: false, publisherId: '' }` | `enabled`: Whether to enable advertisements. `publisherId`: Your unique [vi.ai](https://vi.ai/publisher-video-monetization/?aid=plyrio) publisher ID. |
|
||||||
|
| `urls` | Object | See source. | If you wish to override any API URLs then you can do so here. You can also set a custom download URL for the download button. |
|
||||||
|
| `vimeo` | Object | `{ byline: false, portrait: false, title: false, speed: true, transparent: false }` | See [Vimeo embed options](https://github.com/vimeo/player.js/#embed-options). Some are set automatically based on other config options, namely: `loop`, `autoplay`, `muted`, `gesture`, `playsinline` |
|
||||||
|
| `youtube` | Object | `{ noCookie: false, rel: 0, showinfo: 0, iv_load_policy: 3, modestbranding: 1 }` | See [YouTube embed options](https://developers.google.com/youtube/player_parameters#Parameters). The only custom option is `noCookie` to use an alternative to YouTube that doesn't use cookies (useful for GDPR, etc). Some are set automatically based on other config options, namely: `autoplay`, `hl`, `controls`, `disablekb`, `playsinline`, `cc_load_policy`, `cc_lang_pref`, `widget_referrer` |
|
||||||
|
| `previewThumbnails` | Object | `{ enabled: false, src: '' }` | `enabled`: Whether to enable the preview thumbnails (they must be generated by you). `src` must be either a string or an array of strings representing URLs for the VTT files containing the image URL(s). Learn more about [preview thumbnails](#preview-thumbnails) below. |
|
||||||
|
|
||||||
1. Vimeo only
|
1. Vimeo only
|
||||||
|
2. Autoplay is generally not recommended as it is seen as a negative user experience. It is also disabled in many browsers. Before raising issues, do your homework. More info can be found here:
|
||||||
|
|
||||||
## API
|
- https://webkit.org/blog/6784/new-video-policies-for-ios/
|
||||||
|
- https://developers.google.com/web/updates/2017/09/autoplay-policy-changes
|
||||||
|
- https://hacks.mozilla.org/2019/02/firefox-66-to-block-automatically-playing-audible-video-and-audio/
|
||||||
|
|
||||||
|
# API
|
||||||
|
|
||||||
There are methods, setters and getters on a Plyr object.
|
There are methods, setters and getters on a Plyr object.
|
||||||
|
|
||||||
### Object
|
## Object
|
||||||
|
|
||||||
The easiest way to access the Plyr object is to set the return value from your call to the constructor to a variable. For example:
|
The easiest way to access the Plyr object is to set the return value from your call to the constructor to a variable. For example:
|
||||||
|
|
||||||
@@ -340,7 +340,7 @@ element.addEventListener('ready', event => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Methods
|
## Methods
|
||||||
|
|
||||||
Example method use:
|
Example method use:
|
||||||
|
|
||||||
@@ -365,16 +365,16 @@ player.fullscreen.enter(); // Enter fullscreen
|
|||||||
| `fullscreen.exit()` | - | Exit fullscreen. |
|
| `fullscreen.exit()` | - | Exit fullscreen. |
|
||||||
| `fullscreen.toggle()` | - | Toggle fullscreen. |
|
| `fullscreen.toggle()` | - | Toggle fullscreen. |
|
||||||
| `airplay()` | - | Trigger the airplay dialog on supported devices. |
|
| `airplay()` | - | Trigger the airplay dialog on supported devices. |
|
||||||
| `toggleControls(toggle)` | Boolean | Toggle the controls (video only). Takes optional truthy value to force it on/off. |
|
| `toggleControls(toggle)` | Boolean | Toggle the controls (video only). Takes optional truthy value to force it on/off. |
|
||||||
| `on(event, function)` | String, Function | Add an event listener for the specified event. |
|
| `on(event, function)` | String, Function | Add an event listener for the specified event. |
|
||||||
| `once(event, function)` | String, Function | Add an event listener for the specified event once. |
|
| `once(event, function)` | String, Function | Add an event listener for the specified event once. |
|
||||||
| `off(event, function)` | String, Function | Remove an event listener for the specified event. |
|
| `off(event, function)` | String, Function | Remove an event listener for the specified event. |
|
||||||
| `supports(type)` | String | Check support for a mime type. |
|
| `supports(type)` | String | Check support for a mime type. |
|
||||||
| `destroy()` | - | Destroy the instance and garbage collect any elements. |
|
| `destroy()` | - | Destroy the instance and garbage collect any elements. |
|
||||||
|
|
||||||
1. For HTML5 players, `play()` will return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) in _some_ browsers - WebKit and Mozilla [according to MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) at time of writing.
|
1. For HTML5 players, `play()` will return a [`Promise`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise) in _some_ browsers - WebKit and Mozilla [according to MDN](https://developer.mozilla.org/en-US/docs/Web/API/HTMLMediaElement/play) at time of writing.
|
||||||
|
|
||||||
### Getters and Setters
|
## Getters and Setters
|
||||||
|
|
||||||
Example setters:
|
Example setters:
|
||||||
|
|
||||||
@@ -391,37 +391,38 @@ player.currentTime; // 10
|
|||||||
player.fullscreen.active; // false;
|
player.fullscreen.active; // false;
|
||||||
```
|
```
|
||||||
|
|
||||||
| Property | Getter | Setter | Description |
|
| Property | Getter | Setter | Description |
|
||||||
| -------------------- | ------ | ------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
| -------------------- | ------ | ------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `isHTML5` | ✓ | - | Returns a boolean indicating if the current player is HTML5. |
|
| `isHTML5` | ✓ | - | Returns a boolean indicating if the current player is HTML5. |
|
||||||
| `isEmbed` | ✓ | - | Returns a boolean indicating if the current player is an embedded player. |
|
| `isEmbed` | ✓ | - | Returns a boolean indicating if the current player is an embedded player. |
|
||||||
| `playing` | ✓ | - | Returns a boolean indicating if the current player is playing. |
|
| `playing` | ✓ | - | Returns a boolean indicating if the current player is playing. |
|
||||||
| `paused` | ✓ | - | Returns a boolean indicating if the current player is paused. |
|
| `paused` | ✓ | - | Returns a boolean indicating if the current player is paused. |
|
||||||
| `stopped` | ✓ | - | Returns a boolean indicating if the current player is stopped. |
|
| `stopped` | ✓ | - | Returns a boolean indicating if the current player is stopped. |
|
||||||
| `ended` | ✓ | - | Returns a boolean indicating if the current player has finished playback. |
|
| `ended` | ✓ | - | Returns a boolean indicating if the current player has finished playback. |
|
||||||
| `buffered` | ✓ | - | Returns a float between 0 and 1 indicating how much of the media is buffered |
|
| `buffered` | ✓ | - | Returns a float between 0 and 1 indicating how much of the media is buffered |
|
||||||
| `currentTime` | ✓ | ✓ | Gets or sets the currentTime for the player. The setter accepts a float in seconds. |
|
| `currentTime` | ✓ | ✓ | Gets or sets the currentTime for the player. The setter accepts a float in seconds. |
|
||||||
| `seeking` | ✓ | - | Returns a boolean indicating if the current player is seeking. |
|
| `seeking` | ✓ | - | Returns a boolean indicating if the current player is seeking. |
|
||||||
| `duration` | ✓ | - | Returns the duration for the current media. |
|
| `duration` | ✓ | - | Returns the duration for the current media. |
|
||||||
| `volume` | ✓ | ✓ | Gets or sets the volume for the player. The setter accepts a float between 0 and 1. |
|
| `volume` | ✓ | ✓ | Gets or sets the volume for the player. The setter accepts a float between 0 and 1. |
|
||||||
| `muted` | ✓ | ✓ | Gets or sets the muted state of the player. The setter accepts a boolean. |
|
| `muted` | ✓ | ✓ | Gets or sets the muted state of the player. The setter accepts a boolean. |
|
||||||
| `hasAudio` | ✓ | - | Returns a boolean indicating if the current media has an audio track. |
|
| `hasAudio` | ✓ | - | Returns a boolean indicating if the current media has an audio track. |
|
||||||
| `speed` | ✓ | ✓ | Gets or sets the speed for the player. The setter accepts a value in the options specified in your config. Generally the minimum should be 0.5. |
|
| `speed` | ✓ | ✓ | Gets or sets the speed for the player. The setter accepts a value in the options specified in your config. Generally the minimum should be 0.5. |
|
||||||
| `quality`¹ | ✓ | ✓ | Gets or sets the quality for the player. The setter accepts a value from the options specified in your config. |
|
| `quality`¹ | ✓ | ✓ | Gets or sets the quality for the player. The setter accepts a value from the options specified in your config. |
|
||||||
| `loop` | ✓ | ✓ | Gets or sets the current loop state of the player. The setter accepts a boolean. |
|
| `loop` | ✓ | ✓ | Gets or sets the current loop state of the player. The setter accepts a boolean. |
|
||||||
| `source` | ✓ | ✓ | Gets or sets the current source for the player. The setter accepts an object. See [source setter](#source-setter) below for examples. |
|
| `source` | ✓ | ✓ | Gets or sets the current source for the player. The setter accepts an object. See [source setter](#the-source-setter) below for examples. |
|
||||||
| `poster` | ✓ | ✓ | Gets or sets the current poster image for the player. The setter accepts a string; the URL for the updated poster image. |
|
| `poster` | ✓ | ✓ | Gets or sets the current poster image for the player. The setter accepts a string; the URL for the updated poster image. |
|
||||||
| `autoplay` | ✓ | ✓ | Gets or sets the autoplay state of the player. The setter accepts a boolean. |
|
| `autoplay` | ✓ | ✓ | Gets or sets the autoplay state of the player. The setter accepts a boolean. |
|
||||||
| `currentTrack` | ✓ | ✓ | Gets or sets the caption track by index. `-1` means the track is missing or captions is not active |
|
| `currentTrack` | ✓ | ✓ | Gets or sets the caption track by index. `-1` means the track is missing or captions is not active |
|
||||||
| `language` | ✓ | ✓ | Gets or sets the preferred captions language for the player. The setter accepts an ISO two-letter language code. Support for the languages is dependent on the captions you include. If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use `currentTrack` instead. |
|
| `language` | ✓ | ✓ | Gets or sets the preferred captions language for the player. The setter accepts an ISO two-letter language code. Support for the languages is dependent on the captions you include. If your captions don't have any language data, or if you have multiple tracks with the same language, you may want to use `currentTrack` instead. |
|
||||||
| `fullscreen.active` | ✓ | - | Returns a boolean indicating if the current player is in fullscreen mode. |
|
| `fullscreen.active` | ✓ | - | Returns a boolean indicating if the current player is in fullscreen mode. |
|
||||||
| `fullscreen.enabled` | ✓ | - | Returns a boolean indicating if the current player has fullscreen enabled. |
|
| `fullscreen.enabled` | ✓ | - | Returns a boolean indicating if the current player has fullscreen enabled. |
|
||||||
| `pip` | ✓ | ✓ | Gets or sets the picture-in-picture state of the player. The setter accepts a boolean. This currently only supported on Safari 10+ on MacOS Sierra+ and iOS 10+. |
|
| `pip`¹ | ✓ | ✓ | Gets or sets the picture-in-picture state of the player. The setter accepts a boolean. This currently only supported on Safari 10+ (on MacOS Sierra+ and iOS 10+) and Chrome 70+. |
|
||||||
|
| `ratio` | ✓ | ✓ | Gets or sets the video aspect ratio. The setter accepts a string in the same format as the `ratio` option. |
|
||||||
|
| `download` | ✓ | ✓ | Gets or sets the URL for the download button. The setter accepts a string containing a valid absolute URL. |
|
||||||
|
|
||||||
1. YouTube only. HTML5 will follow.
|
1. HTML5 only
|
||||||
2. HTML5 only
|
|
||||||
|
|
||||||
#### The `.source` setter
|
### The `.source` setter
|
||||||
|
|
||||||
This allows changing the player source and type on the fly.
|
This allows changing the player source and type on the fly.
|
||||||
|
|
||||||
@@ -435,10 +436,12 @@ player.source = {
|
|||||||
{
|
{
|
||||||
src: '/path/to/movie.mp4',
|
src: '/path/to/movie.mp4',
|
||||||
type: 'video/mp4',
|
type: 'video/mp4',
|
||||||
|
size: 720,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
src: '/path/to/movie.webm',
|
src: '/path/to/movie.webm',
|
||||||
type: 'video/webm',
|
type: 'video/webm',
|
||||||
|
size: 1080,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
poster: '/path/to/poster.jpg',
|
poster: '/path/to/poster.jpg',
|
||||||
@@ -521,7 +524,7 @@ _Note:_ `src` property for YouTube and Vimeo can either be the video ID or the w
|
|||||||
|
|
||||||
1. HTML5 only
|
1. HTML5 only
|
||||||
|
|
||||||
## Events
|
# Events
|
||||||
|
|
||||||
You can listen for events on the target element you setup Plyr on (see example under the table). Some events only apply to HTML5 audio and video. Using your
|
You can listen for events on the target element you setup Plyr on (see example under the table). Some events only apply to HTML5 audio and video. Using your
|
||||||
reference to the instance, you can use the `on()` API method or `addEventListener()`. Access to the API can be obtained this way through the `event.detail.plyr`
|
reference to the instance, you can use the `on()` API method or `addEventListener()`. Access to the API can be obtained this way through the `event.detail.plyr`
|
||||||
@@ -533,7 +536,7 @@ player.on('ready', event => {
|
|||||||
});
|
});
|
||||||
```
|
```
|
||||||
|
|
||||||
### Standard Media Events
|
## Standard Media Events
|
||||||
|
|
||||||
| Event Type | Description |
|
| Event Type | Description |
|
||||||
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
@@ -556,13 +559,14 @@ player.on('ready', event => {
|
|||||||
| `controlsshown` | Sent when the controls are shown. |
|
| `controlsshown` | Sent when the controls are shown. |
|
||||||
| `ready` | Triggered when the instance is ready for API calls. |
|
| `ready` | Triggered when the instance is ready for API calls. |
|
||||||
|
|
||||||
#### HTML5 only
|
### HTML5 only
|
||||||
|
|
||||||
| Event Type | Description |
|
| Event Type | Description |
|
||||||
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ---------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `loadstart` | Sent when loading of the media begins. |
|
| `loadstart` | Sent when loading of the media begins. |
|
||||||
| `loadeddata` | The first frame of the media has finished loading. |
|
| `loadeddata` | The first frame of the media has finished loading. |
|
||||||
| `loadedmetadata` | The media's metadata has finished loading; all attributes now contain as much useful information as they're going to. |
|
| `loadedmetadata` | The media's metadata has finished loading; all attributes now contain as much useful information as they're going to. |
|
||||||
|
| `qualitychange` | The quality of playback has changed. |
|
||||||
| `canplay` | Sent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the `HAVE_ENOUGH_DATA` `readyState`. |
|
| `canplay` | Sent when enough data is available that the media can be played, at least for a couple of frames. This corresponds to the `HAVE_ENOUGH_DATA` `readyState`. |
|
||||||
| `canplaythrough` | Sent when the ready state changes to `CAN_PLAY_THROUGH`, indicating that the entire media can be played without interruption, assuming the download rate remains at least at the current level. _Note:_ Manually setting the `currentTime` will eventually fire a `canplaythrough` event in firefox. Other browsers might not fire this event. |
|
| `canplaythrough` | Sent when the ready state changes to `CAN_PLAY_THROUGH`, indicating that the entire media can be played without interruption, assuming the download rate remains at least at the current level. _Note:_ Manually setting the `currentTime` will eventually fire a `canplaythrough` event in firefox. Other browsers might not fire this event. |
|
||||||
| `stalled` | Sent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming. |
|
| `stalled` | Sent when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming. |
|
||||||
@@ -571,30 +575,28 @@ player.on('ready', event => {
|
|||||||
| `cuechange` | Sent when a `TextTrack` has changed the currently displaying cues. |
|
| `cuechange` | Sent when a `TextTrack` has changed the currently displaying cues. |
|
||||||
| `error` | Sent when an error occurs. The element's `error` attribute contains more information. |
|
| `error` | Sent when an error occurs. The element's `error` attribute contains more information. |
|
||||||
|
|
||||||
#### YouTube only
|
### YouTube only
|
||||||
|
|
||||||
| Event Type | Description |
|
| Event Type | Description |
|
||||||
| ------------------ | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
| ------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||||
| `statechange` | The state of the player has changed. The code can be accessed via `event.detail.code`. Possible values are `-1`: Unstarted, `0`: Ended, `1`: Playing, `2`: Paused, `3`: Buffering, `5`: Video cued. See the [YouTube Docs](https://developers.google.com/youtube/iframe_api_reference#onStateChange) for more information. |
|
| `statechange` | The state of the player has changed. The code can be accessed via `event.detail.code`. Possible values are `-1`: Unstarted, `0`: Ended, `1`: Playing, `2`: Paused, `3`: Buffering, `5`: Video cued. See the [YouTube Docs](https://developers.google.com/youtube/iframe_api_reference#onStateChange) for more information. |
|
||||||
| `qualitychange` | The quality of playback has changed. |
|
|
||||||
| `qualityrequested` | A change to playback quality has been requested. _Note:_ A change to quality can only be _requested_ via the API. There is no guarantee the quality will change to the level requested. You should listen to the `qualitychange` event for true changes. |
|
|
||||||
|
|
||||||
_Note:_ These events also bubble up the DOM. The event target will be the container element.
|
_Note:_ These events also bubble up the DOM. The event target will be the container element.
|
||||||
|
|
||||||
Some event details borrowed from [MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events).
|
Some event details borrowed from [MDN](https://developer.mozilla.org/en-US/docs/Web/Guide/Events/Media_events).
|
||||||
|
|
||||||
## Embeds
|
# Embeds
|
||||||
|
|
||||||
YouTube and Vimeo are currently supported and function much like a HTML5 video. Similar events and API methods are available for all types. However if you wish
|
YouTube and Vimeo are currently supported and function much like a HTML5 video. Similar events and API methods are available for all types. However if you wish
|
||||||
to access the API's directly. You can do so via the `embed` property of your player object - e.g. `player.embed`. You can then use the relevant methods from the
|
to access the API's directly. You can do so via the `embed` property of your player object - e.g. `player.embed`. You can then use the relevant methods from the
|
||||||
third party APIs. More info on the respective API's here:
|
third party APIs. More info on the respective API's here:
|
||||||
|
|
||||||
* [YouTube iframe API Reference](https://developers.google.com/youtube/iframe_api_reference)
|
- [YouTube iframe API Reference](https://developers.google.com/youtube/iframe_api_reference)
|
||||||
* [Vimeo player.js Reference](https://github.com/vimeo/player.js)
|
- [Vimeo player.js Reference](https://github.com/vimeo/player.js)
|
||||||
|
|
||||||
_Note_: Not all API methods may work 100%. Your mileage may vary. It's better to use the Plyr API where possible.
|
_Note_: Not all API methods may work 100%. Your mileage may vary. It's better to use the Plyr API where possible.
|
||||||
|
|
||||||
## Shortcuts
|
# Shortcuts
|
||||||
|
|
||||||
By default, a player will bind the following keyboard shortcuts when it has focus. If you have the `global` option to `true` and there's only one player in the
|
By default, a player will bind the following keyboard shortcuts when it has focus. If you have the `global` option to `true` and there's only one player in the
|
||||||
document then the shortcuts will work when any element has focus, apart from an element that requires input.
|
document then the shortcuts will work when any element has focus, apart from an element that requires input.
|
||||||
@@ -613,11 +615,17 @@ document then the shortcuts will work when any element has focus, apart from an
|
|||||||
| `C` | Toggle captions |
|
| `C` | Toggle captions |
|
||||||
| `L` | Toggle loop |
|
| `L` | Toggle loop |
|
||||||
|
|
||||||
## Fullscreen
|
# Preview thumbnails
|
||||||
|
|
||||||
|
It's possible to display preview thumbnails as per the demo when you hover over the scrubber or while you are scrubbing in the main video area. This can be used for all video types but is easiest with HTML5 of course. You will need to generate the sprite or images yourself. This is possible using something like AWS transcoder to generate the frames and then combine them into a sprite image. Sprites are recommended for performance reasons - they will be much faster to download and easier to compress into a small file size making them load faster.
|
||||||
|
|
||||||
|
You can see the example VTT files [here](https://cdn.plyr.io/static/demo/thumbs/100p.vtt) and [here](https://cdn.plyr.io/static/demo/thumbs/240p.vtt) for how the sprites are done. The coordinates are set as the `xywh` hash on the URL in the order X Offset, Y Offset, Width, Height (e.g. `240p-00001.jpg#xywh=1708,480,427,240` is offset `1708px` from the left, `480px` from the top and is `427x240px`. If you want to include images per frame, this is also possible but will be slower, resulting in a degraded experience.
|
||||||
|
|
||||||
|
# Fullscreen
|
||||||
|
|
||||||
Fullscreen in Plyr is supported by all browsers that [currently support it](http://caniuse.com/#feat=fullscreen).
|
Fullscreen in Plyr is supported by all browsers that [currently support it](http://caniuse.com/#feat=fullscreen).
|
||||||
|
|
||||||
## Browser support
|
# Browser support
|
||||||
|
|
||||||
Plyr supports the last 2 versions of most _modern_ browsers.
|
Plyr supports the last 2 versions of most _modern_ browsers.
|
||||||
|
|
||||||
@@ -636,11 +644,11 @@ Plyr supports the last 2 versions of most _modern_ browsers.
|
|||||||
2. Native player used (no support for `<progress>` or `<input type="range">`) but the API is supported. No native fullscreen support, fallback can be used (see [options](#options)).
|
2. Native player used (no support for `<progress>` or `<input type="range">`) but the API is supported. No native fullscreen support, fallback can be used (see [options](#options)).
|
||||||
3. Polyfills required. See below.
|
3. Polyfills required. See below.
|
||||||
|
|
||||||
### Polyfills
|
## Polyfills
|
||||||
|
|
||||||
Plyr uses ES6 which isn't supported in all browsers quite yet. This means some features will need to be polyfilled to be available otherwise you'll run into issues. We've elected to not burden the ~90% of users that do support these features with extra JS and instead leave polyfilling to you to work out based on your needs. The easiest method I've found is to use [polyfill.io](https://polyfill.io) which provides polyfills based on user agent. This is the method the demo uses.
|
Plyr uses ES6 which isn't supported in all browsers quite yet. This means some features will need to be polyfilled to be available otherwise you'll run into issues. We've elected to not burden the ~90% of users that do support these features with extra JS and instead leave polyfilling to you to work out based on your needs. The easiest method I've found is to use [polyfill.io](https://polyfill.io) which provides polyfills based on user agent. This is the method the demo uses.
|
||||||
|
|
||||||
### Checking for support
|
## Checking for support
|
||||||
|
|
||||||
You can use the static method to check for support. For example
|
You can use the static method to check for support. For example
|
||||||
|
|
||||||
@@ -650,11 +658,11 @@ const supported = Plyr.supported('video', 'html5', true);
|
|||||||
|
|
||||||
The arguments are:
|
The arguments are:
|
||||||
|
|
||||||
* Media type (`audio` or `video`)
|
- Media type (`audio` or `video`)
|
||||||
* Provider (`html5`, `youtube` or `vimeo`)
|
- Provider (`html5`, `youtube` or `vimeo`)
|
||||||
* Whether the player has the `playsinline` attribute (only applicable to iOS 10+)
|
- Whether the player has the `playsinline` attribute (only applicable to iOS 10+)
|
||||||
|
|
||||||
### Disable support programatically
|
## Disable support programmatically
|
||||||
|
|
||||||
The `enabled` option can be used to disable certain User Agents. For example, if you don't want to use Plyr for smartphones, you could use:
|
The `enabled` option can be used to disable certain User Agents. For example, if you don't want to use Plyr for smartphones, you could use:
|
||||||
|
|
||||||
@@ -666,63 +674,72 @@ The `enabled` option can be used to disable certain User Agents. For example, if
|
|||||||
|
|
||||||
If a User Agent is disabled but supports `<video>` and `<audio>` natively, it will use the native player.
|
If a User Agent is disabled but supports `<video>` and `<audio>` natively, it will use the native player.
|
||||||
|
|
||||||
## RangeTouch
|
# Plugins & Components
|
||||||
|
|
||||||
Some touch browsers (particularly Mobile Safari on iOS) seem to have issues with `<input type="range">` elements whereby touching the track to set the value
|
Some awesome folks have made plugins for CMSs and Components for JavaScript frameworks:
|
||||||
doesn't work and sliding the thumb can be tricky. To combat this, I've created [RangeTouch](https://rangetouch.com) which I'd recommend including in your
|
|
||||||
solution. It's a tiny script with a nice benefit for users on touch devices.
|
|
||||||
|
|
||||||
## Issues
|
| Type | Maintainer | Link |
|
||||||
|
| --------- | -------------------------------------------------------------- | -------------------------------------------------------------------------------------------- |
|
||||||
|
| WordPress | Brandon Lavigne ([@drrobotnik](https://github.com/drrobotnik)) | [https://wordpress.org/plugins/plyr/](https://wordpress.org/plugins/plyr/) |
|
||||||
|
| Angular | Simon Bobrov ([@smnbbrv](https://github.com/smnbbrv)) | [https://github.com/smnbbrv/ngx-plyr](https://github.com/smnbbrv/ngx-plyr) |
|
||||||
|
| React | Jose Miguel Bejarano ([@xDae](https://github.com/xDae)) | [https://github.com/xDae/react-plyr](https://github.com/xDae/react-plyr) |
|
||||||
|
| Vue | Gabe Dunn ([@redxtech](https://github.com/redxtech)) | [https://github.com/redxtech/vue-plyr](https://github.com/redxtech/vue-plyr) |
|
||||||
|
| Neos | Jon Uhlmann ([@jonnitto](https://github.com/jonnitto)) | [https://packagist.org/packages/jonnitto/plyr](https://packagist.org/packages/jonnitto/plyr) |
|
||||||
|
| Kirby | Dominik Pschenitschni ([@dpschen](https://github.com/dpschen)) | [https://github.com/dpschen/kirby-plyrtag](https://github.com/dpschen/kirby-plyrtag) |
|
||||||
|
|
||||||
|
# Issues
|
||||||
|
|
||||||
If you find anything weird with Plyr, please let us know using the GitHub issues tracker.
|
If you find anything weird with Plyr, please let us know using the GitHub issues tracker.
|
||||||
|
|
||||||
## Author
|
# Author
|
||||||
|
|
||||||
Plyr is developed by [@sam_potts](https://twitter.com/sam_potts) / [sampotts.me](http://sampotts.me) with help from the awesome
|
Plyr is developed by [@sam_potts](https://twitter.com/sam_potts) / [sampotts.me](http://sampotts.me) with help from the awesome
|
||||||
[contributors](https://github.com/sampotts/plyr/graphs/contributors)
|
[contributors](https://github.com/sampotts/plyr/graphs/contributors)
|
||||||
|
|
||||||
## Donate
|
# Donate
|
||||||
|
|
||||||
Plyr costs money to run, not only my time. I donate my time for free as I enjoy building Plyr but unfortunately have to pay for domains, hosting, and more. Any help with costs is appreciated...
|
Plyr costs money to run, not only my time. I donate my time for free as I enjoy building Plyr but unfortunately have to pay for domains, hosting, and more. Any help with costs is appreciated...
|
||||||
|
|
||||||
* [Donate via Patron](https://www.patreon.com/plyr)
|
- [Donate via Patreon](https://www.patreon.com/plyr)
|
||||||
* [Donate via PayPal](https://www.paypal.me/pottsy/20usd)
|
- [Donate via PayPal](https://www.paypal.me/pottsy/20usd)
|
||||||
|
|
||||||
## Mentions
|
# Mentions
|
||||||
|
|
||||||
* [ProductHunt](https://www.producthunt.com/tech/plyr)
|
- [ProductHunt](https://www.producthunt.com/tech/plyr)
|
||||||
* [The Changelog](http://thechangelog.com/plyr-simple-html5-media-player-custom-controls-webvtt-captions/)
|
- [The Changelog](http://thechangelog.com/plyr-simple-html5-media-player-custom-controls-webvtt-captions/)
|
||||||
* [HTML5 Weekly #177](http://html5weekly.com/issues/177)
|
- [HTML5 Weekly #177](http://html5weekly.com/issues/177)
|
||||||
* [Responsive Design #149](http://us4.campaign-archive2.com/?u=559bc631fe5294fc66f5f7f89&id=451a61490f)
|
- [Responsive Design #149](http://us4.campaign-archive2.com/?u=559bc631fe5294fc66f5f7f89&id=451a61490f)
|
||||||
* [Web Design Weekly #174](https://web-design-weekly.com/2015/02/24/web-design-weekly-174/)
|
- [Web Design Weekly #174](https://web-design-weekly.com/2015/02/24/web-design-weekly-174/)
|
||||||
* [Hacker News](https://news.ycombinator.com/item?id=9136774)
|
- [Front End Focus #177](https://frontendfoc.us/issues/177)
|
||||||
* [Web Platform Daily](http://webplatformdaily.org/releases/2015-03-04)
|
- [Hacker News](https://news.ycombinator.com/item?id=9136774)
|
||||||
* [LayerVault Designer News](https://news.layervault.com/stories/45394-plyr--a-simple-html5-media-player)
|
- [Web Platform Daily](http://webplatformdaily.org/releases/2015-03-04)
|
||||||
* [The Treehouse Show #131](https://teamtreehouse.com/library/episode-131-origami-react-responsive-hero-images)
|
- [LayerVault Designer News](https://news.layervault.com/stories/45394-plyr--a-simple-html5-media-player)
|
||||||
* [noupe.com](http://www.noupe.com/design/html5-plyr-is-a-responsive-and-accessible-video-player-94389.html)
|
- [The Treehouse Show #131](https://teamtreehouse.com/library/episode-131-origami-react-responsive-hero-images)
|
||||||
|
- [noupe.com](http://www.noupe.com/design/html5-plyr-is-a-responsive-and-accessible-video-player-94389.html)
|
||||||
|
|
||||||
## Used by
|
# Used by
|
||||||
|
|
||||||
* [Selz.com](https://selz.com)
|
- [Selz.com](https://selz.com)
|
||||||
* [Peugeot.fr](http://www.peugeot.fr/marque-et-technologie/technologies/peugeot-i-cockpit.html)
|
- [Peugeot.fr](http://www.peugeot.fr/marque-et-technologie/technologies/peugeot-i-cockpit.html)
|
||||||
* [Peugeot.de](http://www.peugeot.de/modelle/modellberater/208-3-turer/fotos-videos.html)
|
- [Peugeot.de](http://www.peugeot.de/modelle/modellberater/208-3-turer/fotos-videos.html)
|
||||||
* [TomTom.com](http://prioritydriving.tomtom.com/)
|
- [TomTom.com](http://prioritydriving.tomtom.com/)
|
||||||
* [DIGBMX](http://digbmx.com/)
|
- [DIGBMX](http://digbmx.com/)
|
||||||
* [Grime Archive](https://grimearchive.com/)
|
- [Grime Archive](https://grimearchive.com/)
|
||||||
* [koel - A personal music streaming server that works.](http://koel.phanan.net/)
|
- [koel - A personal music streaming server that works.](http://koel.phanan.net/)
|
||||||
* [Oscar Radio](http://oscar-radio.xyz/)
|
- [Oscar Radio](http://oscar-radio.xyz/)
|
||||||
* [Sparkk TV](https://www.sparkktv.com/)
|
- [Sparkk TV](https://www.sparkktv.com/)
|
||||||
|
- [@halfhalftravel](https://www.halfhalftravel.com/)
|
||||||
|
|
||||||
Let me know on [Twitter](https://twitter.com/sam_potts) I can add you to the above list. It'd be awesome to see how you're using Plyr :-)
|
If you want to be added to the list, open a pull request. It'd be awesome to see how you're using Plyr 😎
|
||||||
|
|
||||||
## Useful links and credits
|
# Useful links and credits
|
||||||
|
|
||||||
Credit to the PayPal HTML5 Video player from which Plyr's caption functionality was originally ported from:
|
Credit to the PayPal HTML5 Video player from which Plyr's caption functionality was originally ported from:
|
||||||
|
|
||||||
* [PayPal's Accessible HTML5 Video Player](https://github.com/paypal/accessible-html5-video-player)
|
- [PayPal's Accessible HTML5 Video Player](https://github.com/paypal/accessible-html5-video-player)
|
||||||
* [An awesome guide for Plyr in Japanese!](http://syncer.jp/how-to-use-plyr-io) by [@arayutw](https://twitter.com/arayutw)
|
- [An awesome guide for Plyr in Japanese!](http://syncer.jp/how-to-use-plyr-io) by [@arayutw](https://twitter.com/arayutw)
|
||||||
|
|
||||||
## Thanks
|
# Thanks
|
||||||
|
|
||||||
[](https://www.fastly.com/)
|
[](https://www.fastly.com/)
|
||||||
|
|
||||||
@@ -732,6 +749,6 @@ Massive thanks to [Fastly](https://www.fastly.com/) for providing the CDN servic
|
|||||||
|
|
||||||
Massive thanks to [Sentry](https://sentry.io/) for providing the logging services for the demo site.
|
Massive thanks to [Sentry](https://sentry.io/) for providing the logging services for the demo site.
|
||||||
|
|
||||||
## Copyright and License
|
# Copyright and License
|
||||||
|
|
||||||
[The MIT license](license.md)
|
[The MIT license](license.md)
|
||||||
|
|||||||
+26
-21
@@ -4,7 +4,6 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import controls from './controls';
|
import controls from './controls';
|
||||||
import i18n from './i18n';
|
|
||||||
import support from './support';
|
import support from './support';
|
||||||
import { dedupe } from './utils/arrays';
|
import { dedupe } from './utils/arrays';
|
||||||
import browser from './utils/browser';
|
import browser from './utils/browser';
|
||||||
@@ -18,6 +17,7 @@ import {
|
|||||||
} from './utils/elements';
|
} from './utils/elements';
|
||||||
import { on, triggerEvent } from './utils/events';
|
import { on, triggerEvent } from './utils/events';
|
||||||
import fetch from './utils/fetch';
|
import fetch from './utils/fetch';
|
||||||
|
import i18n from './utils/i18n';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
import { getHTML } from './utils/strings';
|
import { getHTML } from './utils/strings';
|
||||||
import { parseUrl } from './utils/urls';
|
import { parseUrl } from './utils/urls';
|
||||||
@@ -83,10 +83,8 @@ const captions = {
|
|||||||
// * active: The state preferred by user settings or config
|
// * active: The state preferred by user settings or config
|
||||||
// * toggled: The real captions state
|
// * toggled: The real captions state
|
||||||
|
|
||||||
const languages = dedupe(
|
const browserLanguages = navigator.languages || [navigator.language || navigator.userLanguage || 'en'];
|
||||||
Array.from(navigator.languages || navigator.userLanguage).map(language => language.split('-')[0]),
|
const languages = dedupe(browserLanguages.map(language => language.split('-')[0]));
|
||||||
);
|
|
||||||
|
|
||||||
let language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase();
|
let language = (this.storage.get('language') || this.config.captions.language || 'auto').toLowerCase();
|
||||||
|
|
||||||
// Use first browser language when language is 'auto'
|
// Use first browser language when language is 'auto'
|
||||||
@@ -125,19 +123,22 @@ const captions = {
|
|||||||
|
|
||||||
// Handle tracks (add event listener and "pseudo"-default)
|
// Handle tracks (add event listener and "pseudo"-default)
|
||||||
if (this.isHTML5 && this.isVideo) {
|
if (this.isHTML5 && this.isVideo) {
|
||||||
tracks.filter(track => !meta.get(track)).forEach(track => {
|
tracks
|
||||||
this.debug.log('Track added', track);
|
.filter(track => !meta.get(track))
|
||||||
// Attempt to store if the original dom element was "default"
|
.forEach(track => {
|
||||||
meta.set(track, {
|
this.debug.log('Track added', track);
|
||||||
default: track.mode === 'showing',
|
// Attempt to store if the original dom element was "default"
|
||||||
|
meta.set(track, {
|
||||||
|
default: track.mode === 'showing',
|
||||||
|
});
|
||||||
|
|
||||||
|
// Turn off native caption rendering to avoid double captions
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
track.mode = 'hidden';
|
||||||
|
|
||||||
|
// Add event listener for cue changes
|
||||||
|
on.call(this, track, 'cuechange', () => captions.updateCues.call(this));
|
||||||
});
|
});
|
||||||
|
|
||||||
// Turn off native caption rendering to avoid double captions
|
|
||||||
track.mode = 'hidden';
|
|
||||||
|
|
||||||
// Add event listener for cue changes
|
|
||||||
on.call(this, track, 'cuechange', () => captions.updateCues.call(this));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update language first time it matches, or if the previous matching track was removed
|
// Update language first time it matches, or if the previous matching track was removed
|
||||||
@@ -165,7 +166,6 @@ const captions = {
|
|||||||
|
|
||||||
const { toggled } = this.captions; // Current state
|
const { toggled } = this.captions; // Current state
|
||||||
const activeClass = this.config.classNames.captions.active;
|
const activeClass = this.config.classNames.captions.active;
|
||||||
|
|
||||||
// Get the next state
|
// Get the next state
|
||||||
// If the method is called without parameter, toggle based on current value
|
// If the method is called without parameter, toggle based on current value
|
||||||
const active = is.nullOrUndefined(input) ? !toggled : input;
|
const active = is.nullOrUndefined(input) ? !toggled : input;
|
||||||
@@ -191,8 +191,10 @@ const captions = {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle state
|
// Toggle button if it's enabled
|
||||||
this.elements.buttons.captions.pressed = active;
|
if (this.elements.buttons.captions) {
|
||||||
|
this.elements.buttons.captions.pressed = active;
|
||||||
|
}
|
||||||
|
|
||||||
// Add class hook
|
// Add class hook
|
||||||
toggleClass(this.elements.container, activeClass, active);
|
toggleClass(this.elements.container, activeClass, active);
|
||||||
@@ -299,10 +301,12 @@ const captions = {
|
|||||||
const sortIsDefault = track => Number((this.captions.meta.get(track) || {}).default);
|
const sortIsDefault = track => Number((this.captions.meta.get(track) || {}).default);
|
||||||
const sorted = Array.from(tracks).sort((a, b) => sortIsDefault(b) - sortIsDefault(a));
|
const sorted = Array.from(tracks).sort((a, b) => sortIsDefault(b) - sortIsDefault(a));
|
||||||
let track;
|
let track;
|
||||||
|
|
||||||
languages.every(language => {
|
languages.every(language => {
|
||||||
track = sorted.find(track => track.language === language);
|
track = sorted.find(t => t.language === language);
|
||||||
return !track; // Break iteration if there is a match
|
return !track; // Break iteration if there is a match
|
||||||
});
|
});
|
||||||
|
|
||||||
// If no match is found but is required, get first
|
// If no match is found but is required, get first
|
||||||
return track || (force ? sorted[0] : undefined);
|
return track || (force ? sorted[0] : undefined);
|
||||||
},
|
},
|
||||||
@@ -359,6 +363,7 @@ const captions = {
|
|||||||
// Get cues from track
|
// Get cues from track
|
||||||
if (!cues) {
|
if (!cues) {
|
||||||
const track = captions.getCurrentTrack.call(this);
|
const track = captions.getCurrentTrack.call(this);
|
||||||
|
|
||||||
cues = Array.from((track || {}).activeCues || [])
|
cues = Array.from((track || {}).activeCues || [])
|
||||||
.map(cue => cue.getCueAsHTML())
|
.map(cue => cue.getCueAsHTML())
|
||||||
.map(getHTML);
|
.map(getHTML);
|
||||||
|
|||||||
+55
-28
@@ -42,8 +42,9 @@ const defaults = {
|
|||||||
// Clicking the currentTime inverts it's value to show time left rather than elapsed
|
// Clicking the currentTime inverts it's value to show time left rather than elapsed
|
||||||
toggleInvert: true,
|
toggleInvert: true,
|
||||||
|
|
||||||
// Aspect ratio (for embeds)
|
// Force an aspect ratio
|
||||||
ratio: '16:9',
|
// The format must be `'w:h'` (e.g. `'16:9'`)
|
||||||
|
ratio: null,
|
||||||
|
|
||||||
// Click video container to play/pause
|
// Click video container to play/pause
|
||||||
clickToPlay: true,
|
clickToPlay: true,
|
||||||
@@ -60,7 +61,7 @@ const defaults = {
|
|||||||
// Sprite (for icons)
|
// Sprite (for icons)
|
||||||
loadSprite: true,
|
loadSprite: true,
|
||||||
iconPrefix: 'plyr',
|
iconPrefix: 'plyr',
|
||||||
iconUrl: 'https://cdn.plyr.io/3.3.12/plyr.svg',
|
iconUrl: 'https://cdn.plyr.io/3.5.5/plyr.svg',
|
||||||
|
|
||||||
// Blank video (used to prevent errors on source change)
|
// Blank video (used to prevent errors on source change)
|
||||||
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
|
blankVideo: 'https://cdn.plyr.io/static/blank.mp4',
|
||||||
@@ -68,19 +69,7 @@ const defaults = {
|
|||||||
// Quality default
|
// Quality default
|
||||||
quality: {
|
quality: {
|
||||||
default: 576,
|
default: 576,
|
||||||
options: [
|
options: [4320, 2880, 2160, 1440, 1080, 720, 576, 480, 360, 240],
|
||||||
4320,
|
|
||||||
2880,
|
|
||||||
2160,
|
|
||||||
1440,
|
|
||||||
1080,
|
|
||||||
720,
|
|
||||||
576,
|
|
||||||
480,
|
|
||||||
360,
|
|
||||||
240,
|
|
||||||
'default', // YouTube's "auto"
|
|
||||||
],
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set loops
|
// Set loops
|
||||||
@@ -120,7 +109,7 @@ const defaults = {
|
|||||||
// Fullscreen settings
|
// Fullscreen settings
|
||||||
fullscreen: {
|
fullscreen: {
|
||||||
enabled: true, // Allow fullscreen?
|
enabled: true, // Allow fullscreen?
|
||||||
fallback: true, // Fallback for vintage browsers
|
fallback: true, // Fallback using full viewport/window
|
||||||
iosNative: false, // Use the native fullscreen in iOS (disables custom controls)
|
iosNative: false, // Use the native fullscreen in iOS (disables custom controls)
|
||||||
},
|
},
|
||||||
|
|
||||||
@@ -139,12 +128,14 @@ const defaults = {
|
|||||||
// 'fast-forward',
|
// 'fast-forward',
|
||||||
'progress',
|
'progress',
|
||||||
'current-time',
|
'current-time',
|
||||||
|
// 'duration',
|
||||||
'mute',
|
'mute',
|
||||||
'volume',
|
'volume',
|
||||||
'captions',
|
'captions',
|
||||||
'settings',
|
'settings',
|
||||||
'pip',
|
'pip',
|
||||||
'airplay',
|
'airplay',
|
||||||
|
// 'download',
|
||||||
'fullscreen',
|
'fullscreen',
|
||||||
],
|
],
|
||||||
settings: ['captions', 'quality', 'speed'],
|
settings: ['captions', 'quality', 'speed'],
|
||||||
@@ -167,6 +158,7 @@ const defaults = {
|
|||||||
unmute: 'Unmute',
|
unmute: 'Unmute',
|
||||||
enableCaptions: 'Enable captions',
|
enableCaptions: 'Enable captions',
|
||||||
disableCaptions: 'Disable captions',
|
disableCaptions: 'Disable captions',
|
||||||
|
download: 'Download',
|
||||||
enterFullscreen: 'Enter fullscreen',
|
enterFullscreen: 'Enter fullscreen',
|
||||||
exitFullscreen: 'Exit fullscreen',
|
exitFullscreen: 'Exit fullscreen',
|
||||||
frameTitle: 'Player for {title}',
|
frameTitle: 'Player for {title}',
|
||||||
@@ -196,6 +188,7 @@ const defaults = {
|
|||||||
|
|
||||||
// URLs
|
// URLs
|
||||||
urls: {
|
urls: {
|
||||||
|
download: null,
|
||||||
vimeo: {
|
vimeo: {
|
||||||
sdk: 'https://player.vimeo.com/api/player.js',
|
sdk: 'https://player.vimeo.com/api/player.js',
|
||||||
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
iframe: 'https://player.vimeo.com/video/{0}?{1}',
|
||||||
@@ -203,8 +196,7 @@ const defaults = {
|
|||||||
},
|
},
|
||||||
youtube: {
|
youtube: {
|
||||||
sdk: 'https://www.youtube.com/iframe_api',
|
sdk: 'https://www.youtube.com/iframe_api',
|
||||||
api:
|
api: 'https://noembed.com/embed?url=https://www.youtube.com/watch?v={0}',
|
||||||
'https://www.googleapis.com/youtube/v3/videos?id={0}&key={1}&fields=items(snippet(title))&part=snippet',
|
|
||||||
},
|
},
|
||||||
googleIMA: {
|
googleIMA: {
|
||||||
sdk: 'https://imasdk.googleapis.com/js/sdkloader/ima3.js',
|
sdk: 'https://imasdk.googleapis.com/js/sdkloader/ima3.js',
|
||||||
@@ -222,6 +214,7 @@ const defaults = {
|
|||||||
mute: null,
|
mute: null,
|
||||||
volume: null,
|
volume: null,
|
||||||
captions: null,
|
captions: null,
|
||||||
|
download: null,
|
||||||
fullscreen: null,
|
fullscreen: null,
|
||||||
pip: null,
|
pip: null,
|
||||||
airplay: null,
|
airplay: null,
|
||||||
@@ -257,6 +250,7 @@ const defaults = {
|
|||||||
'cuechange',
|
'cuechange',
|
||||||
|
|
||||||
// Custom events
|
// Custom events
|
||||||
|
'download',
|
||||||
'enterfullscreen',
|
'enterfullscreen',
|
||||||
'exitfullscreen',
|
'exitfullscreen',
|
||||||
'captionsenabled',
|
'captionsenabled',
|
||||||
@@ -268,8 +262,9 @@ const defaults = {
|
|||||||
|
|
||||||
// YouTube
|
// YouTube
|
||||||
'statechange',
|
'statechange',
|
||||||
|
|
||||||
|
// Quality
|
||||||
'qualitychange',
|
'qualitychange',
|
||||||
'qualityrequested',
|
|
||||||
|
|
||||||
// Ads
|
// Ads
|
||||||
'adsloaded',
|
'adsloaded',
|
||||||
@@ -301,6 +296,7 @@ const defaults = {
|
|||||||
fastForward: '[data-plyr="fast-forward"]',
|
fastForward: '[data-plyr="fast-forward"]',
|
||||||
mute: '[data-plyr="mute"]',
|
mute: '[data-plyr="mute"]',
|
||||||
captions: '[data-plyr="captions"]',
|
captions: '[data-plyr="captions"]',
|
||||||
|
download: '[data-plyr="download"]',
|
||||||
fullscreen: '[data-plyr="fullscreen"]',
|
fullscreen: '[data-plyr="fullscreen"]',
|
||||||
pip: '[data-plyr="pip"]',
|
pip: '[data-plyr="pip"]',
|
||||||
airplay: '[data-plyr="airplay"]',
|
airplay: '[data-plyr="airplay"]',
|
||||||
@@ -324,9 +320,6 @@ const defaults = {
|
|||||||
progress: '.plyr__progress',
|
progress: '.plyr__progress',
|
||||||
captions: '.plyr__captions',
|
captions: '.plyr__captions',
|
||||||
caption: '.plyr__caption',
|
caption: '.plyr__caption',
|
||||||
menu: {
|
|
||||||
quality: '.js-plyr__menu__list--quality',
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
|
|
||||||
// Class hooks added to the player in different states
|
// Class hooks added to the player in different states
|
||||||
@@ -335,6 +328,7 @@ const defaults = {
|
|||||||
provider: 'plyr--{0}',
|
provider: 'plyr--{0}',
|
||||||
video: 'plyr__video-wrapper',
|
video: 'plyr__video-wrapper',
|
||||||
embed: 'plyr__video-embed',
|
embed: 'plyr__video-embed',
|
||||||
|
videoFixedRatio: 'plyr__video-wrapper--fixed-ratio',
|
||||||
embedContainer: 'plyr__video-embed__container',
|
embedContainer: 'plyr__video-embed__container',
|
||||||
poster: 'plyr__poster',
|
poster: 'plyr__poster',
|
||||||
posterEnabled: 'plyr__poster-enabled',
|
posterEnabled: 'plyr__poster-enabled',
|
||||||
@@ -354,6 +348,9 @@ const defaults = {
|
|||||||
isTouch: 'plyr--is-touch',
|
isTouch: 'plyr--is-touch',
|
||||||
uiSupported: 'plyr--full-ui',
|
uiSupported: 'plyr--full-ui',
|
||||||
noTransition: 'plyr--no-transition',
|
noTransition: 'plyr--no-transition',
|
||||||
|
display: {
|
||||||
|
time: 'plyr__time',
|
||||||
|
},
|
||||||
menu: {
|
menu: {
|
||||||
value: 'plyr__menu__value',
|
value: 'plyr__menu__value',
|
||||||
badge: 'plyr__badge',
|
badge: 'plyr__badge',
|
||||||
@@ -376,6 +373,16 @@ const defaults = {
|
|||||||
active: 'plyr--airplay-active',
|
active: 'plyr--airplay-active',
|
||||||
},
|
},
|
||||||
tabFocus: 'plyr__tab-focus',
|
tabFocus: 'plyr__tab-focus',
|
||||||
|
previewThumbnails: {
|
||||||
|
// Tooltip thumbs
|
||||||
|
thumbContainer: 'plyr__preview-thumb',
|
||||||
|
thumbContainerShown: 'plyr__preview-thumb--is-shown',
|
||||||
|
imageContainer: 'plyr__preview-thumb__image-container',
|
||||||
|
timeContainer: 'plyr__preview-thumb__time-container',
|
||||||
|
// Scrubbing
|
||||||
|
scrubbingContainer: 'plyr__preview-scrubbing',
|
||||||
|
scrubbingContainerShown: 'plyr__preview-scrubbing--is-shown',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// Embed attributes
|
// Embed attributes
|
||||||
@@ -386,16 +393,36 @@ const defaults = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
// API keys
|
|
||||||
keys: {
|
|
||||||
google: null,
|
|
||||||
},
|
|
||||||
|
|
||||||
// Advertisements plugin
|
// Advertisements plugin
|
||||||
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
|
// Register for an account here: http://vi.ai/publisher-video-monetization/?aid=plyrio
|
||||||
ads: {
|
ads: {
|
||||||
enabled: false,
|
enabled: false,
|
||||||
publisherId: '',
|
publisherId: '',
|
||||||
|
tagUrl: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
// Preview Thumbnails plugin
|
||||||
|
previewThumbnails: {
|
||||||
|
enabled: false,
|
||||||
|
src: '',
|
||||||
|
},
|
||||||
|
|
||||||
|
// Vimeo plugin
|
||||||
|
vimeo: {
|
||||||
|
byline: false,
|
||||||
|
portrait: false,
|
||||||
|
title: false,
|
||||||
|
speed: true,
|
||||||
|
transparent: false,
|
||||||
|
},
|
||||||
|
|
||||||
|
// YouTube plugin
|
||||||
|
youtube: {
|
||||||
|
noCookie: false, // Whether to use an alternative version of YouTube without cookies
|
||||||
|
rel: 0, // No related vids
|
||||||
|
showinfo: 0, // Hide info
|
||||||
|
iv_load_policy: 3, // Hide annotations
|
||||||
|
modestbranding: 1, // Hide logos as much as possible (they still show one in the corner when paused)
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
// ==========================================================================
|
||||||
|
// Plyr states
|
||||||
|
// ==========================================================================
|
||||||
|
|
||||||
|
export const pip = {
|
||||||
|
active: 'picture-in-picture',
|
||||||
|
inactive: 'inline',
|
||||||
|
};
|
||||||
|
|
||||||
|
export default { pip };
|
||||||
@@ -15,11 +15,11 @@ export const types = {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Get provider by URL
|
* Get provider by URL
|
||||||
* @param {string} url
|
* @param {String} url
|
||||||
*/
|
*/
|
||||||
export function getProviderByUrl(url) {
|
export function getProviderByUrl(url) {
|
||||||
// YouTube
|
// YouTube
|
||||||
if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtu\.?be)\/.+$/.test(url)) {
|
if (/^(https?:\/\/)?(www\.)?(youtube\.com|youtube-nocookie\.com|youtu\.?be)\/.+$/.test(url)) {
|
||||||
return providers.youtube;
|
return providers.youtube;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -17,10 +17,12 @@ export default class Console {
|
|||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
return this.enabled ? Function.prototype.bind.call(console.log, console) : noop;
|
return this.enabled ? Function.prototype.bind.call(console.log, console) : noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
get warn() {
|
get warn() {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
return this.enabled ? Function.prototype.bind.call(console.warn, console) : noop;
|
return this.enabled ? Function.prototype.bind.call(console.warn, console) : noop;
|
||||||
}
|
}
|
||||||
|
|
||||||
get error() {
|
get error() {
|
||||||
// eslint-disable-next-line no-console
|
// eslint-disable-next-line no-console
|
||||||
return this.enabled ? Function.prototype.bind.call(console.error, console) : noop;
|
return this.enabled ? Function.prototype.bind.call(console.error, console) : noop;
|
||||||
|
|||||||
Vendored
+821
-544
File diff suppressed because it is too large
Load Diff
+52
-7
@@ -1,6 +1,7 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Fullscreen wrapper
|
// Fullscreen wrapper
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API#prefixing
|
// https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API#prefixing
|
||||||
|
// https://webkit.org/blog/7929/designing-websites-for-iphone-x/
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import browser from './utils/browser';
|
import browser from './utils/browser';
|
||||||
@@ -45,6 +46,34 @@ function toggleFallback(toggle = false) {
|
|||||||
// Toggle class hook
|
// Toggle class hook
|
||||||
toggleClass(this.target, this.player.config.classNames.fullscreen.fallback, toggle);
|
toggleClass(this.target, this.player.config.classNames.fullscreen.fallback, toggle);
|
||||||
|
|
||||||
|
// Force full viewport on iPhone X+
|
||||||
|
if (browser.isIos) {
|
||||||
|
let viewport = document.head.querySelector('meta[name="viewport"]');
|
||||||
|
const property = 'viewport-fit=cover';
|
||||||
|
|
||||||
|
// Inject the viewport meta if required
|
||||||
|
if (!viewport) {
|
||||||
|
viewport = document.createElement('meta');
|
||||||
|
viewport.setAttribute('name', 'viewport');
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if the property already exists
|
||||||
|
const hasProperty = is.string(viewport.content) && viewport.content.includes(property);
|
||||||
|
|
||||||
|
if (toggle) {
|
||||||
|
this.cleanupViewport = !hasProperty;
|
||||||
|
|
||||||
|
if (!hasProperty) {
|
||||||
|
viewport.content += `,${property}`;
|
||||||
|
}
|
||||||
|
} else if (this.cleanupViewport) {
|
||||||
|
viewport.content = viewport.content
|
||||||
|
.split(',')
|
||||||
|
.filter(part => part.trim() !== property)
|
||||||
|
.join(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Toggle button and fire events
|
// Toggle button and fire events
|
||||||
onChange.call(this);
|
onChange.call(this);
|
||||||
}
|
}
|
||||||
@@ -61,6 +90,9 @@ class Fullscreen {
|
|||||||
// Scroll position
|
// Scroll position
|
||||||
this.scrollPosition = { x: 0, y: 0 };
|
this.scrollPosition = { x: 0, y: 0 };
|
||||||
|
|
||||||
|
// Force the use of 'full window/browser' rather than fullscreen
|
||||||
|
this.forceFallback = player.config.fullscreen.fallback === 'force';
|
||||||
|
|
||||||
// Register event listeners
|
// Register event listeners
|
||||||
// Handle event (incase user presses escape etc)
|
// Handle event (incase user presses escape etc)
|
||||||
on.call(
|
on.call(
|
||||||
@@ -97,6 +129,11 @@ class Fullscreen {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// If we're actually using native
|
||||||
|
get usingNative() {
|
||||||
|
return Fullscreen.native && !this.forceFallback;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the prefix for handlers
|
// Get the prefix for handlers
|
||||||
static get prefix() {
|
static get prefix() {
|
||||||
// No prefix
|
// No prefix
|
||||||
@@ -141,7 +178,7 @@ class Fullscreen {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Fallback using classname
|
// Fallback using classname
|
||||||
if (!Fullscreen.native) {
|
if (!Fullscreen.native || this.forceFallback) {
|
||||||
return hasClass(this.target, this.player.config.classNames.fullscreen.fallback);
|
return hasClass(this.target, this.player.config.classNames.fullscreen.fallback);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +197,17 @@ class Fullscreen {
|
|||||||
// Update UI
|
// Update UI
|
||||||
update() {
|
update() {
|
||||||
if (this.enabled) {
|
if (this.enabled) {
|
||||||
this.player.debug.log(`${Fullscreen.native ? 'Native' : 'Fallback'} fullscreen enabled`);
|
let mode;
|
||||||
|
|
||||||
|
if (this.forceFallback) {
|
||||||
|
mode = 'Fallback (forced)';
|
||||||
|
} else if (Fullscreen.native) {
|
||||||
|
mode = 'Native';
|
||||||
|
} else {
|
||||||
|
mode = 'Fallback';
|
||||||
|
}
|
||||||
|
|
||||||
|
this.player.debug.log(`${mode} fullscreen enabled`);
|
||||||
} else {
|
} else {
|
||||||
this.player.debug.log('Fullscreen not supported and fallback disabled');
|
this.player.debug.log('Fullscreen not supported and fallback disabled');
|
||||||
}
|
}
|
||||||
@@ -177,10 +224,8 @@ class Fullscreen {
|
|||||||
|
|
||||||
// iOS native fullscreen doesn't need the request step
|
// iOS native fullscreen doesn't need the request step
|
||||||
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
||||||
if (this.player.playing) {
|
this.target.webkitEnterFullscreen();
|
||||||
this.target.webkitEnterFullscreen();
|
} else if (!Fullscreen.native || this.forceFallback) {
|
||||||
}
|
|
||||||
} else if (!Fullscreen.native) {
|
|
||||||
toggleFallback.call(this, true);
|
toggleFallback.call(this, true);
|
||||||
} else if (!this.prefix) {
|
} else if (!this.prefix) {
|
||||||
this.target.requestFullscreen();
|
this.target.requestFullscreen();
|
||||||
@@ -199,7 +244,7 @@ class Fullscreen {
|
|||||||
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
if (browser.isIos && this.player.config.fullscreen.iosNative) {
|
||||||
this.target.webkitExitFullscreen();
|
this.target.webkitExitFullscreen();
|
||||||
this.player.play();
|
this.player.play();
|
||||||
} else if (!Fullscreen.native) {
|
} else if (!Fullscreen.native || this.forceFallback) {
|
||||||
toggleFallback.call(this, false);
|
toggleFallback.call(this, false);
|
||||||
} else if (!this.prefix) {
|
} else if (!this.prefix) {
|
||||||
(document.cancelFullScreen || document.exitFullscreen).call(document);
|
(document.cancelFullScreen || document.exitFullscreen).call(document);
|
||||||
|
|||||||
+19
-5
@@ -5,6 +5,8 @@
|
|||||||
import support from './support';
|
import support from './support';
|
||||||
import { removeElement } from './utils/elements';
|
import { removeElement } from './utils/elements';
|
||||||
import { triggerEvent } from './utils/events';
|
import { triggerEvent } from './utils/events';
|
||||||
|
import is from './utils/is';
|
||||||
|
import { setAspectRatio } from './utils/style';
|
||||||
|
|
||||||
const html5 = {
|
const html5 = {
|
||||||
getSources() {
|
getSources() {
|
||||||
@@ -14,8 +16,16 @@ const html5 = {
|
|||||||
|
|
||||||
const sources = Array.from(this.media.querySelectorAll('source'));
|
const sources = Array.from(this.media.querySelectorAll('source'));
|
||||||
|
|
||||||
// Filter out unsupported sources
|
// Filter out unsupported sources (if type is specified)
|
||||||
return sources.filter(source => support.mime.call(this, source.getAttribute('type')));
|
return sources.filter(source => {
|
||||||
|
const type = source.getAttribute('type');
|
||||||
|
|
||||||
|
if (is.empty(type)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return support.mime.call(this, type);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get quality levels
|
// Get quality levels
|
||||||
@@ -34,12 +44,17 @@ const html5 = {
|
|||||||
|
|
||||||
const player = this;
|
const player = this;
|
||||||
|
|
||||||
|
// Set aspect ratio if fixed
|
||||||
|
if (!is.empty(this.config.ratio)) {
|
||||||
|
setAspectRatio.call(player);
|
||||||
|
}
|
||||||
|
|
||||||
// Quality
|
// Quality
|
||||||
Object.defineProperty(player.media, 'quality', {
|
Object.defineProperty(player.media, 'quality', {
|
||||||
get() {
|
get() {
|
||||||
// Get sources
|
// Get sources
|
||||||
const sources = html5.getSources.call(player);
|
const sources = html5.getSources.call(player);
|
||||||
const source = sources.find(source => source.getAttribute('src') === player.source);
|
const source = sources.find(s => s.getAttribute('src') === player.source);
|
||||||
|
|
||||||
// Return size, if match is found
|
// Return size, if match is found
|
||||||
return source && Number(source.getAttribute('size'));
|
return source && Number(source.getAttribute('size'));
|
||||||
@@ -47,9 +62,8 @@ const html5 = {
|
|||||||
set(input) {
|
set(input) {
|
||||||
// Get sources
|
// Get sources
|
||||||
const sources = html5.getSources.call(player);
|
const sources = html5.getSources.call(player);
|
||||||
|
|
||||||
// Get first match for requested size
|
// Get first match for requested size
|
||||||
const source = sources.find(source => Number(source.getAttribute('size')) === input);
|
const source = sources.find(s => Number(s.getAttribute('size')) === input);
|
||||||
|
|
||||||
// No matching source found
|
// No matching source found
|
||||||
if (!source) {
|
if (!source) {
|
||||||
|
|||||||
+450
-289
File diff suppressed because it is too large
Load Diff
+121
-84
@@ -6,23 +6,37 @@
|
|||||||
|
|
||||||
/* global google */
|
/* global google */
|
||||||
|
|
||||||
import i18n from '../i18n';
|
import { createElement } from '../utils/elements';
|
||||||
import { createElement } from './../utils/elements';
|
import { triggerEvent } from '../utils/events';
|
||||||
import { triggerEvent } from './../utils/events';
|
import i18n from '../utils/i18n';
|
||||||
import is from './../utils/is';
|
import is from '../utils/is';
|
||||||
import loadScript from './../utils/loadScript';
|
import loadScript from '../utils/load-script';
|
||||||
import { formatTime } from './../utils/time';
|
import { formatTime } from '../utils/time';
|
||||||
import { buildUrlParams } from './../utils/urls';
|
import { buildUrlParams } from '../utils/urls';
|
||||||
|
|
||||||
|
const destroy = instance => {
|
||||||
|
// Destroy our adsManager
|
||||||
|
if (instance.manager) {
|
||||||
|
instance.manager.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Destroy our adsManager
|
||||||
|
if (instance.elements.displayContainer) {
|
||||||
|
instance.elements.displayContainer.destroy();
|
||||||
|
}
|
||||||
|
|
||||||
|
instance.elements.container.remove();
|
||||||
|
};
|
||||||
|
|
||||||
class Ads {
|
class Ads {
|
||||||
/**
|
/**
|
||||||
* Ads constructor.
|
* Ads constructor.
|
||||||
* @param {object} player
|
* @param {Object} player
|
||||||
* @return {Ads}
|
* @return {Ads}
|
||||||
*/
|
*/
|
||||||
constructor(player) {
|
constructor(player) {
|
||||||
this.player = player;
|
this.player = player;
|
||||||
this.publisherId = player.config.ads.publisherId;
|
this.config = player.config.ads;
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
this.initialized = false;
|
this.initialized = false;
|
||||||
this.elements = {
|
this.elements = {
|
||||||
@@ -49,8 +63,13 @@ class Ads {
|
|||||||
}
|
}
|
||||||
|
|
||||||
get enabled() {
|
get enabled() {
|
||||||
|
const { config } = this;
|
||||||
|
|
||||||
return (
|
return (
|
||||||
this.player.isHTML5 && this.player.isVideo && this.player.config.ads.enabled && !is.empty(this.publisherId)
|
this.player.isHTML5 &&
|
||||||
|
this.player.isVideo &&
|
||||||
|
config.enabled &&
|
||||||
|
(!is.empty(config.publisherId) || is.url(config.tagUrl))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,20 +77,22 @@ class Ads {
|
|||||||
* Load the IMA SDK
|
* Load the IMA SDK
|
||||||
*/
|
*/
|
||||||
load() {
|
load() {
|
||||||
if (this.enabled) {
|
if (!this.enabled) {
|
||||||
// Check if the Google IMA3 SDK is loaded or load it ourselves
|
return;
|
||||||
if (!is.object(window.google) || !is.object(window.google.ima)) {
|
}
|
||||||
loadScript(this.player.config.urls.googleIMA.sdk)
|
|
||||||
.then(() => {
|
// Check if the Google IMA3 SDK is loaded or load it ourselves
|
||||||
this.ready();
|
if (!is.object(window.google) || !is.object(window.google.ima)) {
|
||||||
})
|
loadScript(this.player.config.urls.googleIMA.sdk)
|
||||||
.catch(() => {
|
.then(() => {
|
||||||
// Script failed to load or is blocked
|
this.ready();
|
||||||
this.trigger('error', new Error('Google IMA SDK failed to load'));
|
})
|
||||||
});
|
.catch(() => {
|
||||||
} else {
|
// Script failed to load or is blocked
|
||||||
this.ready();
|
this.trigger('error', new Error('Google IMA SDK failed to load'));
|
||||||
}
|
});
|
||||||
|
} else {
|
||||||
|
this.ready();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -79,6 +100,11 @@ class Ads {
|
|||||||
* Get the ads instance ready
|
* Get the ads instance ready
|
||||||
*/
|
*/
|
||||||
ready() {
|
ready() {
|
||||||
|
// Double check we're enabled
|
||||||
|
if (!this.enabled) {
|
||||||
|
destroy(this);
|
||||||
|
}
|
||||||
|
|
||||||
// Start ticking our safety timer. If the whole advertisement
|
// Start ticking our safety timer. If the whole advertisement
|
||||||
// thing doesn't resolve within our set time; we bail
|
// thing doesn't resolve within our set time; we bail
|
||||||
this.startSafetyTimer(12000, 'ready()');
|
this.startSafetyTimer(12000, 'ready()');
|
||||||
@@ -95,12 +121,18 @@ class Ads {
|
|||||||
this.setupIMA();
|
this.setupIMA();
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the default tag URL
|
// Build the tag URL
|
||||||
get tagUrl() {
|
get tagUrl() {
|
||||||
|
const { config } = this;
|
||||||
|
|
||||||
|
if (is.url(config.tagUrl)) {
|
||||||
|
return config.tagUrl;
|
||||||
|
}
|
||||||
|
|
||||||
const params = {
|
const params = {
|
||||||
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
|
AV_PUBLISHERID: '58c25bb0073ef448b1087ad6',
|
||||||
AV_CHANNELID: '5a0458dc28a06145e4519d21',
|
AV_CHANNELID: '5a0458dc28a06145e4519d21',
|
||||||
AV_URL: location.hostname,
|
AV_URL: window.location.hostname,
|
||||||
cb: Date.now(),
|
cb: Date.now(),
|
||||||
AV_WIDTH: 640,
|
AV_WIDTH: 640,
|
||||||
AV_HEIGHT: 480,
|
AV_HEIGHT: 480,
|
||||||
@@ -125,6 +157,7 @@ class Ads {
|
|||||||
this.elements.container = createElement('div', {
|
this.elements.container = createElement('div', {
|
||||||
class: this.player.config.classNames.ads,
|
class: this.player.config.classNames.ads,
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.elements.container.appendChild(this.elements.container);
|
this.player.elements.container.appendChild(this.elements.container);
|
||||||
|
|
||||||
// So we can run VPAID2
|
// So we can run VPAID2
|
||||||
@@ -133,9 +166,11 @@ class Ads {
|
|||||||
// Set language
|
// Set language
|
||||||
google.ima.settings.setLocale(this.player.config.ads.language);
|
google.ima.settings.setLocale(this.player.config.ads.language);
|
||||||
|
|
||||||
// We assume the adContainer is the video container of the plyr element
|
// Set playback for iOS10+
|
||||||
// that will house the ads
|
google.ima.settings.setDisableCustomPlaybackForIOS10Plus(this.player.config.playsinline);
|
||||||
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container);
|
|
||||||
|
// We assume the adContainer is the video container of the plyr element that will house the ads
|
||||||
|
this.elements.displayContainer = new google.ima.AdDisplayContainer(this.elements.container, this.player.media);
|
||||||
|
|
||||||
// Request video ads to be pre-loaded
|
// Request video ads to be pre-loaded
|
||||||
this.requestAds();
|
this.requestAds();
|
||||||
@@ -184,7 +219,7 @@ class Ads {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Update the ad countdown
|
* Update the ad countdown
|
||||||
* @param {boolean} start
|
* @param {Boolean} start
|
||||||
*/
|
*/
|
||||||
pollCountdown(start = false) {
|
pollCountdown(start = false) {
|
||||||
if (!start) {
|
if (!start) {
|
||||||
@@ -207,6 +242,11 @@ class Ads {
|
|||||||
* @param {Event} adsManagerLoadedEvent
|
* @param {Event} adsManagerLoadedEvent
|
||||||
*/
|
*/
|
||||||
onAdsManagerLoaded(event) {
|
onAdsManagerLoaded(event) {
|
||||||
|
// Load could occur after a source change (race condition)
|
||||||
|
if (!this.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Get the ads manager
|
// Get the ads manager
|
||||||
const settings = new google.ima.AdsRenderingSettings();
|
const settings = new google.ima.AdsRenderingSettings();
|
||||||
|
|
||||||
@@ -221,6 +261,20 @@ class Ads {
|
|||||||
// Get the cue points for any mid-rolls by filtering out the pre- and post-roll
|
// Get the cue points for any mid-rolls by filtering out the pre- and post-roll
|
||||||
this.cuePoints = this.manager.getCuePoints();
|
this.cuePoints = this.manager.getCuePoints();
|
||||||
|
|
||||||
|
// Add listeners to the required events
|
||||||
|
// Advertisement error events
|
||||||
|
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error));
|
||||||
|
|
||||||
|
// Advertisement regular events
|
||||||
|
Object.keys(google.ima.AdEvent.Type).forEach(type => {
|
||||||
|
this.manager.addEventListener(google.ima.AdEvent.Type[type], e => this.onAdEvent(e));
|
||||||
|
});
|
||||||
|
|
||||||
|
// Resolve our adsManager
|
||||||
|
this.trigger('loaded');
|
||||||
|
}
|
||||||
|
|
||||||
|
addCuePoints() {
|
||||||
// Add advertisement cue's within the time line if available
|
// Add advertisement cue's within the time line if available
|
||||||
if (!is.empty(this.cuePoints)) {
|
if (!is.empty(this.cuePoints)) {
|
||||||
this.cuePoints.forEach(cuePoint => {
|
this.cuePoints.forEach(cuePoint => {
|
||||||
@@ -228,7 +282,7 @@ class Ads {
|
|||||||
const seekElement = this.player.elements.progress;
|
const seekElement = this.player.elements.progress;
|
||||||
|
|
||||||
if (is.element(seekElement)) {
|
if (is.element(seekElement)) {
|
||||||
const cuePercentage = 100 / this.player.duration * cuePoint;
|
const cuePercentage = (100 / this.player.duration) * cuePoint;
|
||||||
const cue = createElement('span', {
|
const cue = createElement('span', {
|
||||||
class: this.player.config.classNames.cues,
|
class: this.player.config.classNames.cues,
|
||||||
});
|
});
|
||||||
@@ -239,25 +293,6 @@ class Ads {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get skippable state
|
|
||||||
// TODO: Skip button
|
|
||||||
// this.player.debug.warn(this.manager.getAdSkippableState());
|
|
||||||
|
|
||||||
// Set volume to match player
|
|
||||||
this.manager.setVolume(this.player.volume);
|
|
||||||
|
|
||||||
// Add listeners to the required events
|
|
||||||
// Advertisement error events
|
|
||||||
this.manager.addEventListener(google.ima.AdErrorEvent.Type.AD_ERROR, error => this.onAdError(error));
|
|
||||||
|
|
||||||
// Advertisement regular events
|
|
||||||
Object.keys(google.ima.AdEvent.Type).forEach(type => {
|
|
||||||
this.manager.addEventListener(google.ima.AdEvent.Type[type], event => this.onAdEvent(event));
|
|
||||||
});
|
|
||||||
|
|
||||||
// Resolve our adsManager
|
|
||||||
this.trigger('loaded');
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -268,26 +303,25 @@ class Ads {
|
|||||||
*/
|
*/
|
||||||
onAdEvent(event) {
|
onAdEvent(event) {
|
||||||
const { container } = this.player.elements;
|
const { container } = this.player.elements;
|
||||||
|
|
||||||
// Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
|
// Retrieve the ad from the event. Some events (e.g. ALL_ADS_COMPLETED)
|
||||||
// don't have ad object associated
|
// don't have ad object associated
|
||||||
const ad = event.getAd();
|
const ad = event.getAd();
|
||||||
|
const adData = event.getAdData();
|
||||||
|
|
||||||
// Proxy event
|
// Proxy event
|
||||||
const dispatchEvent = type => {
|
const dispatchEvent = type => {
|
||||||
const event = `ads${type.replace(/_/g, '').toLowerCase()}`;
|
triggerEvent.call(this.player, this.player.media, `ads${type.replace(/_/g, '').toLowerCase()}`);
|
||||||
triggerEvent.call(this.player, this.player.media, event);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Bubble the event
|
||||||
|
dispatchEvent(event.type);
|
||||||
|
|
||||||
switch (event.type) {
|
switch (event.type) {
|
||||||
case google.ima.AdEvent.Type.LOADED:
|
case google.ima.AdEvent.Type.LOADED:
|
||||||
// This is the first event sent for an ad - it is possible to determine whether the
|
// This is the first event sent for an ad - it is possible to determine whether the
|
||||||
// ad is a video ad or an overlay
|
// ad is a video ad or an overlay
|
||||||
this.trigger('loaded');
|
this.trigger('loaded');
|
||||||
|
|
||||||
// Bubble event
|
|
||||||
dispatchEvent(event.type);
|
|
||||||
|
|
||||||
// Start countdown
|
// Start countdown
|
||||||
this.pollCountdown(true);
|
this.pollCountdown(true);
|
||||||
|
|
||||||
@@ -299,15 +333,19 @@ class Ads {
|
|||||||
|
|
||||||
// console.info('Ad type: ' + event.getAd().getAdPodInfo().getPodIndex());
|
// console.info('Ad type: ' + event.getAd().getAdPodInfo().getPodIndex());
|
||||||
// console.info('Ad time: ' + event.getAd().getAdPodInfo().getTimeOffset());
|
// console.info('Ad time: ' + event.getAd().getAdPodInfo().getTimeOffset());
|
||||||
|
|
||||||
|
break;
|
||||||
|
|
||||||
|
case google.ima.AdEvent.Type.STARTED:
|
||||||
|
// Set volume to match player
|
||||||
|
this.manager.setVolume(this.player.volume);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
|
case google.ima.AdEvent.Type.ALL_ADS_COMPLETED:
|
||||||
// All ads for the current videos are done. We can now request new advertisements
|
// All ads for the current videos are done. We can now request new advertisements
|
||||||
// in case the video is re-played
|
// in case the video is re-played
|
||||||
|
|
||||||
// Fire event
|
|
||||||
dispatchEvent(event.type);
|
|
||||||
|
|
||||||
// TODO: Example for what happens when a next video in a playlist would be loaded.
|
// TODO: Example for what happens when a next video in a playlist would be loaded.
|
||||||
// So here we load a new video when all ads are done.
|
// So here we load a new video when all ads are done.
|
||||||
// Then we load new ads within a new adsManager. When the video
|
// Then we load new ads within a new adsManager. When the video
|
||||||
@@ -332,6 +370,7 @@ class Ads {
|
|||||||
// playing when the IMA SDK is ready or has failed
|
// playing when the IMA SDK is ready or has failed
|
||||||
|
|
||||||
this.loadAds();
|
this.loadAds();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED:
|
case google.ima.AdEvent.Type.CONTENT_PAUSE_REQUESTED:
|
||||||
@@ -339,8 +378,6 @@ class Ads {
|
|||||||
// for example display a pause button and remaining time. Fired when content should
|
// for example display a pause button and remaining time. Fired when content should
|
||||||
// be paused. This usually happens right before an ad is about to cover the content
|
// be paused. This usually happens right before an ad is about to cover the content
|
||||||
|
|
||||||
dispatchEvent(event.type);
|
|
||||||
|
|
||||||
this.pauseContent();
|
this.pauseContent();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
@@ -351,20 +388,17 @@ class Ads {
|
|||||||
// Fired when content should be resumed. This usually happens when an ad finishes
|
// Fired when content should be resumed. This usually happens when an ad finishes
|
||||||
// or collapses
|
// or collapses
|
||||||
|
|
||||||
dispatchEvent(event.type);
|
|
||||||
|
|
||||||
this.pollCountdown();
|
this.pollCountdown();
|
||||||
|
|
||||||
this.resumeContent();
|
this.resumeContent();
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case google.ima.AdEvent.Type.STARTED:
|
case google.ima.AdEvent.Type.LOG:
|
||||||
case google.ima.AdEvent.Type.MIDPOINT:
|
if (adData.adError) {
|
||||||
case google.ima.AdEvent.Type.COMPLETE:
|
this.player.debug.warn(`Non-fatal ad error: ${adData.adError.getMessage()}`);
|
||||||
case google.ima.AdEvent.Type.IMPRESSION:
|
}
|
||||||
case google.ima.AdEvent.Type.CLICK:
|
|
||||||
dispatchEvent(event.type);
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@@ -390,14 +424,16 @@ class Ads {
|
|||||||
const { container } = this.player.elements;
|
const { container } = this.player.elements;
|
||||||
let time;
|
let time;
|
||||||
|
|
||||||
// Add listeners to the required events
|
this.player.on('canplay', () => {
|
||||||
|
this.addCuePoints();
|
||||||
|
});
|
||||||
|
|
||||||
this.player.on('ended', () => {
|
this.player.on('ended', () => {
|
||||||
this.loader.contentComplete();
|
this.loader.contentComplete();
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.on('seeking', () => {
|
this.player.on('timeupdate', () => {
|
||||||
time = this.player.currentTime;
|
time = this.player.currentTime;
|
||||||
return time;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
this.player.on('seeked', () => {
|
this.player.on('seeked', () => {
|
||||||
@@ -437,6 +473,9 @@ class Ads {
|
|||||||
// Play the requested advertisement whenever the adsManager is ready
|
// Play the requested advertisement whenever the adsManager is ready
|
||||||
this.managerPromise
|
this.managerPromise
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
// Set volume to match player
|
||||||
|
this.manager.setVolume(this.player.volume);
|
||||||
|
|
||||||
// Initialize the container. Must be done via a user action on mobile devices
|
// Initialize the container. Must be done via a user action on mobile devices
|
||||||
this.elements.displayContainer.initialize();
|
this.elements.displayContainer.initialize();
|
||||||
|
|
||||||
@@ -470,10 +509,8 @@ class Ads {
|
|||||||
// Ad is stopped
|
// Ad is stopped
|
||||||
this.playing = false;
|
this.playing = false;
|
||||||
|
|
||||||
// Play our video
|
// Play video
|
||||||
if (this.player.currentTime < this.player.duration) {
|
this.player.media.play();
|
||||||
this.player.play();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -483,11 +520,11 @@ class Ads {
|
|||||||
// Show the advertisement container
|
// Show the advertisement container
|
||||||
this.elements.container.style.zIndex = 3;
|
this.elements.container.style.zIndex = 3;
|
||||||
|
|
||||||
// Ad is playing.
|
// Ad is playing
|
||||||
this.playing = true;
|
this.playing = true;
|
||||||
|
|
||||||
// Pause our video.
|
// Pause our video.
|
||||||
this.player.pause();
|
this.player.media.pause();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -535,7 +572,7 @@ class Ads {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles callbacks after an ad event was invoked
|
* Handles callbacks after an ad event was invoked
|
||||||
* @param {string} event - Event type
|
* @param {String} event - Event type
|
||||||
*/
|
*/
|
||||||
trigger(event, ...args) {
|
trigger(event, ...args) {
|
||||||
const handlers = this.events[event];
|
const handlers = this.events[event];
|
||||||
@@ -551,8 +588,8 @@ class Ads {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners
|
* Add event listeners
|
||||||
* @param {string} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
* @return {Ads}
|
* @return {Ads}
|
||||||
*/
|
*/
|
||||||
on(event, callback) {
|
on(event, callback) {
|
||||||
@@ -570,8 +607,8 @@ class Ads {
|
|||||||
* The advertisement has 12 seconds to get its things together. We stop this timer when the
|
* The advertisement has 12 seconds to get its things together. We stop this timer when the
|
||||||
* advertisement is playing, or when a user action is required to start, then we clear the
|
* advertisement is playing, or when a user action is required to start, then we clear the
|
||||||
* timer on ad ready
|
* timer on ad ready
|
||||||
* @param {number} time
|
* @param {Number} time
|
||||||
* @param {string} from
|
* @param {String} from
|
||||||
*/
|
*/
|
||||||
startSafetyTimer(time, from) {
|
startSafetyTimer(time, from) {
|
||||||
this.player.debug.log(`Safety timer invoked from: ${from}`);
|
this.player.debug.log(`Safety timer invoked from: ${from}`);
|
||||||
@@ -584,7 +621,7 @@ class Ads {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Clear our safety timer(s)
|
* Clear our safety timer(s)
|
||||||
* @param {string} from
|
* @param {String} from
|
||||||
*/
|
*/
|
||||||
clearSafetyTimer(from) {
|
clearSafetyTimer(from) {
|
||||||
if (!is.nullOrUndefined(this.safetyTimer)) {
|
if (!is.nullOrUndefined(this.safetyTimer)) {
|
||||||
|
|||||||
@@ -0,0 +1,652 @@
|
|||||||
|
import { createElement } from '../utils/elements';
|
||||||
|
import { once } from '../utils/events';
|
||||||
|
import fetch from '../utils/fetch';
|
||||||
|
import is from '../utils/is';
|
||||||
|
import { formatTime } from '../utils/time';
|
||||||
|
|
||||||
|
// Arg: vttDataString example: "WEBVTT\n\n1\n00:00:05.000 --> 00:00:10.000\n1080p-00001.jpg"
|
||||||
|
const parseVtt = vttDataString => {
|
||||||
|
const processedList = [];
|
||||||
|
const frames = vttDataString.split(/\r\n\r\n|\n\n|\r\r/);
|
||||||
|
|
||||||
|
frames.forEach(frame => {
|
||||||
|
const result = {};
|
||||||
|
const lines = frame.split(/\r\n|\n|\r/);
|
||||||
|
|
||||||
|
lines.forEach(line => {
|
||||||
|
if (!is.number(result.startTime)) {
|
||||||
|
// The line with start and end times on it is the first line of interest
|
||||||
|
const matchTimes = line.match(
|
||||||
|
/([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})( ?--> ?)([0-9]{2})?:?([0-9]{2}):([0-9]{2}).([0-9]{2,3})/,
|
||||||
|
); // Note that this currently ignores caption formatting directives that are optionally on the end of this line - fine for non-captions VTT
|
||||||
|
|
||||||
|
if (matchTimes) {
|
||||||
|
result.startTime =
|
||||||
|
Number(matchTimes[1] || 0) * 60 * 60 +
|
||||||
|
Number(matchTimes[2]) * 60 +
|
||||||
|
Number(matchTimes[3]) +
|
||||||
|
Number(`0.${matchTimes[4]}`);
|
||||||
|
result.endTime =
|
||||||
|
Number(matchTimes[6] || 0) * 60 * 60 +
|
||||||
|
Number(matchTimes[7]) * 60 +
|
||||||
|
Number(matchTimes[8]) +
|
||||||
|
Number(`0.${matchTimes[9]}`);
|
||||||
|
}
|
||||||
|
} else if (!is.empty(line.trim()) && is.empty(result.text)) {
|
||||||
|
// If we already have the startTime, then we're definitely up to the text line(s)
|
||||||
|
const lineSplit = line.trim().split('#xywh=');
|
||||||
|
[result.text] = lineSplit;
|
||||||
|
|
||||||
|
// If there's content in lineSplit[1], then we have sprites. If not, then it's just one frame per image
|
||||||
|
if (lineSplit[1]) {
|
||||||
|
[result.x, result.y, result.w, result.h] = lineSplit[1].split(',');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (result.text) {
|
||||||
|
processedList.push(result);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
return processedList;
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Preview thumbnails for seek hover and scrubbing
|
||||||
|
* Seeking: Hover over the seek bar (desktop only): shows a small preview container above the seek bar
|
||||||
|
* Scrubbing: Click and drag the seek bar (desktop and mobile): shows the preview image over the entire video, as if the video is scrubbing at very high speed
|
||||||
|
*
|
||||||
|
* Notes:
|
||||||
|
* - Thumbs are set via JS settings on Plyr init, not HTML5 'track' property. Using the track property would be a bit gross, because it doesn't support custom 'kinds'. kind=metadata might be used for something else, and we want to allow multiple thumbnails tracks. Tracks must have a unique combination of 'kind' and 'label'. We would have to do something like kind=metadata,label=thumbnails1 / kind=metadata,label=thumbnails2. Square peg, round hole
|
||||||
|
* - VTT info: the image URL is relative to the VTT, not the current document. But if the url starts with a slash, it will naturally be relative to the current domain. https://support.jwplayer.com/articles/how-to-add-preview-thumbnails
|
||||||
|
* - This implementation uses multiple separate img elements. Other implementations use background-image on one element. This would be nice and simple, but Firefox and Safari have flickering issues with replacing backgrounds of larger images. It seems that YouTube perhaps only avoids this because they don't have the option for high-res previews (even the fullscreen ones, when mousedown/seeking). Images appear over the top of each other, and previous ones are discarded once the new ones have been rendered
|
||||||
|
*/
|
||||||
|
|
||||||
|
class PreviewThumbnails {
|
||||||
|
/**
|
||||||
|
* PreviewThumbnails constructor.
|
||||||
|
* @param {Plyr} player
|
||||||
|
* @return {PreviewThumbnails}
|
||||||
|
*/
|
||||||
|
constructor(player) {
|
||||||
|
this.player = player;
|
||||||
|
this.thumbnails = [];
|
||||||
|
this.loaded = false;
|
||||||
|
this.lastMouseMoveTime = Date.now();
|
||||||
|
this.mouseDown = false;
|
||||||
|
this.loadedImages = [];
|
||||||
|
|
||||||
|
this.elements = {
|
||||||
|
thumb: {},
|
||||||
|
scrubbing: {},
|
||||||
|
};
|
||||||
|
|
||||||
|
this.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
get enabled() {
|
||||||
|
return this.player.isHTML5 && this.player.isVideo && this.player.config.previewThumbnails.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
load() {
|
||||||
|
// Togglethe regular seek tooltip
|
||||||
|
if (this.player.elements.display.seekTooltip) {
|
||||||
|
this.player.elements.display.seekTooltip.hidden = this.enabled;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!this.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.getThumbnails().then(() => {
|
||||||
|
if (!this.enabled) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Render DOM elements
|
||||||
|
this.render();
|
||||||
|
|
||||||
|
// Check to see if thumb container size was specified manually in CSS
|
||||||
|
this.determineContainerAutoSizing();
|
||||||
|
|
||||||
|
this.loaded = true;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download VTT files and parse them
|
||||||
|
getThumbnails() {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const { src } = this.player.config.previewThumbnails;
|
||||||
|
|
||||||
|
if (is.empty(src)) {
|
||||||
|
throw new Error('Missing previewThumbnails.src config attribute');
|
||||||
|
}
|
||||||
|
|
||||||
|
// If string, convert into single-element list
|
||||||
|
const urls = is.string(src) ? [src] : src;
|
||||||
|
// Loop through each src URL. Download and process the VTT file, storing the resulting data in this.thumbnails
|
||||||
|
const promises = urls.map(u => this.getThumbnail(u));
|
||||||
|
|
||||||
|
Promise.all(promises).then(() => {
|
||||||
|
// Sort smallest to biggest (e.g., [120p, 480p, 1080p])
|
||||||
|
this.thumbnails.sort((x, y) => x.height - y.height);
|
||||||
|
|
||||||
|
this.player.debug.log('Preview thumbnails', this.thumbnails);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Process individual VTT file
|
||||||
|
getThumbnail(url) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
fetch(url).then(response => {
|
||||||
|
const thumbnail = {
|
||||||
|
frames: parseVtt(response),
|
||||||
|
height: null,
|
||||||
|
urlPrefix: '',
|
||||||
|
};
|
||||||
|
|
||||||
|
// If the URLs don't start with '/', then we need to set their relative path to be the location of the VTT file
|
||||||
|
// If the URLs do start with '/', then they obviously don't need a prefix, so it will remain blank
|
||||||
|
// If the thumbnail URLs start with with none of '/', 'http://' or 'https://', then we need to set their relative path to be the location of the VTT file
|
||||||
|
if (
|
||||||
|
!thumbnail.frames[0].text.startsWith('/') &&
|
||||||
|
!thumbnail.frames[0].text.startsWith('http://') &&
|
||||||
|
!thumbnail.frames[0].text.startsWith('https://')
|
||||||
|
) {
|
||||||
|
thumbnail.urlPrefix = url.substring(0, url.lastIndexOf('/') + 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download the first frame, so that we can determine/set the height of this thumbnailsDef
|
||||||
|
const tempImage = new Image();
|
||||||
|
|
||||||
|
tempImage.onload = () => {
|
||||||
|
thumbnail.height = tempImage.naturalHeight;
|
||||||
|
thumbnail.width = tempImage.naturalWidth;
|
||||||
|
|
||||||
|
this.thumbnails.push(thumbnail);
|
||||||
|
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
|
||||||
|
tempImage.src = thumbnail.urlPrefix + thumbnail.frames[0].text;
|
||||||
|
});
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
startMove(event) {
|
||||||
|
if (!this.loaded) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is.event(event) || !['touchmove', 'mousemove'].includes(event.type)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Wait until media has a duration
|
||||||
|
if (!this.player.media.duration) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (event.type === 'touchmove') {
|
||||||
|
// Calculate seek hover position as approx video seconds
|
||||||
|
this.seekTime = this.player.media.duration * (this.player.elements.inputs.seek.value / 100);
|
||||||
|
} else {
|
||||||
|
// Calculate seek hover position as approx video seconds
|
||||||
|
const clientRect = this.player.elements.progress.getBoundingClientRect();
|
||||||
|
const percentage = (100 / clientRect.width) * (event.pageX - clientRect.left);
|
||||||
|
this.seekTime = this.player.media.duration * (percentage / 100);
|
||||||
|
|
||||||
|
if (this.seekTime < 0) {
|
||||||
|
// The mousemove fires for 10+px out to the left
|
||||||
|
this.seekTime = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.seekTime > this.player.media.duration - 1) {
|
||||||
|
// Took 1 second off the duration for safety, because different players can disagree on the real duration of a video
|
||||||
|
this.seekTime = this.player.media.duration - 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.mousePosX = event.pageX;
|
||||||
|
|
||||||
|
// Set time text inside image container
|
||||||
|
this.elements.thumb.time.innerText = formatTime(this.seekTime);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Download and show image
|
||||||
|
this.showImageAtCurrentTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
endMove() {
|
||||||
|
this.toggleThumbContainer(false, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
startScrubbing(event) {
|
||||||
|
// Only act on left mouse button (0), or touch device (event.button is false)
|
||||||
|
if (event.button === false || event.button === 0) {
|
||||||
|
this.mouseDown = true;
|
||||||
|
|
||||||
|
// Wait until media has a duration
|
||||||
|
if (this.player.media.duration) {
|
||||||
|
this.toggleScrubbingContainer(true);
|
||||||
|
this.toggleThumbContainer(false, true);
|
||||||
|
|
||||||
|
// Download and show image
|
||||||
|
this.showImageAtCurrentTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
endScrubbing() {
|
||||||
|
this.mouseDown = false;
|
||||||
|
|
||||||
|
// Hide scrubbing preview. But wait until the video has successfully seeked before hiding the scrubbing preview
|
||||||
|
if (Math.ceil(this.lastTime) === Math.ceil(this.player.media.currentTime)) {
|
||||||
|
// The video was already seeked/loaded at the chosen time - hide immediately
|
||||||
|
this.toggleScrubbingContainer(false);
|
||||||
|
} else {
|
||||||
|
// The video hasn't seeked yet. Wait for that
|
||||||
|
once.call(this.player, this.player.media, 'timeupdate', () => {
|
||||||
|
// Re-check mousedown - we might have already started scrubbing again
|
||||||
|
if (!this.mouseDown) {
|
||||||
|
this.toggleScrubbingContainer(false);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setup hooks for Plyr and window events
|
||||||
|
*/
|
||||||
|
listeners() {
|
||||||
|
// Hide thumbnail preview - on mouse click, mouse leave (in listeners.js for now), and video play/seek. All four are required, e.g., for buffering
|
||||||
|
this.player.on('play', () => {
|
||||||
|
this.toggleThumbContainer(false, true);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.player.on('seeked', () => {
|
||||||
|
this.toggleThumbContainer(false);
|
||||||
|
});
|
||||||
|
|
||||||
|
this.player.on('timeupdate', () => {
|
||||||
|
this.lastTime = this.player.media.currentTime;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create HTML elements for image containers
|
||||||
|
*/
|
||||||
|
render() {
|
||||||
|
// Create HTML element: plyr__preview-thumbnail-container
|
||||||
|
this.elements.thumb.container = createElement('div', {
|
||||||
|
class: this.player.config.classNames.previewThumbnails.thumbContainer,
|
||||||
|
});
|
||||||
|
|
||||||
|
// Wrapper for the image for styling
|
||||||
|
this.elements.thumb.imageContainer = createElement('div', {
|
||||||
|
class: this.player.config.classNames.previewThumbnails.imageContainer,
|
||||||
|
});
|
||||||
|
this.elements.thumb.container.appendChild(this.elements.thumb.imageContainer);
|
||||||
|
|
||||||
|
// Create HTML element, parent+span: time text (e.g., 01:32:00)
|
||||||
|
const timeContainer = createElement('div', {
|
||||||
|
class: this.player.config.classNames.previewThumbnails.timeContainer,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.elements.thumb.time = createElement('span', {}, '00:00');
|
||||||
|
timeContainer.appendChild(this.elements.thumb.time);
|
||||||
|
|
||||||
|
this.elements.thumb.container.appendChild(timeContainer);
|
||||||
|
|
||||||
|
// Inject the whole thumb
|
||||||
|
if (is.element(this.player.elements.progress)) {
|
||||||
|
this.player.elements.progress.appendChild(this.elements.thumb.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Create HTML element: plyr__preview-scrubbing-container
|
||||||
|
this.elements.scrubbing.container = createElement('div', {
|
||||||
|
class: this.player.config.classNames.previewThumbnails.scrubbingContainer,
|
||||||
|
});
|
||||||
|
|
||||||
|
this.player.elements.wrapper.appendChild(this.elements.scrubbing.container);
|
||||||
|
}
|
||||||
|
|
||||||
|
showImageAtCurrentTime() {
|
||||||
|
if (this.mouseDown) {
|
||||||
|
this.setScrubbingContainerSize();
|
||||||
|
} else {
|
||||||
|
this.setThumbContainerSizeAndPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find the desired thumbnail index
|
||||||
|
// TODO: Handle a video longer than the thumbs where thumbNum is null
|
||||||
|
const thumbNum = this.thumbnails[0].frames.findIndex(
|
||||||
|
frame => this.seekTime >= frame.startTime && this.seekTime <= frame.endTime,
|
||||||
|
);
|
||||||
|
const hasThumb = thumbNum >= 0;
|
||||||
|
let qualityIndex = 0;
|
||||||
|
|
||||||
|
// Show the thumb container if we're not scrubbing
|
||||||
|
if (!this.mouseDown) {
|
||||||
|
this.toggleThumbContainer(hasThumb);
|
||||||
|
}
|
||||||
|
|
||||||
|
// No matching thumb found
|
||||||
|
if (!hasThumb) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check to see if we've already downloaded higher quality versions of this image
|
||||||
|
this.thumbnails.forEach((thumbnail, index) => {
|
||||||
|
if (this.loadedImages.includes(thumbnail.frames[thumbNum].text)) {
|
||||||
|
qualityIndex = index;
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// Only proceed if either thumbnum or thumbfilename has changed
|
||||||
|
if (thumbNum !== this.showingThumb) {
|
||||||
|
this.showingThumb = thumbNum;
|
||||||
|
this.loadImage(qualityIndex);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Show the image that's currently specified in this.showingThumb
|
||||||
|
loadImage(qualityIndex = 0) {
|
||||||
|
const thumbNum = this.showingThumb;
|
||||||
|
const thumbnail = this.thumbnails[qualityIndex];
|
||||||
|
const { urlPrefix } = thumbnail;
|
||||||
|
const frame = thumbnail.frames[thumbNum];
|
||||||
|
const thumbFilename = thumbnail.frames[thumbNum].text;
|
||||||
|
const thumbUrl = urlPrefix + thumbFilename;
|
||||||
|
|
||||||
|
if (!this.currentImageElement || this.currentImageElement.dataset.filename !== thumbFilename) {
|
||||||
|
// If we're already loading a previous image, remove its onload handler - we don't want it to load after this one
|
||||||
|
// Only do this if not using sprites. Without sprites we really want to show as many images as possible, as a best-effort
|
||||||
|
if (this.loadingImage && this.usingSprites) {
|
||||||
|
this.loadingImage.onload = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// We're building and adding a new image. In other implementations of similar functionality (YouTube), background image
|
||||||
|
// is instead used. But this causes issues with larger images in Firefox and Safari - switching between background
|
||||||
|
// images causes a flicker. Putting a new image over the top does not
|
||||||
|
const previewImage = new Image();
|
||||||
|
previewImage.src = thumbUrl;
|
||||||
|
previewImage.dataset.index = thumbNum;
|
||||||
|
previewImage.dataset.filename = thumbFilename;
|
||||||
|
this.showingThumbFilename = thumbFilename;
|
||||||
|
|
||||||
|
this.player.debug.log(`Loading image: ${thumbUrl}`);
|
||||||
|
|
||||||
|
// For some reason, passing the named function directly causes it to execute immediately. So I've wrapped it in an anonymous function...
|
||||||
|
previewImage.onload = () =>
|
||||||
|
this.showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, true);
|
||||||
|
this.loadingImage = previewImage;
|
||||||
|
this.removeOldImages(previewImage);
|
||||||
|
} else {
|
||||||
|
// Update the existing image
|
||||||
|
this.showImage(this.currentImageElement, frame, qualityIndex, thumbNum, thumbFilename, false);
|
||||||
|
this.currentImageElement.dataset.index = thumbNum;
|
||||||
|
this.removeOldImages(this.currentImageElement);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
showImage(previewImage, frame, qualityIndex, thumbNum, thumbFilename, newImage = true) {
|
||||||
|
this.player.debug.log(
|
||||||
|
`Showing thumb: ${thumbFilename}. num: ${thumbNum}. qual: ${qualityIndex}. newimg: ${newImage}`,
|
||||||
|
);
|
||||||
|
this.setImageSizeAndOffset(previewImage, frame);
|
||||||
|
|
||||||
|
if (newImage) {
|
||||||
|
this.currentImageContainer.appendChild(previewImage);
|
||||||
|
this.currentImageElement = previewImage;
|
||||||
|
|
||||||
|
if (!this.loadedImages.includes(thumbFilename)) {
|
||||||
|
this.loadedImages.push(thumbFilename);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preload images before and after the current one
|
||||||
|
// Show higher quality of the same frame
|
||||||
|
// Each step here has a short time delay, and only continues if still hovering/seeking the same spot. This is to protect slow connections from overloading
|
||||||
|
this.preloadNearby(thumbNum, true)
|
||||||
|
.then(this.preloadNearby(thumbNum, false))
|
||||||
|
.then(this.getHigherQuality(qualityIndex, previewImage, frame, thumbFilename));
|
||||||
|
}
|
||||||
|
|
||||||
|
// Remove all preview images that aren't the designated current image
|
||||||
|
removeOldImages(currentImage) {
|
||||||
|
// Get a list of all images, convert it from a DOM list to an array
|
||||||
|
Array.from(this.currentImageContainer.children).forEach(image => {
|
||||||
|
if (image.tagName.toLowerCase() !== 'img') {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const removeDelay = this.usingSprites ? 500 : 1000;
|
||||||
|
|
||||||
|
if (image.dataset.index !== currentImage.dataset.index && !image.dataset.deleting) {
|
||||||
|
// Wait 200ms, as the new image can take some time to show on certain browsers (even though it was downloaded before showing). This will prevent flicker, and show some generosity towards slower clients
|
||||||
|
// First set attribute 'deleting' to prevent multi-handling of this on repeat firing of this function
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
image.dataset.deleting = true;
|
||||||
|
|
||||||
|
// This has to be set before the timeout - to prevent issues switching between hover and scrub
|
||||||
|
const { currentImageContainer } = this;
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
|
currentImageContainer.removeChild(image);
|
||||||
|
this.player.debug.log(`Removing thumb: ${image.dataset.filename}`);
|
||||||
|
}, removeDelay);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Preload images before and after the current one. Only if the user is still hovering/seeking the same frame
|
||||||
|
// This will only preload the lowest quality
|
||||||
|
preloadNearby(thumbNum, forward = true) {
|
||||||
|
return new Promise(resolve => {
|
||||||
|
setTimeout(() => {
|
||||||
|
const oldThumbFilename = this.thumbnails[0].frames[thumbNum].text;
|
||||||
|
|
||||||
|
if (this.showingThumbFilename === oldThumbFilename) {
|
||||||
|
// Find the nearest thumbs with different filenames. Sometimes it'll be the next index, but in the case of sprites, it might be 100+ away
|
||||||
|
let thumbnailsClone;
|
||||||
|
if (forward) {
|
||||||
|
thumbnailsClone = this.thumbnails[0].frames.slice(thumbNum);
|
||||||
|
} else {
|
||||||
|
thumbnailsClone = this.thumbnails[0].frames.slice(0, thumbNum).reverse();
|
||||||
|
}
|
||||||
|
|
||||||
|
let foundOne = false;
|
||||||
|
|
||||||
|
thumbnailsClone.forEach(frame => {
|
||||||
|
const newThumbFilename = frame.text;
|
||||||
|
|
||||||
|
if (newThumbFilename !== oldThumbFilename) {
|
||||||
|
// Found one with a different filename. Make sure it hasn't already been loaded on this page visit
|
||||||
|
if (!this.loadedImages.includes(newThumbFilename)) {
|
||||||
|
foundOne = true;
|
||||||
|
this.player.debug.log(`Preloading thumb filename: ${newThumbFilename}`);
|
||||||
|
|
||||||
|
const { urlPrefix } = this.thumbnails[0];
|
||||||
|
const thumbURL = urlPrefix + newThumbFilename;
|
||||||
|
const previewImage = new Image();
|
||||||
|
previewImage.src = thumbURL;
|
||||||
|
previewImage.onload = () => {
|
||||||
|
this.player.debug.log(`Preloaded thumb filename: ${newThumbFilename}`);
|
||||||
|
if (!this.loadedImages.includes(newThumbFilename))
|
||||||
|
this.loadedImages.push(newThumbFilename);
|
||||||
|
|
||||||
|
// We don't resolve until the thumb is loaded
|
||||||
|
resolve();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
// If there are none to preload then we want to resolve immediately
|
||||||
|
if (!foundOne) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// If user has been hovering current image for half a second, look for a higher quality one
|
||||||
|
getHigherQuality(currentQualityIndex, previewImage, frame, thumbFilename) {
|
||||||
|
if (currentQualityIndex < this.thumbnails.length - 1) {
|
||||||
|
// Only use the higher quality version if it's going to look any better - if the current thumb is of a lower pixel density than the thumbnail container
|
||||||
|
let previewImageHeight = previewImage.naturalHeight;
|
||||||
|
|
||||||
|
if (this.usingSprites) {
|
||||||
|
previewImageHeight = frame.h;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previewImageHeight < this.thumbContainerHeight) {
|
||||||
|
// Recurse back to the loadImage function - show a higher quality one, but only if the viewer is on this frame for a while
|
||||||
|
setTimeout(() => {
|
||||||
|
// Make sure the mouse hasn't already moved on and started hovering at another image
|
||||||
|
if (this.showingThumbFilename === thumbFilename) {
|
||||||
|
this.player.debug.log(`Showing higher quality thumb for: ${thumbFilename}`);
|
||||||
|
this.loadImage(currentQualityIndex + 1);
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get currentImageContainer() {
|
||||||
|
if (this.mouseDown) {
|
||||||
|
return this.elements.scrubbing.container;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.elements.thumb.imageContainer;
|
||||||
|
}
|
||||||
|
|
||||||
|
get usingSprites() {
|
||||||
|
return Object.keys(this.thumbnails[0].frames[0]).includes('w');
|
||||||
|
}
|
||||||
|
|
||||||
|
get thumbAspectRatio() {
|
||||||
|
if (this.usingSprites) {
|
||||||
|
return this.thumbnails[0].frames[0].w / this.thumbnails[0].frames[0].h;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.thumbnails[0].width / this.thumbnails[0].height;
|
||||||
|
}
|
||||||
|
|
||||||
|
get thumbContainerHeight() {
|
||||||
|
if (this.mouseDown) {
|
||||||
|
// Can't use media.clientHeight - HTML5 video goes big and does black bars above and below
|
||||||
|
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Math.floor(this.player.media.clientWidth / this.thumbAspectRatio / 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
get currentImageElement() {
|
||||||
|
if (this.mouseDown) {
|
||||||
|
return this.currentScrubbingImageElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
return this.currentThumbnailImageElement;
|
||||||
|
}
|
||||||
|
|
||||||
|
set currentImageElement(element) {
|
||||||
|
if (this.mouseDown) {
|
||||||
|
this.currentScrubbingImageElement = element;
|
||||||
|
} else {
|
||||||
|
this.currentThumbnailImageElement = element;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleThumbContainer(toggle = false, clearShowing = false) {
|
||||||
|
const className = this.player.config.classNames.previewThumbnails.thumbContainerShown;
|
||||||
|
this.elements.thumb.container.classList.toggle(className, toggle);
|
||||||
|
|
||||||
|
if (!toggle && clearShowing) {
|
||||||
|
this.showingThumb = null;
|
||||||
|
this.showingThumbFilename = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
toggleScrubbingContainer(toggle = false) {
|
||||||
|
const className = this.player.config.classNames.previewThumbnails.scrubbingContainerShown;
|
||||||
|
this.elements.scrubbing.container.classList.toggle(className, toggle);
|
||||||
|
|
||||||
|
if (!toggle) {
|
||||||
|
this.showingThumb = null;
|
||||||
|
this.showingThumbFilename = null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
determineContainerAutoSizing() {
|
||||||
|
if (this.elements.thumb.imageContainer.clientHeight > 20) {
|
||||||
|
// This will prevent auto sizing in this.setThumbContainerSizeAndPos()
|
||||||
|
this.sizeSpecifiedInCSS = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set the size to be about a quarter of the size of video. Unless option dynamicSize === false, in which case it needs to be set in CSS
|
||||||
|
setThumbContainerSizeAndPos() {
|
||||||
|
if (!this.sizeSpecifiedInCSS) {
|
||||||
|
const thumbWidth = Math.floor(this.thumbContainerHeight * this.thumbAspectRatio);
|
||||||
|
this.elements.thumb.imageContainer.style.height = `${this.thumbContainerHeight}px`;
|
||||||
|
this.elements.thumb.imageContainer.style.width = `${thumbWidth}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.setThumbContainerPos();
|
||||||
|
}
|
||||||
|
|
||||||
|
setThumbContainerPos() {
|
||||||
|
const seekbarRect = this.player.elements.progress.getBoundingClientRect();
|
||||||
|
const plyrRect = this.player.elements.container.getBoundingClientRect();
|
||||||
|
const { container } = this.elements.thumb;
|
||||||
|
// Find the lowest and highest desired left-position, so we don't slide out the side of the video container
|
||||||
|
const minVal = plyrRect.left - seekbarRect.left + 10;
|
||||||
|
const maxVal = plyrRect.right - seekbarRect.left - container.clientWidth - 10;
|
||||||
|
// Set preview container position to: mousepos, minus seekbar.left, minus half of previewContainer.clientWidth
|
||||||
|
let previewPos = this.mousePosX - seekbarRect.left - container.clientWidth / 2;
|
||||||
|
|
||||||
|
if (previewPos < minVal) {
|
||||||
|
previewPos = minVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (previewPos > maxVal) {
|
||||||
|
previewPos = maxVal;
|
||||||
|
}
|
||||||
|
|
||||||
|
container.style.left = `${previewPos}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Can't use 100% width, in case the video is a different aspect ratio to the video container
|
||||||
|
setScrubbingContainerSize() {
|
||||||
|
this.elements.scrubbing.container.style.width = `${this.player.media.clientWidth}px`;
|
||||||
|
// Can't use media.clientHeight - html5 video goes big and does black bars above and below
|
||||||
|
this.elements.scrubbing.container.style.height = `${this.player.media.clientWidth / this.thumbAspectRatio}px`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprites need to be offset to the correct location
|
||||||
|
setImageSizeAndOffset(previewImage, frame) {
|
||||||
|
if (!this.usingSprites) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find difference between height and preview container height
|
||||||
|
const multiplier = this.thumbContainerHeight / frame.h;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
previewImage.style.height = `${Math.floor(previewImage.naturalHeight * multiplier)}px`;
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
previewImage.style.width = `${Math.floor(previewImage.naturalWidth * multiplier)}px`;
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
previewImage.style.left = `-${frame.x * multiplier}px`;
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
previewImage.style.top = `-${frame.y * multiplier}px`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export default PreviewThumbnails;
|
||||||
+33
-52
@@ -2,16 +2,18 @@
|
|||||||
// Vimeo plugin
|
// Vimeo plugin
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import captions from './../captions';
|
import captions from '../captions';
|
||||||
import controls from './../controls';
|
import controls from '../controls';
|
||||||
import ui from './../ui';
|
import ui from '../ui';
|
||||||
import { createElement, replaceElement, toggleClass } from './../utils/elements';
|
import { createElement, replaceElement, toggleClass } from '../utils/elements';
|
||||||
import { triggerEvent } from './../utils/events';
|
import { triggerEvent } from '../utils/events';
|
||||||
import fetch from './../utils/fetch';
|
import fetch from '../utils/fetch';
|
||||||
import is from './../utils/is';
|
import is from '../utils/is';
|
||||||
import loadScript from './../utils/loadScript';
|
import loadScript from '../utils/load-script';
|
||||||
import { format, stripHTML } from './../utils/strings';
|
import { extend } from '../utils/objects';
|
||||||
import { buildUrlParams } from './../utils/urls';
|
import { format, stripHTML } from '../utils/strings';
|
||||||
|
import { setAspectRatio } from '../utils/style';
|
||||||
|
import { buildUrlParams } from '../utils/urls';
|
||||||
|
|
||||||
// Parse Vimeo ID from URL
|
// Parse Vimeo ID from URL
|
||||||
function parseId(url) {
|
function parseId(url) {
|
||||||
@@ -27,13 +29,6 @@ function parseId(url) {
|
|||||||
return url.match(regex) ? RegExp.$2 : url;
|
return url.match(regex) ? RegExp.$2 : url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get aspect ratio for dimensions
|
|
||||||
function getAspectRatio(width, height) {
|
|
||||||
const getRatio = (w, h) => (h === 0 ? w : getRatio(h, w % h));
|
|
||||||
const ratio = getRatio(width, height);
|
|
||||||
return `${width / ratio}:${height / ratio}`;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set playback state and trigger change (only on actual change)
|
// Set playback state and trigger change (only on actual change)
|
||||||
function assurePlaybackState(play) {
|
function assurePlaybackState(play) {
|
||||||
if (play && !this.embed.hasPlayed) {
|
if (play && !this.embed.hasPlayed) {
|
||||||
@@ -51,55 +46,41 @@ const vimeo = {
|
|||||||
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
||||||
|
|
||||||
// Set intial ratio
|
// Set intial ratio
|
||||||
vimeo.setAspectRatio.call(this);
|
setAspectRatio.call(this);
|
||||||
|
|
||||||
// Load the API if not already
|
// Load the SDK if not already
|
||||||
if (!is.object(window.Vimeo)) {
|
if (!is.object(window.Vimeo)) {
|
||||||
loadScript(this.config.urls.vimeo.sdk)
|
loadScript(this.config.urls.vimeo.sdk)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
vimeo.ready.call(this);
|
vimeo.ready.call(this);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.debug.warn('Vimeo API failed to load', error);
|
this.debug.warn('Vimeo SDK (player.js) failed to load', error);
|
||||||
});
|
});
|
||||||
} else {
|
} else {
|
||||||
vimeo.ready.call(this);
|
vimeo.ready.call(this);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Set aspect ratio
|
|
||||||
// For Vimeo we have an extra 300% height <div> to hide the standard controls and UI
|
|
||||||
setAspectRatio(input) {
|
|
||||||
const [x, y] = (is.string(input) ? input : this.config.ratio).split(':');
|
|
||||||
const padding = 100 / x * y;
|
|
||||||
this.elements.wrapper.style.paddingBottom = `${padding}%`;
|
|
||||||
|
|
||||||
if (this.supported.ui) {
|
|
||||||
const height = 240;
|
|
||||||
const offset = (height - padding) / (height / 50);
|
|
||||||
|
|
||||||
this.media.style.transform = `translateY(-${offset}%)`;
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// API Ready
|
// API Ready
|
||||||
ready() {
|
ready() {
|
||||||
const player = this;
|
const player = this;
|
||||||
|
const config = player.config.vimeo;
|
||||||
|
|
||||||
// Get Vimeo params for the iframe
|
// Get Vimeo params for the iframe
|
||||||
const options = {
|
const params = buildUrlParams(
|
||||||
loop: player.config.loop.active,
|
extend(
|
||||||
autoplay: player.autoplay,
|
{},
|
||||||
// muted: player.muted,
|
{
|
||||||
byline: false,
|
loop: player.config.loop.active,
|
||||||
portrait: false,
|
autoplay: player.autoplay,
|
||||||
title: false,
|
muted: player.muted,
|
||||||
speed: true,
|
gesture: 'media',
|
||||||
transparent: 0,
|
playsinline: !this.config.fullscreen.iosNative,
|
||||||
gesture: 'media',
|
},
|
||||||
playsinline: !this.config.fullscreen.iosNative,
|
config,
|
||||||
};
|
),
|
||||||
const params = buildUrlParams(options);
|
);
|
||||||
|
|
||||||
// Get the source URL or ID
|
// Get the source URL or ID
|
||||||
let source = player.media.getAttribute('src');
|
let source = player.media.getAttribute('src');
|
||||||
@@ -110,7 +91,6 @@ const vimeo = {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const id = parseId(source);
|
const id = parseId(source);
|
||||||
|
|
||||||
// Build an iframe
|
// Build an iframe
|
||||||
const iframe = createElement('iframe');
|
const iframe = createElement('iframe');
|
||||||
const src = format(player.config.urls.vimeo.iframe, id, params);
|
const src = format(player.config.urls.vimeo.iframe, id, params);
|
||||||
@@ -121,7 +101,6 @@ const vimeo = {
|
|||||||
|
|
||||||
// Get poster, if already set
|
// Get poster, if already set
|
||||||
const { poster } = player;
|
const { poster } = player;
|
||||||
|
|
||||||
// Inject the package
|
// Inject the package
|
||||||
const wrapper = createElement('div', { poster, class: player.config.classNames.embedContainer });
|
const wrapper = createElement('div', { poster, class: player.config.classNames.embedContainer });
|
||||||
wrapper.appendChild(iframe);
|
wrapper.appendChild(iframe);
|
||||||
@@ -278,6 +257,7 @@ const vimeo = {
|
|||||||
.getVideoUrl()
|
.getVideoUrl()
|
||||||
.then(value => {
|
.then(value => {
|
||||||
currentSrc = value;
|
currentSrc = value;
|
||||||
|
controls.setDownloadUrl.call(player);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
this.debug.warn(error);
|
this.debug.warn(error);
|
||||||
@@ -298,8 +278,9 @@ const vimeo = {
|
|||||||
|
|
||||||
// Set aspect ratio based on video size
|
// Set aspect ratio based on video size
|
||||||
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => {
|
Promise.all([player.embed.getVideoWidth(), player.embed.getVideoHeight()]).then(dimensions => {
|
||||||
const ratio = getAspectRatio(dimensions[0], dimensions[1]);
|
const [width, height] = dimensions;
|
||||||
vimeo.setAspectRatio.call(this, ratio);
|
player.embed.ratio = [width, height];
|
||||||
|
setAspectRatio.call(this);
|
||||||
});
|
});
|
||||||
|
|
||||||
// Set autopause
|
// Set autopause
|
||||||
|
|||||||
+80
-135
@@ -2,16 +2,16 @@
|
|||||||
// YouTube plugin
|
// YouTube plugin
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import controls from './../controls';
|
import ui from '../ui';
|
||||||
import ui from './../ui';
|
import { createElement, replaceElement, toggleClass } from '../utils/elements';
|
||||||
import { dedupe } from './../utils/arrays';
|
import { triggerEvent } from '../utils/events';
|
||||||
import { createElement, replaceElement, toggleClass } from './../utils/elements';
|
import fetch from '../utils/fetch';
|
||||||
import { triggerEvent } from './../utils/events';
|
import is from '../utils/is';
|
||||||
import fetch from './../utils/fetch';
|
import loadImage from '../utils/load-image';
|
||||||
import is from './../utils/is';
|
import loadScript from '../utils/load-script';
|
||||||
import loadImage from './../utils/loadImage';
|
import { extend } from '../utils/objects';
|
||||||
import loadScript from './../utils/loadScript';
|
import { format, generateId } from '../utils/strings';
|
||||||
import { format, generateId } from './../utils/strings';
|
import { setAspectRatio } from '../utils/style';
|
||||||
|
|
||||||
// Parse YouTube ID from URL
|
// Parse YouTube ID from URL
|
||||||
function parseId(url) {
|
function parseId(url) {
|
||||||
@@ -23,37 +23,6 @@ function parseId(url) {
|
|||||||
return url.match(regex) ? RegExp.$2 : url;
|
return url.match(regex) ? RegExp.$2 : url;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Standardise YouTube quality unit
|
|
||||||
function mapQualityUnit(input) {
|
|
||||||
const qualities = {
|
|
||||||
hd2160: 2160,
|
|
||||||
hd1440: 1440,
|
|
||||||
hd1080: 1080,
|
|
||||||
hd720: 720,
|
|
||||||
large: 480,
|
|
||||||
medium: 360,
|
|
||||||
small: 240,
|
|
||||||
tiny: 144,
|
|
||||||
};
|
|
||||||
|
|
||||||
const entry = Object.entries(qualities).find(entry => entry.includes(input));
|
|
||||||
|
|
||||||
if (entry) {
|
|
||||||
// Get the match corresponding to the input
|
|
||||||
return entry.find(value => value !== input);
|
|
||||||
}
|
|
||||||
|
|
||||||
return 'default';
|
|
||||||
}
|
|
||||||
|
|
||||||
function mapQualityUnits(levels) {
|
|
||||||
if (is.empty(levels)) {
|
|
||||||
return levels;
|
|
||||||
}
|
|
||||||
|
|
||||||
return dedupe(levels.map(level => mapQualityUnit(level)));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Set playback state and trigger change (only on actual change)
|
// Set playback state and trigger change (only on actual change)
|
||||||
function assurePlaybackState(play) {
|
function assurePlaybackState(play) {
|
||||||
if (play && !this.embed.hasPlayed) {
|
if (play && !this.embed.hasPlayed) {
|
||||||
@@ -65,84 +34,78 @@ function assurePlaybackState(play) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getHost(config) {
|
||||||
|
if (config.noCookie) {
|
||||||
|
return 'https://www.youtube-nocookie.com';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (window.location.protocol === 'http:') {
|
||||||
|
return 'http://www.youtube.com';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Use YouTube's default
|
||||||
|
return undefined;
|
||||||
|
}
|
||||||
|
|
||||||
const youtube = {
|
const youtube = {
|
||||||
setup() {
|
setup() {
|
||||||
// Add embed class for responsive
|
// Add embed class for responsive
|
||||||
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
toggleClass(this.elements.wrapper, this.config.classNames.embed, true);
|
||||||
|
|
||||||
// Set aspect ratio
|
|
||||||
youtube.setAspectRatio.call(this);
|
|
||||||
|
|
||||||
// Setup API
|
// Setup API
|
||||||
if (is.object(window.YT) && is.function(window.YT.Player)) {
|
if (is.object(window.YT) && is.function(window.YT.Player)) {
|
||||||
youtube.ready.call(this);
|
youtube.ready.call(this);
|
||||||
} else {
|
} else {
|
||||||
// Load the API
|
// Reference current global callback
|
||||||
loadScript(this.config.urls.youtube.sdk).catch(error => {
|
const callback = window.onYouTubeIframeAPIReady;
|
||||||
this.debug.warn('YouTube API failed to load', error);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Setup callback for the API
|
|
||||||
// YouTube has it's own system of course...
|
|
||||||
window.onYouTubeReadyCallbacks = window.onYouTubeReadyCallbacks || [];
|
|
||||||
|
|
||||||
// Add to queue
|
|
||||||
window.onYouTubeReadyCallbacks.push(() => {
|
|
||||||
youtube.ready.call(this);
|
|
||||||
});
|
|
||||||
|
|
||||||
// Set callback to process queue
|
// Set callback to process queue
|
||||||
window.onYouTubeIframeAPIReady = () => {
|
window.onYouTubeIframeAPIReady = () => {
|
||||||
window.onYouTubeReadyCallbacks.forEach(callback => {
|
// Call global callback if set
|
||||||
|
if (is.function(callback)) {
|
||||||
callback();
|
callback();
|
||||||
});
|
}
|
||||||
|
|
||||||
|
youtube.ready.call(this);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Load the SDK
|
||||||
|
loadScript(this.config.urls.youtube.sdk).catch(error => {
|
||||||
|
this.debug.warn('YouTube API failed to load', error);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
// Get the media title
|
// Get the media title
|
||||||
getTitle(videoId) {
|
getTitle(videoId) {
|
||||||
// Try via undocumented API method first
|
const url = format(this.config.urls.youtube.api, videoId);
|
||||||
// This method disappears now and then though...
|
|
||||||
// https://github.com/sampotts/plyr/issues/709
|
|
||||||
if (is.function(this.embed.getVideoData)) {
|
|
||||||
const { title } = this.embed.getVideoData();
|
|
||||||
|
|
||||||
if (is.empty(title)) {
|
fetch(url)
|
||||||
this.config.title = title;
|
.then(data => {
|
||||||
ui.setTitle.call(this);
|
if (is.object(data)) {
|
||||||
return;
|
const { title, height, width } = data;
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// Or via Google API
|
// Set title
|
||||||
const key = this.config.keys.google;
|
this.config.title = title;
|
||||||
if (is.string(key) && !is.empty(key)) {
|
ui.setTitle.call(this);
|
||||||
const url = format(this.config.urls.youtube.api, videoId, key);
|
|
||||||
|
|
||||||
fetch(url)
|
// Set aspect ratio
|
||||||
.then(result => {
|
this.embed.ratio = [width, height];
|
||||||
if (is.object(result)) {
|
}
|
||||||
this.config.title = result.items[0].snippet.title;
|
|
||||||
ui.setTitle.call(this);
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.catch(() => {});
|
|
||||||
}
|
|
||||||
},
|
|
||||||
|
|
||||||
// Set aspect ratio
|
setAspectRatio.call(this);
|
||||||
setAspectRatio() {
|
})
|
||||||
const ratio = this.config.ratio.split(':');
|
.catch(() => {
|
||||||
this.elements.wrapper.style.paddingBottom = `${100 / ratio[0] * ratio[1]}%`;
|
// Set aspect ratio
|
||||||
|
setAspectRatio.call(this);
|
||||||
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
// API ready
|
// API ready
|
||||||
ready() {
|
ready() {
|
||||||
const player = this;
|
const player = this;
|
||||||
|
|
||||||
// Ignore already setup (race condition)
|
// Ignore already setup (race condition)
|
||||||
const currentId = player.media.getAttribute('id');
|
const currentId = player.media && player.media.getAttribute('id');
|
||||||
if (!is.empty(currentId) && currentId.startsWith('youtube-')) {
|
if (!is.empty(currentId) && currentId.startsWith('youtube-')) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -158,52 +121,51 @@ const youtube = {
|
|||||||
// Replace the <iframe> with a <div> due to YouTube API issues
|
// Replace the <iframe> with a <div> due to YouTube API issues
|
||||||
const videoId = parseId(source);
|
const videoId = parseId(source);
|
||||||
const id = generateId(player.provider);
|
const id = generateId(player.provider);
|
||||||
|
|
||||||
// Get poster, if already set
|
// Get poster, if already set
|
||||||
const { poster } = player;
|
const { poster } = player;
|
||||||
|
|
||||||
// Replace media element
|
// Replace media element
|
||||||
const container = createElement('div', { id, poster });
|
const container = createElement('div', { id, poster });
|
||||||
player.media = replaceElement(container, player.media);
|
player.media = replaceElement(container, player.media);
|
||||||
|
|
||||||
// Id to poster wrapper
|
// Id to poster wrapper
|
||||||
const posterSrc = format => `https://img.youtube.com/vi/${videoId}/${format}default.jpg`;
|
const posterSrc = s => `https://i.ytimg.com/vi/${videoId}/${s}default.jpg`;
|
||||||
|
|
||||||
// Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
|
// Check thumbnail images in order of quality, but reject fallback thumbnails (120px wide)
|
||||||
loadImage(posterSrc('maxres'), 121) // Higest quality and unpadded
|
loadImage(posterSrc('maxres'), 121) // Higest quality and unpadded
|
||||||
.catch(() => loadImage(posterSrc('sd'), 121)) // 480p padded 4:3
|
.catch(() => loadImage(posterSrc('sd'), 121)) // 480p padded 4:3
|
||||||
.catch(() => loadImage(posterSrc('hq'))) // 360p padded 4:3. Always exists
|
.catch(() => loadImage(posterSrc('hq'))) // 360p padded 4:3. Always exists
|
||||||
.then(image => ui.setPoster.call(player, image.src))
|
.then(image => ui.setPoster.call(player, image.src))
|
||||||
.then(posterSrc => {
|
.then(src => {
|
||||||
// If the image is padded, use background-size "cover" instead (like youtube does too with their posters)
|
// If the image is padded, use background-size "cover" instead (like youtube does too with their posters)
|
||||||
if (!posterSrc.includes('maxres')) {
|
if (!src.includes('maxres')) {
|
||||||
player.elements.poster.style.backgroundSize = 'cover';
|
player.elements.poster.style.backgroundSize = 'cover';
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch(() => {});
|
.catch(() => {});
|
||||||
|
|
||||||
|
const config = player.config.youtube;
|
||||||
|
|
||||||
// Setup instance
|
// Setup instance
|
||||||
// https://developers.google.com/youtube/iframe_api_reference
|
// https://developers.google.com/youtube/iframe_api_reference
|
||||||
player.embed = new window.YT.Player(id, {
|
player.embed = new window.YT.Player(id, {
|
||||||
videoId,
|
videoId,
|
||||||
playerVars: {
|
host: getHost(config),
|
||||||
autoplay: player.config.autoplay ? 1 : 0, // Autoplay
|
playerVars: extend(
|
||||||
controls: player.supported.ui ? 0 : 1, // Only show controls if not fully supported
|
{},
|
||||||
rel: 0, // No related vids
|
{
|
||||||
showinfo: 0, // Hide info
|
autoplay: player.config.autoplay ? 1 : 0, // Autoplay
|
||||||
iv_load_policy: 3, // Hide annotations
|
hl: player.config.hl, // iframe interface language
|
||||||
modestbranding: 1, // Hide logos as much as possible (they still show one in the corner when paused)
|
controls: player.supported.ui ? 0 : 1, // Only show controls if not fully supported
|
||||||
disablekb: 1, // Disable keyboard as we handle it
|
disablekb: 1, // Disable keyboard as we handle it
|
||||||
playsinline: 1, // Allow iOS inline playback
|
playsinline: !player.config.fullscreen.iosNative ? 1 : 0, // Allow iOS inline playback
|
||||||
|
// Captions are flaky on YouTube
|
||||||
// Tracking for stats
|
cc_load_policy: player.captions.active ? 1 : 0,
|
||||||
// origin: window ? `${window.location.protocol}//${window.location.host}` : null,
|
cc_lang_pref: player.config.captions.language,
|
||||||
widget_referrer: window ? window.location.href : null,
|
// Tracking for stats
|
||||||
|
widget_referrer: window ? window.location.href : null,
|
||||||
// Captions are flaky on YouTube
|
},
|
||||||
cc_load_policy: player.captions.active ? 1 : 0,
|
config,
|
||||||
cc_lang_pref: player.config.captions.language,
|
),
|
||||||
},
|
|
||||||
events: {
|
events: {
|
||||||
onError(event) {
|
onError(event) {
|
||||||
// YouTube may fire onError twice, so only handle it once
|
// YouTube may fire onError twice, so only handle it once
|
||||||
@@ -224,11 +186,6 @@ const youtube = {
|
|||||||
triggerEvent.call(player, player.media, 'error');
|
triggerEvent.call(player, player.media, 'error');
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
onPlaybackQualityChange() {
|
|
||||||
triggerEvent.call(player, player.media, 'qualitychange', false, {
|
|
||||||
quality: player.media.quality,
|
|
||||||
});
|
|
||||||
},
|
|
||||||
onPlaybackRateChange(event) {
|
onPlaybackRateChange(event) {
|
||||||
// Get the instance
|
// Get the instance
|
||||||
const instance = event.target;
|
const instance = event.target;
|
||||||
@@ -239,6 +196,10 @@ const youtube = {
|
|||||||
triggerEvent.call(player, player.media, 'ratechange');
|
triggerEvent.call(player, player.media, 'ratechange');
|
||||||
},
|
},
|
||||||
onReady(event) {
|
onReady(event) {
|
||||||
|
// Bail if onReady has already been called. See issue #1108
|
||||||
|
if (is.function(player.media.play)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
// Get the instance
|
// Get the instance
|
||||||
const instance = event.target;
|
const instance = event.target;
|
||||||
|
|
||||||
@@ -294,16 +255,6 @@ const youtube = {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
// Quality
|
|
||||||
Object.defineProperty(player.media, 'quality', {
|
|
||||||
get() {
|
|
||||||
return mapQualityUnit(instance.getPlaybackQuality());
|
|
||||||
},
|
|
||||||
set(input) {
|
|
||||||
instance.setPlaybackQuality(mapQualityUnit(input));
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
// Volume
|
// Volume
|
||||||
let { volume } = player.config;
|
let { volume } = player.config;
|
||||||
Object.defineProperty(player.media, 'volume', {
|
Object.defineProperty(player.media, 'volume', {
|
||||||
@@ -433,7 +384,7 @@ const youtube = {
|
|||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
// Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
|
// Restore paused state (YouTube starts playing on seek if the video hasn't been played yet)
|
||||||
if (player.media.paused && !player.embed.hasPlayed) {
|
if (!player.config.autoplay && player.media.paused && !player.embed.hasPlayed) {
|
||||||
player.media.pause();
|
player.media.pause();
|
||||||
} else {
|
} else {
|
||||||
assurePlaybackState.call(player, true);
|
assurePlaybackState.call(player, true);
|
||||||
@@ -452,12 +403,6 @@ const youtube = {
|
|||||||
player.media.duration = instance.getDuration();
|
player.media.duration = instance.getDuration();
|
||||||
triggerEvent.call(player, player.media, 'durationchange');
|
triggerEvent.call(player, player.media, 'durationchange');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get quality
|
|
||||||
controls.setQualityMenu.call(
|
|
||||||
player,
|
|
||||||
mapQualityUnits(instance.getAvailableQualityLevels()),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
|
|||||||
+216
-83
@@ -1,12 +1,13 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Plyr
|
// Plyr
|
||||||
// plyr.js v3.3.20
|
// plyr.js v3.5.5
|
||||||
// https://github.com/sampotts/plyr
|
// https://github.com/sampotts/plyr
|
||||||
// License: The MIT License (MIT)
|
// License: The MIT License (MIT)
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import captions from './captions';
|
import captions from './captions';
|
||||||
import defaults from './config/defaults';
|
import defaults from './config/defaults';
|
||||||
|
import { pip } from './config/states';
|
||||||
import { getProviderByUrl, providers, types } from './config/types';
|
import { getProviderByUrl, providers, types } from './config/types';
|
||||||
import Console from './console';
|
import Console from './console';
|
||||||
import controls from './controls';
|
import controls from './controls';
|
||||||
@@ -14,6 +15,7 @@ import Fullscreen from './fullscreen';
|
|||||||
import Listeners from './listeners';
|
import Listeners from './listeners';
|
||||||
import media from './media';
|
import media from './media';
|
||||||
import Ads from './plugins/ads';
|
import Ads from './plugins/ads';
|
||||||
|
import PreviewThumbnails from './plugins/preview-thumbnails';
|
||||||
import source from './source';
|
import source from './source';
|
||||||
import Storage from './storage';
|
import Storage from './storage';
|
||||||
import support from './support';
|
import support from './support';
|
||||||
@@ -22,8 +24,10 @@ import { closest } from './utils/arrays';
|
|||||||
import { createElement, hasClass, removeElement, replaceElement, toggleClass, wrap } from './utils/elements';
|
import { createElement, hasClass, removeElement, replaceElement, toggleClass, wrap } from './utils/elements';
|
||||||
import { off, on, once, triggerEvent, unbindListeners } from './utils/events';
|
import { off, on, once, triggerEvent, unbindListeners } from './utils/events';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
import loadSprite from './utils/loadSprite';
|
import loadSprite from './utils/load-sprite';
|
||||||
|
import { clamp } from './utils/numbers';
|
||||||
import { cloneDeep, extend } from './utils/objects';
|
import { cloneDeep, extend } from './utils/objects';
|
||||||
|
import { getAspectRatio, reduceAspectRatio, setAspectRatio, validateRatio } from './utils/style';
|
||||||
import { parseUrl } from './utils/urls';
|
import { parseUrl } from './utils/urls';
|
||||||
|
|
||||||
// Private properties
|
// Private properties
|
||||||
@@ -75,16 +79,17 @@ class Plyr {
|
|||||||
// Elements cache
|
// Elements cache
|
||||||
this.elements = {
|
this.elements = {
|
||||||
container: null,
|
container: null,
|
||||||
|
captions: null,
|
||||||
buttons: {},
|
buttons: {},
|
||||||
display: {},
|
display: {},
|
||||||
progress: {},
|
progress: {},
|
||||||
inputs: {},
|
inputs: {},
|
||||||
settings: {
|
settings: {
|
||||||
|
popup: null,
|
||||||
menu: null,
|
menu: null,
|
||||||
panes: {},
|
panels: {},
|
||||||
tabs: {},
|
buttons: {},
|
||||||
},
|
},
|
||||||
captions: null,
|
|
||||||
};
|
};
|
||||||
|
|
||||||
// Captions
|
// Captions
|
||||||
@@ -146,7 +151,6 @@ class Plyr {
|
|||||||
// Set media type based on tag or data attribute
|
// Set media type based on tag or data attribute
|
||||||
// Supported: video, audio, vimeo, youtube
|
// Supported: video, audio, vimeo, youtube
|
||||||
const type = this.media.tagName.toLowerCase();
|
const type = this.media.tagName.toLowerCase();
|
||||||
|
|
||||||
// Embed properties
|
// Embed properties
|
||||||
let iframe = null;
|
let iframe = null;
|
||||||
let url = null;
|
let url = null;
|
||||||
@@ -171,7 +175,7 @@ class Plyr {
|
|||||||
this.elements.container.className = '';
|
this.elements.container.className = '';
|
||||||
|
|
||||||
// Get attributes from URL and set config
|
// Get attributes from URL and set config
|
||||||
if (url.searchParams.length) {
|
if (url.search.length) {
|
||||||
const truthy = ['1', 'true'];
|
const truthy = ['1', 'true'];
|
||||||
|
|
||||||
if (truthy.includes(url.searchParams.get('autoplay'))) {
|
if (truthy.includes(url.searchParams.get('autoplay'))) {
|
||||||
@@ -185,6 +189,7 @@ class Plyr {
|
|||||||
// YouTube requires the playsinline in the URL
|
// YouTube requires the playsinline in the URL
|
||||||
if (this.isYouTube) {
|
if (this.isYouTube) {
|
||||||
this.config.playsinline = truthy.includes(url.searchParams.get('playsinline'));
|
this.config.playsinline = truthy.includes(url.searchParams.get('playsinline'));
|
||||||
|
this.config.youtube.hl = url.searchParams.get('hl'); // TODO: Should this be setting language?
|
||||||
} else {
|
} else {
|
||||||
this.config.playsinline = true;
|
this.config.playsinline = true;
|
||||||
}
|
}
|
||||||
@@ -220,7 +225,7 @@ class Plyr {
|
|||||||
if (this.media.hasAttribute('autoplay')) {
|
if (this.media.hasAttribute('autoplay')) {
|
||||||
this.config.autoplay = true;
|
this.config.autoplay = true;
|
||||||
}
|
}
|
||||||
if (this.media.hasAttribute('playsinline')) {
|
if (this.media.hasAttribute('playsinline') || this.media.hasAttribute('webkit-playsinline')) {
|
||||||
this.config.playsinline = true;
|
this.config.playsinline = true;
|
||||||
}
|
}
|
||||||
if (this.media.hasAttribute('muted')) {
|
if (this.media.hasAttribute('muted')) {
|
||||||
@@ -259,7 +264,7 @@ class Plyr {
|
|||||||
|
|
||||||
// Wrap media
|
// Wrap media
|
||||||
if (!is.element(this.elements.container)) {
|
if (!is.element(this.elements.container)) {
|
||||||
this.elements.container = createElement('div');
|
this.elements.container = createElement('div', { tabindex: 0 });
|
||||||
wrap(this.media, this.elements.container);
|
wrap(this.media, this.elements.container);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -292,11 +297,21 @@ class Plyr {
|
|||||||
this.fullscreen = new Fullscreen(this);
|
this.fullscreen = new Fullscreen(this);
|
||||||
|
|
||||||
// Setup ads if provided
|
// Setup ads if provided
|
||||||
this.ads = new Ads(this);
|
if (this.config.ads.enabled) {
|
||||||
|
this.ads = new Ads(this);
|
||||||
|
}
|
||||||
|
|
||||||
// Autoplay if required
|
// Autoplay if required
|
||||||
if (this.config.autoplay) {
|
if (this.isHTML5 && this.config.autoplay) {
|
||||||
this.play();
|
setTimeout(() => this.play(), 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Seek time will be recorded (in listeners.js) so we can prevent hiding controls for a few seconds after seek
|
||||||
|
this.lastSeekTime = 0;
|
||||||
|
|
||||||
|
// Setup preview thumbnails if enabled
|
||||||
|
if (this.config.previewThumbnails.enabled) {
|
||||||
|
this.previewThumbnails = new PreviewThumbnails(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -308,22 +323,27 @@ class Plyr {
|
|||||||
* Types and provider helpers
|
* Types and provider helpers
|
||||||
*/
|
*/
|
||||||
get isHTML5() {
|
get isHTML5() {
|
||||||
return Boolean(this.provider === providers.html5);
|
return this.provider === providers.html5;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isEmbed() {
|
get isEmbed() {
|
||||||
return Boolean(this.isYouTube || this.isVimeo);
|
return this.isYouTube || this.isVimeo;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isYouTube() {
|
get isYouTube() {
|
||||||
return Boolean(this.provider === providers.youtube);
|
return this.provider === providers.youtube;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isVimeo() {
|
get isVimeo() {
|
||||||
return Boolean(this.provider === providers.vimeo);
|
return this.provider === providers.vimeo;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isVideo() {
|
get isVideo() {
|
||||||
return Boolean(this.type === types.video);
|
return this.type === types.video;
|
||||||
}
|
}
|
||||||
|
|
||||||
get isAudio() {
|
get isAudio() {
|
||||||
return Boolean(this.type === types.audio);
|
return this.type === types.audio;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -334,6 +354,11 @@ class Plyr {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Intecept play with ads
|
||||||
|
if (this.ads && this.ads.enabled) {
|
||||||
|
this.ads.managerPromise.then(() => this.ads.play()).catch(() => this.media.play());
|
||||||
|
}
|
||||||
|
|
||||||
// Return the promise (for HTML5)
|
// Return the promise (for HTML5)
|
||||||
return this.media.play();
|
return this.media.play();
|
||||||
}
|
}
|
||||||
@@ -379,7 +404,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle playback based on current status
|
* Toggle playback based on current status
|
||||||
* @param {boolean} input
|
* @param {Boolean} input
|
||||||
*/
|
*/
|
||||||
togglePlay(input) {
|
togglePlay(input) {
|
||||||
// Toggle based on current state if nothing passed
|
// Toggle based on current state if nothing passed
|
||||||
@@ -413,7 +438,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Rewind
|
* Rewind
|
||||||
* @param {number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime
|
* @param {Number} seekTime - how far to rewind in seconds. Defaults to the config.seekTime
|
||||||
*/
|
*/
|
||||||
rewind(seekTime) {
|
rewind(seekTime) {
|
||||||
this.currentTime = this.currentTime - (is.number(seekTime) ? seekTime : this.config.seekTime);
|
this.currentTime = this.currentTime - (is.number(seekTime) ? seekTime : this.config.seekTime);
|
||||||
@@ -421,7 +446,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Fast forward
|
* Fast forward
|
||||||
* @param {number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime
|
* @param {Number} seekTime - how far to fast forward in seconds. Defaults to the config.seekTime
|
||||||
*/
|
*/
|
||||||
forward(seekTime) {
|
forward(seekTime) {
|
||||||
this.currentTime = this.currentTime + (is.number(seekTime) ? seekTime : this.config.seekTime);
|
this.currentTime = this.currentTime + (is.number(seekTime) ? seekTime : this.config.seekTime);
|
||||||
@@ -429,7 +454,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Seek to a time
|
* Seek to a time
|
||||||
* @param {number} input - where to seek to in seconds. Defaults to 0 (the start)
|
* @param {Number} input - where to seek to in seconds. Defaults to 0 (the start)
|
||||||
*/
|
*/
|
||||||
set currentTime(input) {
|
set currentTime(input) {
|
||||||
// Bail if media duration isn't available yet
|
// Bail if media duration isn't available yet
|
||||||
@@ -488,9 +513,9 @@ class Plyr {
|
|||||||
get duration() {
|
get duration() {
|
||||||
// Faux duration set via config
|
// Faux duration set via config
|
||||||
const fauxDuration = parseFloat(this.config.duration);
|
const fauxDuration = parseFloat(this.config.duration);
|
||||||
|
// Media duration can be NaN or Infinity before the media has loaded
|
||||||
// Media duration can be NaN before the media has loaded
|
const realDuration = (this.media || {}).duration;
|
||||||
const duration = (this.media || {}).duration || 0;
|
const duration = !is.number(realDuration) || realDuration === Infinity ? 0 : realDuration;
|
||||||
|
|
||||||
// If config duration is funky, use regular duration
|
// If config duration is funky, use regular duration
|
||||||
return fauxDuration || duration;
|
return fauxDuration || duration;
|
||||||
@@ -498,7 +523,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the player volume
|
* Set the player volume
|
||||||
* @param {number} value - must be between 0 and 1. Defaults to the value from local storage and config.volume if not set in storage
|
* @param {Number} value - must be between 0 and 1. Defaults to the value from local storage and config.volume if not set in storage
|
||||||
*/
|
*/
|
||||||
set volume(value) {
|
set volume(value) {
|
||||||
let volume = value;
|
let volume = value;
|
||||||
@@ -549,7 +574,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Increase volume
|
* Increase volume
|
||||||
* @param {boolean} step - How much to decrease by (between 0 and 1)
|
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
||||||
*/
|
*/
|
||||||
increaseVolume(step) {
|
increaseVolume(step) {
|
||||||
const volume = this.media.muted ? 0 : this.volume;
|
const volume = this.media.muted ? 0 : this.volume;
|
||||||
@@ -558,7 +583,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Decrease volume
|
* Decrease volume
|
||||||
* @param {boolean} step - How much to decrease by (between 0 and 1)
|
* @param {Boolean} step - How much to decrease by (between 0 and 1)
|
||||||
*/
|
*/
|
||||||
decreaseVolume(step) {
|
decreaseVolume(step) {
|
||||||
this.increaseVolume(-step);
|
this.increaseVolume(-step);
|
||||||
@@ -566,7 +591,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set muted state
|
* Set muted state
|
||||||
* @param {boolean} mute
|
* @param {Boolean} mute
|
||||||
*/
|
*/
|
||||||
set muted(mute) {
|
set muted(mute) {
|
||||||
let toggle = mute;
|
let toggle = mute;
|
||||||
@@ -618,7 +643,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set playback speed
|
* Set playback speed
|
||||||
* @param {number} speed - the speed of playback (0.5-2.0)
|
* @param {Number} speed - the speed of playback (0.5-2.0)
|
||||||
*/
|
*/
|
||||||
set speed(input) {
|
set speed(input) {
|
||||||
let speed = null;
|
let speed = null;
|
||||||
@@ -635,24 +660,17 @@ class Plyr {
|
|||||||
speed = this.config.speed.selected;
|
speed = this.config.speed.selected;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set min/max
|
// Clamp to min/max
|
||||||
if (speed < 0.1) {
|
const { minimumSpeed: min, maximumSpeed: max } = this;
|
||||||
speed = 0.1;
|
speed = clamp(speed, min, max);
|
||||||
}
|
|
||||||
if (speed > 2.0) {
|
|
||||||
speed = 2.0;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!this.config.speed.options.includes(speed)) {
|
|
||||||
this.debug.warn(`Unsupported speed (${speed})`);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update config
|
// Update config
|
||||||
this.config.speed.selected = speed;
|
this.config.speed.selected = speed;
|
||||||
|
|
||||||
// Set media speed
|
// Set media speed
|
||||||
this.media.playbackRate = speed;
|
setTimeout(() => {
|
||||||
|
this.media.playbackRate = speed;
|
||||||
|
}, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -662,10 +680,46 @@ class Plyr {
|
|||||||
return Number(this.media.playbackRate);
|
return Number(this.media.playbackRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the minimum allowed speed
|
||||||
|
*/
|
||||||
|
get minimumSpeed() {
|
||||||
|
if (this.isYouTube) {
|
||||||
|
// https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
|
||||||
|
return Math.min(...this.options.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isVimeo) {
|
||||||
|
// https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
|
||||||
|
return 0.5;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/32320020/1191319
|
||||||
|
return 0.0625;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the maximum allowed speed
|
||||||
|
*/
|
||||||
|
get maximumSpeed() {
|
||||||
|
if (this.isYouTube) {
|
||||||
|
// https://developers.google.com/youtube/iframe_api_reference#setPlaybackRate
|
||||||
|
return Math.max(...this.options.speed);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (this.isVimeo) {
|
||||||
|
// https://github.com/vimeo/player.js/#setplaybackrateplaybackrate-number-promisenumber-rangeerrorerror
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
|
||||||
|
// https://stackoverflow.com/a/32320020/1191319
|
||||||
|
return 16;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set playback quality
|
* Set playback quality
|
||||||
* Currently HTML5 & YouTube only
|
* Currently HTML5 & YouTube only
|
||||||
* @param {number} input - Quality level
|
* @param {Number} input - Quality level
|
||||||
*/
|
*/
|
||||||
set quality(input) {
|
set quality(input) {
|
||||||
const config = this.config.quality;
|
const config = this.config.quality;
|
||||||
@@ -682,20 +736,27 @@ class Plyr {
|
|||||||
config.default,
|
config.default,
|
||||||
].find(is.number);
|
].find(is.number);
|
||||||
|
|
||||||
|
let updateStorage = true;
|
||||||
|
|
||||||
if (!options.includes(quality)) {
|
if (!options.includes(quality)) {
|
||||||
const value = closest(options, quality);
|
const value = closest(options, quality);
|
||||||
this.debug.warn(`Unsupported quality option: ${quality}, using ${value} instead`);
|
this.debug.warn(`Unsupported quality option: ${quality}, using ${value} instead`);
|
||||||
quality = value;
|
quality = value;
|
||||||
}
|
|
||||||
|
|
||||||
// Trigger request event
|
// Don't update storage if quality is not supported
|
||||||
triggerEvent.call(this, this.media, 'qualityrequested', false, { quality });
|
updateStorage = false;
|
||||||
|
}
|
||||||
|
|
||||||
// Update config
|
// Update config
|
||||||
config.selected = quality;
|
config.selected = quality;
|
||||||
|
|
||||||
// Set quality
|
// Set quality
|
||||||
this.media.quality = quality;
|
this.media.quality = quality;
|
||||||
|
|
||||||
|
// Save to storage
|
||||||
|
if (updateStorage) {
|
||||||
|
this.storage.set({ quality });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -708,7 +769,7 @@ class Plyr {
|
|||||||
/**
|
/**
|
||||||
* Toggle loop
|
* Toggle loop
|
||||||
* TODO: Finish fancy new logic. Set the indicator on load as user may pass loop as config
|
* TODO: Finish fancy new logic. Set the indicator on load as user may pass loop as config
|
||||||
* @param {boolean} input - Whether to loop or not
|
* @param {Boolean} input - Whether to loop or not
|
||||||
*/
|
*/
|
||||||
set loop(input) {
|
set loop(input) {
|
||||||
const toggle = is.boolean(input) ? input : this.config.loop.active;
|
const toggle = is.boolean(input) ? input : this.config.loop.active;
|
||||||
@@ -768,7 +829,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set new media source
|
* Set new media source
|
||||||
* @param {object} input - The new source object (see docs)
|
* @param {Object} input - The new source object (see docs)
|
||||||
*/
|
*/
|
||||||
set source(input) {
|
set source(input) {
|
||||||
source.change.call(this, input);
|
source.change.call(this, input);
|
||||||
@@ -781,9 +842,31 @@ class Plyr {
|
|||||||
return this.media.currentSrc;
|
return this.media.currentSrc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get a download URL (either source or custom)
|
||||||
|
*/
|
||||||
|
get download() {
|
||||||
|
const { download } = this.config.urls;
|
||||||
|
|
||||||
|
return is.url(download) ? download : this.source;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the download URL
|
||||||
|
*/
|
||||||
|
set download(input) {
|
||||||
|
if (!is.url(input)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config.urls.download = input;
|
||||||
|
|
||||||
|
controls.setDownloadUrl.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the poster image for a video
|
* Set the poster image for a video
|
||||||
* @param {input} - the URL for the new poster image
|
* @param {String} input - the URL for the new poster image
|
||||||
*/
|
*/
|
||||||
set poster(input) {
|
set poster(input) {
|
||||||
if (!this.isVideo) {
|
if (!this.isVideo) {
|
||||||
@@ -805,9 +888,41 @@ class Plyr {
|
|||||||
return this.media.getAttribute('poster');
|
return this.media.getAttribute('poster');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the current aspect ratio in use
|
||||||
|
*/
|
||||||
|
get ratio() {
|
||||||
|
if (!this.isVideo) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const ratio = reduceAspectRatio(getAspectRatio.call(this));
|
||||||
|
|
||||||
|
return is.array(ratio) ? ratio.join(':') : ratio;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set video aspect ratio
|
||||||
|
*/
|
||||||
|
set ratio(input) {
|
||||||
|
if (!this.isVideo) {
|
||||||
|
this.debug.warn('Aspect ratio can only be set for video');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!is.string(input) || !validateRatio(input)) {
|
||||||
|
this.debug.error(`Invalid aspect ratio specified (${input})`);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
this.config.ratio = input;
|
||||||
|
|
||||||
|
setAspectRatio.call(this);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the autoplay state
|
* Set the autoplay state
|
||||||
* @param {boolean} input - Whether to autoplay or not
|
* @param {Boolean} input - Whether to autoplay or not
|
||||||
*/
|
*/
|
||||||
set autoplay(input) {
|
set autoplay(input) {
|
||||||
const toggle = is.boolean(input) ? input : this.config.autoplay;
|
const toggle = is.boolean(input) ? input : this.config.autoplay;
|
||||||
@@ -823,7 +938,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle captions
|
* Toggle captions
|
||||||
* @param {boolean} input - Whether to enable captions
|
* @param {Boolean} input - Whether to enable captions
|
||||||
*/
|
*/
|
||||||
toggleCaptions(input) {
|
toggleCaptions(input) {
|
||||||
captions.toggle.call(this, input, false);
|
captions.toggle.call(this, input, false);
|
||||||
@@ -831,7 +946,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the caption track by index
|
* Set the caption track by index
|
||||||
* @param {number} - Caption index
|
* @param {Number} - Caption index
|
||||||
*/
|
*/
|
||||||
set currentTrack(input) {
|
set currentTrack(input) {
|
||||||
captions.set.call(this, input, false);
|
captions.set.call(this, input, false);
|
||||||
@@ -848,7 +963,7 @@ class Plyr {
|
|||||||
/**
|
/**
|
||||||
* Set the wanted language for captions
|
* Set the wanted language for captions
|
||||||
* Since tracks can be added later it won't update the actual caption track until there is a matching track
|
* Since tracks can be added later it won't update the actual caption track until there is a matching track
|
||||||
* @param {string} - Two character ISO language code (e.g. EN, FR, PT, etc)
|
* @param {String} - Two character ISO language code (e.g. EN, FR, PT, etc)
|
||||||
*/
|
*/
|
||||||
set language(input) {
|
set language(input) {
|
||||||
captions.setLanguage.call(this, input, false);
|
captions.setLanguage.call(this, input, false);
|
||||||
@@ -867,21 +982,28 @@ class Plyr {
|
|||||||
* TODO: detect outside changes
|
* TODO: detect outside changes
|
||||||
*/
|
*/
|
||||||
set pip(input) {
|
set pip(input) {
|
||||||
const states = {
|
|
||||||
pip: 'picture-in-picture',
|
|
||||||
inline: 'inline',
|
|
||||||
};
|
|
||||||
|
|
||||||
// Bail if no support
|
// Bail if no support
|
||||||
if (!support.pip) {
|
if (!support.pip) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle based on current state if not passed
|
// Toggle based on current state if not passed
|
||||||
const toggle = is.boolean(input) ? input : this.pip === states.inline;
|
const toggle = is.boolean(input) ? input : !this.pip;
|
||||||
|
|
||||||
// Toggle based on current state
|
// Toggle based on current state
|
||||||
this.media.webkitSetPresentationMode(toggle ? states.pip : states.inline);
|
// Safari
|
||||||
|
if (is.function(this.media.webkitSetPresentationMode)) {
|
||||||
|
this.media.webkitSetPresentationMode(toggle ? pip.active : pip.inactive);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chrome
|
||||||
|
if (is.function(this.media.requestPictureInPicture)) {
|
||||||
|
if (!this.pip && toggle) {
|
||||||
|
this.media.requestPictureInPicture();
|
||||||
|
} else if (this.pip && !toggle) {
|
||||||
|
document.exitPictureInPicture();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -892,7 +1014,13 @@ class Plyr {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
return this.media.webkitPresentationMode;
|
// Safari
|
||||||
|
if (!is.empty(this.media.webkitPresentationMode)) {
|
||||||
|
return this.media.webkitPresentationMode === pip.active;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chrome
|
||||||
|
return this.media === document.pictureInPictureElement;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -908,17 +1036,15 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Toggle the player controls
|
* Toggle the player controls
|
||||||
* @param {boolean} [toggle] - Whether to show the controls
|
* @param {Boolean} [toggle] - Whether to show the controls
|
||||||
*/
|
*/
|
||||||
toggleControls(toggle) {
|
toggleControls(toggle) {
|
||||||
// Don't toggle if missing UI support or if it's audio
|
// Don't toggle if missing UI support or if it's audio
|
||||||
if (this.supported.ui && !this.isAudio) {
|
if (this.supported.ui && !this.isAudio) {
|
||||||
// Get state before change
|
// Get state before change
|
||||||
const isHidden = hasClass(this.elements.container, this.config.classNames.hideControls);
|
const isHidden = hasClass(this.elements.container, this.config.classNames.hideControls);
|
||||||
|
|
||||||
// Negate the argument if not undefined since adding the class to hides the controls
|
// Negate the argument if not undefined since adding the class to hides the controls
|
||||||
const force = typeof toggle === 'undefined' ? undefined : !toggle;
|
const force = typeof toggle === 'undefined' ? undefined : !toggle;
|
||||||
|
|
||||||
// Apply and get updated state
|
// Apply and get updated state
|
||||||
const hiding = toggleClass(this.elements.container, this.config.classNames.hideControls, force);
|
const hiding = toggleClass(this.elements.container, this.config.classNames.hideControls, force);
|
||||||
|
|
||||||
@@ -926,36 +1052,41 @@ class Plyr {
|
|||||||
if (hiding && this.config.controls.includes('settings') && !is.empty(this.config.settings)) {
|
if (hiding && this.config.controls.includes('settings') && !is.empty(this.config.settings)) {
|
||||||
controls.toggleMenu.call(this, false);
|
controls.toggleMenu.call(this, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Trigger event on change
|
// Trigger event on change
|
||||||
if (hiding !== isHidden) {
|
if (hiding !== isHidden) {
|
||||||
const eventName = hiding ? 'controlshidden' : 'controlsshown';
|
const eventName = hiding ? 'controlshidden' : 'controlsshown';
|
||||||
triggerEvent.call(this, this.media, eventName);
|
triggerEvent.call(this, this.media, eventName);
|
||||||
}
|
}
|
||||||
|
|
||||||
return !hiding;
|
return !hiding;
|
||||||
}
|
}
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners
|
* Add event listeners
|
||||||
* @param {string} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
on(event, callback) {
|
on(event, callback) {
|
||||||
on.call(this, this.elements.container, event, callback);
|
on.call(this, this.elements.container, event, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Add event listeners once
|
* Add event listeners once
|
||||||
* @param {string} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
once(event, callback) {
|
once(event, callback) {
|
||||||
once.call(this, this.elements.container, event, callback);
|
once.call(this, this.elements.container, event, callback);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Remove event listeners
|
* Remove event listeners
|
||||||
* @param {string} event - Event type
|
* @param {String} event - Event type
|
||||||
* @param {function} callback - Callback for when event occurs
|
* @param {Function} callback - Callback for when event occurs
|
||||||
*/
|
*/
|
||||||
off(event, callback) {
|
off(event, callback) {
|
||||||
off(this.elements.container, event, callback);
|
off(this.elements.container, event, callback);
|
||||||
@@ -965,8 +1096,8 @@ class Plyr {
|
|||||||
* Destroy an instance
|
* Destroy an instance
|
||||||
* Event listeners are removed when elements are removed
|
* Event listeners are removed when elements are removed
|
||||||
* http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory
|
* http://stackoverflow.com/questions/12528049/if-a-dom-element-is-removed-are-its-listeners-also-removed-from-memory
|
||||||
* @param {function} callback - Callback for when destroy is complete
|
* @param {Function} callback - Callback for when destroy is complete
|
||||||
* @param {boolean} soft - Whether it's a soft destroy (for source changes etc)
|
* @param {Boolean} soft - Whether it's a soft destroy (for source changes etc)
|
||||||
*/
|
*/
|
||||||
destroy(callback, soft = false) {
|
destroy(callback, soft = false) {
|
||||||
if (!this.ready) {
|
if (!this.ready) {
|
||||||
@@ -1029,11 +1160,13 @@ class Plyr {
|
|||||||
// Stop playback
|
// Stop playback
|
||||||
this.stop();
|
this.stop();
|
||||||
|
|
||||||
|
// Clear timeouts
|
||||||
|
clearTimeout(this.timers.loading);
|
||||||
|
clearTimeout(this.timers.controls);
|
||||||
|
clearTimeout(this.timers.resized);
|
||||||
|
|
||||||
// Provider specific stuff
|
// Provider specific stuff
|
||||||
if (this.isHTML5) {
|
if (this.isHTML5) {
|
||||||
// Clear timeout
|
|
||||||
clearTimeout(this.timers.loading);
|
|
||||||
|
|
||||||
// Restore native video controls
|
// Restore native video controls
|
||||||
ui.toggleNativeControls.call(this, true);
|
ui.toggleNativeControls.call(this, true);
|
||||||
|
|
||||||
@@ -1065,7 +1198,7 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for support for a mime type (HTML5 only)
|
* Check for support for a mime type (HTML5 only)
|
||||||
* @param {string} type - Mime type
|
* @param {String} type - Mime type
|
||||||
*/
|
*/
|
||||||
supports(type) {
|
supports(type) {
|
||||||
return support.mime.call(this, type);
|
return support.mime.call(this, type);
|
||||||
@@ -1073,9 +1206,9 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Check for support
|
* Check for support
|
||||||
* @param {string} type - Player type (audio/video)
|
* @param {String} type - Player type (audio/video)
|
||||||
* @param {string} provider - Provider (html5/youtube/vimeo)
|
* @param {String} provider - Provider (html5/youtube/vimeo)
|
||||||
* @param {bool} inline - Where player has `playsinline` sttribute
|
* @param {Boolean} inline - Where player has `playsinline` sttribute
|
||||||
*/
|
*/
|
||||||
static supported(type, provider, inline) {
|
static supported(type, provider, inline) {
|
||||||
return support.check(type, provider, inline);
|
return support.check(type, provider, inline);
|
||||||
@@ -1083,8 +1216,8 @@ class Plyr {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Load an SVG sprite into the page
|
* Load an SVG sprite into the page
|
||||||
* @param {string} url - URL for the SVG sprite
|
* @param {String} url - URL for the SVG sprite
|
||||||
* @param {string} [id] - Unique ID
|
* @param {String} [id] - Unique ID
|
||||||
*/
|
*/
|
||||||
static loadSprite(url, id) {
|
static loadSprite(url, id) {
|
||||||
return loadSprite(url, id);
|
return loadSprite(url, id);
|
||||||
@@ -1093,7 +1226,7 @@ class Plyr {
|
|||||||
/**
|
/**
|
||||||
* Setup multiple instances
|
* Setup multiple instances
|
||||||
* @param {*} selector
|
* @param {*} selector
|
||||||
* @param {object} options
|
* @param {Object} options
|
||||||
*/
|
*/
|
||||||
static setup(selector, options = {}) {
|
static setup(selector, options = {}) {
|
||||||
let targets = null;
|
let targets = null;
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// Plyr Polyfilled Build
|
// Plyr Polyfilled Build
|
||||||
// plyr.js v3.3.20
|
// plyr.js v3.5.5
|
||||||
// https://github.com/sampotts/plyr
|
// https://github.com/sampotts/plyr
|
||||||
// License: The MIT License (MIT)
|
// License: The MIT License (MIT)
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import 'babel-polyfill';
|
|
||||||
import 'custom-event-polyfill';
|
import 'custom-event-polyfill';
|
||||||
import 'url-polyfill';
|
import 'url-polyfill';
|
||||||
|
|
||||||
import Plyr from './plyr';
|
import Plyr from './plyr';
|
||||||
|
|
||||||
export default Plyr;
|
export default Plyr;
|
||||||
|
|||||||
+11
-4
@@ -114,12 +114,9 @@ const source = {
|
|||||||
// HTML5 stuff
|
// HTML5 stuff
|
||||||
if (this.isHTML5) {
|
if (this.isHTML5) {
|
||||||
// Setup captions
|
// Setup captions
|
||||||
if ('tracks' in input) {
|
if (Object.keys(input).includes('tracks')) {
|
||||||
source.insertElements.call(this, 'track', input.tracks);
|
source.insertElements.call(this, 'track', input.tracks);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Load HTML5 sources
|
|
||||||
this.media.load();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// If HTML5 or embed but not fully supported, setupInterface and call ready now
|
// If HTML5 or embed but not fully supported, setupInterface and call ready now
|
||||||
@@ -128,6 +125,16 @@ const source = {
|
|||||||
ui.build.call(this);
|
ui.build.call(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load HTML5 sources
|
||||||
|
if (this.isHTML5) {
|
||||||
|
this.media.load();
|
||||||
|
}
|
||||||
|
|
||||||
|
// Reload thumbnails
|
||||||
|
if (this.previewThumbnails) {
|
||||||
|
this.previewThumbnails.load();
|
||||||
|
}
|
||||||
|
|
||||||
// Update the fullscreen support
|
// Update the fullscreen support
|
||||||
this.fullscreen.update();
|
this.fullscreen.update();
|
||||||
},
|
},
|
||||||
|
|||||||
+33
-15
@@ -36,8 +36,26 @@ const support = {
|
|||||||
},
|
},
|
||||||
|
|
||||||
// Picture-in-picture support
|
// Picture-in-picture support
|
||||||
// Safari only currently
|
// Safari & Chrome only currently
|
||||||
pip: (() => !browser.isIPhone && is.function(createElement('video').webkitSetPresentationMode))(),
|
pip: (() => {
|
||||||
|
if (browser.isIPhone) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Safari
|
||||||
|
// https://developer.apple.com/documentation/webkitjs/adding_picture_in_picture_to_your_safari_media_controls
|
||||||
|
if (is.function(createElement('video').webkitSetPresentationMode)) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Chrome
|
||||||
|
// https://developers.google.com/web/updates/2018/10/watch-video-using-picture-in-picture
|
||||||
|
if (document.pictureInPictureEnabled && !createElement('video').disablePictureInPicture) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
})(),
|
||||||
|
|
||||||
// Airplay support
|
// Airplay support
|
||||||
// Safari only currently
|
// Safari only currently
|
||||||
@@ -50,27 +68,27 @@ const support = {
|
|||||||
// Check for mime type support against a player instance
|
// Check for mime type support against a player instance
|
||||||
// Credits: http://diveintohtml5.info/everything.html
|
// Credits: http://diveintohtml5.info/everything.html
|
||||||
// Related: http://www.leanbackplayer.com/test/h5mt.html
|
// Related: http://www.leanbackplayer.com/test/h5mt.html
|
||||||
mime(inputType) {
|
mime(input) {
|
||||||
const [mediaType] = inputType.split('/');
|
if (is.empty(input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const [mediaType] = input.split('/');
|
||||||
|
let type = input;
|
||||||
|
|
||||||
|
// Verify we're using HTML5 and there's no media type mismatch
|
||||||
if (!this.isHTML5 || mediaType !== this.type) {
|
if (!this.isHTML5 || mediaType !== this.type) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
let type;
|
// Add codec if required
|
||||||
if (inputType && inputType.includes('codecs=')) {
|
if (Object.keys(defaultCodecs).includes(type)) {
|
||||||
// Use input directly
|
type += `; codecs="${defaultCodecs[input]}"`;
|
||||||
type = inputType;
|
|
||||||
} else if (inputType === 'audio/mpeg') {
|
|
||||||
// Skip codec
|
|
||||||
type = 'audio/mpeg;';
|
|
||||||
} else if (inputType in defaultCodecs) {
|
|
||||||
// Use codec
|
|
||||||
type = `${inputType}; codecs="${defaultCodecs[inputType]}"`;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
|
return Boolean(type && this.media.canPlayType(type).replace(/no/, ''));
|
||||||
} catch (err) {
|
} catch (e) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
+31
-16
@@ -4,13 +4,13 @@
|
|||||||
|
|
||||||
import captions from './captions';
|
import captions from './captions';
|
||||||
import controls from './controls';
|
import controls from './controls';
|
||||||
import i18n from './i18n';
|
|
||||||
import support from './support';
|
import support from './support';
|
||||||
import browser from './utils/browser';
|
import browser from './utils/browser';
|
||||||
import { getElement, toggleClass } from './utils/elements';
|
import { getElement, toggleClass } from './utils/elements';
|
||||||
import { ready, triggerEvent } from './utils/events';
|
import { ready, triggerEvent } from './utils/events';
|
||||||
|
import i18n from './utils/i18n';
|
||||||
import is from './utils/is';
|
import is from './utils/is';
|
||||||
import loadImage from './utils/loadImage';
|
import loadImage from './utils/load-image';
|
||||||
|
|
||||||
const ui = {
|
const ui = {
|
||||||
addStyleHook() {
|
addStyleHook() {
|
||||||
@@ -67,15 +67,15 @@ const ui = {
|
|||||||
// Reset mute state
|
// Reset mute state
|
||||||
this.muted = null;
|
this.muted = null;
|
||||||
|
|
||||||
// Reset speed
|
|
||||||
this.speed = null;
|
|
||||||
|
|
||||||
// Reset loop state
|
// Reset loop state
|
||||||
this.loop = null;
|
this.loop = null;
|
||||||
|
|
||||||
// Reset quality setting
|
// Reset quality setting
|
||||||
this.quality = null;
|
this.quality = null;
|
||||||
|
|
||||||
|
// Reset speed
|
||||||
|
this.speed = null;
|
||||||
|
|
||||||
// Reset volume display
|
// Reset volume display
|
||||||
controls.updateVolume.call(this);
|
controls.updateVolume.call(this);
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ const ui = {
|
|||||||
|
|
||||||
// Set state
|
// Set state
|
||||||
Array.from(this.elements.buttons.play || []).forEach(target => {
|
Array.from(this.elements.buttons.play || []).forEach(target => {
|
||||||
target.pressed = this.playing;
|
Object.assign(target, { pressed: this.playing });
|
||||||
});
|
});
|
||||||
|
|
||||||
// Only update controls on non timeupdate events
|
// Only update controls on non timeupdate events
|
||||||
@@ -233,22 +233,37 @@ const ui = {
|
|||||||
clearTimeout(this.timers.loading);
|
clearTimeout(this.timers.loading);
|
||||||
|
|
||||||
// Timer to prevent flicker when seeking
|
// Timer to prevent flicker when seeking
|
||||||
this.timers.loading = setTimeout(() => {
|
this.timers.loading = setTimeout(
|
||||||
// Update progress bar loading class state
|
() => {
|
||||||
toggleClass(this.elements.container, this.config.classNames.loading, this.loading);
|
// Update progress bar loading class state
|
||||||
|
toggleClass(this.elements.container, this.config.classNames.loading, this.loading);
|
||||||
|
|
||||||
// Update controls visibility
|
// Update controls visibility
|
||||||
ui.toggleControls.call(this);
|
ui.toggleControls.call(this);
|
||||||
}, this.loading ? 250 : 0);
|
},
|
||||||
|
this.loading ? 250 : 0,
|
||||||
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// Toggle controls based on state and `force` argument
|
// Toggle controls based on state and `force` argument
|
||||||
toggleControls(force) {
|
toggleControls(force) {
|
||||||
const { controls } = this.elements;
|
const { controls: controlsElement } = this.elements;
|
||||||
|
|
||||||
if (controls && this.config.hideControls) {
|
if (controlsElement && this.config.hideControls) {
|
||||||
// Show controls if force, loading, paused, or button interaction, otherwise hide
|
// Don't hide controls if a touch-device user recently seeked. (Must be limited to touch devices, or it occasionally prevents desktop controls from hiding.)
|
||||||
this.toggleControls(Boolean(force || this.loading || this.paused || controls.pressed || controls.hover));
|
const recentTouchSeek = this.touch && this.lastSeekTime + 2000 > Date.now();
|
||||||
|
|
||||||
|
// Show controls if force, loading, paused, button interaction, or recent seek, otherwise hide
|
||||||
|
this.toggleControls(
|
||||||
|
Boolean(
|
||||||
|
force ||
|
||||||
|
this.loading ||
|
||||||
|
this.paused ||
|
||||||
|
controlsElement.pressed ||
|
||||||
|
controlsElement.hover ||
|
||||||
|
recentTouchSeek,
|
||||||
|
),
|
||||||
|
);
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,6 @@
|
|||||||
// Animation utils
|
// Animation utils
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import { toggleHidden } from './elements';
|
|
||||||
import is from './is';
|
import is from './is';
|
||||||
|
|
||||||
export const transitionEndEvent = (() => {
|
export const transitionEndEvent = (() => {
|
||||||
@@ -21,10 +20,19 @@ export const transitionEndEvent = (() => {
|
|||||||
})();
|
})();
|
||||||
|
|
||||||
// Force repaint of element
|
// Force repaint of element
|
||||||
export function repaint(element) {
|
export function repaint(element, delay) {
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
toggleHidden(element, true);
|
try {
|
||||||
element.offsetHeight; // eslint-disable-line
|
// eslint-disable-next-line no-param-reassign
|
||||||
toggleHidden(element, false);
|
element.hidden = true;
|
||||||
}, 0);
|
|
||||||
|
// eslint-disable-next-line no-unused-expressions
|
||||||
|
element.offsetHeight;
|
||||||
|
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
|
element.hidden = false;
|
||||||
|
} catch (e) {
|
||||||
|
// Do nothing
|
||||||
|
}
|
||||||
|
}, delay);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,6 +5,7 @@
|
|||||||
|
|
||||||
const browser = {
|
const browser = {
|
||||||
isIE: /* @cc_on!@ */ false || !!document.documentMode,
|
isIE: /* @cc_on!@ */ false || !!document.documentMode,
|
||||||
|
isEdge: window.navigator.userAgent.includes('Edge'),
|
||||||
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
|
isWebkit: 'WebkitAppearance' in document.documentElement.style && !/Edge/.test(navigator.userAgent),
|
||||||
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
|
isIPhone: /(iPhone|iPod)/gi.test(navigator.platform),
|
||||||
isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform),
|
isIos: /(iPad|iPhone|iPod)/gi.test(navigator.platform),
|
||||||
|
|||||||
+46
-34
@@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
import { toggleListener } from './events';
|
import { toggleListener } from './events';
|
||||||
import is from './is';
|
import is from './is';
|
||||||
|
import { extend } from './objects';
|
||||||
|
|
||||||
// Wrap an element
|
// Wrap an element
|
||||||
export function wrap(elements, wrapper) {
|
export function wrap(elements, wrapper) {
|
||||||
@@ -16,7 +17,6 @@ export function wrap(elements, wrapper) {
|
|||||||
.reverse()
|
.reverse()
|
||||||
.forEach((element, index) => {
|
.forEach((element, index) => {
|
||||||
const child = index > 0 ? wrapper.cloneNode(true) : wrapper;
|
const child = index > 0 ? wrapper.cloneNode(true) : wrapper;
|
||||||
|
|
||||||
// Cache the current parent and sibling.
|
// Cache the current parent and sibling.
|
||||||
const parent = element.parentNode;
|
const parent = element.parentNode;
|
||||||
const sibling = element.nextSibling;
|
const sibling = element.nextSibling;
|
||||||
@@ -70,12 +70,19 @@ export function createElement(type, attributes, text) {
|
|||||||
|
|
||||||
// Inaert an element after another
|
// Inaert an element after another
|
||||||
export function insertAfter(element, target) {
|
export function insertAfter(element, target) {
|
||||||
|
if (!is.element(element) || !is.element(target)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
target.parentNode.insertBefore(element, target.nextSibling);
|
target.parentNode.insertBefore(element, target.nextSibling);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Insert a DocumentFragment
|
// Insert a DocumentFragment
|
||||||
export function insertElement(type, parent, attributes, text) {
|
export function insertElement(type, parent, attributes, text) {
|
||||||
// Inject the new <element>
|
if (!is.element(parent)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
parent.appendChild(createElement(type, attributes, text));
|
parent.appendChild(createElement(type, attributes, text));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -95,6 +102,10 @@ export function removeElement(element) {
|
|||||||
|
|
||||||
// Remove all child elements
|
// Remove all child elements
|
||||||
export function emptyElement(element) {
|
export function emptyElement(element) {
|
||||||
|
if (!is.element(element)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
let { length } = element.childNodes;
|
let { length } = element.childNodes;
|
||||||
|
|
||||||
while (length > 0) {
|
while (length > 0) {
|
||||||
@@ -126,30 +137,28 @@ export function getAttributesFromSelector(sel, existingAttributes) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
const attributes = {};
|
const attributes = {};
|
||||||
const existing = existingAttributes;
|
const existing = extend({}, existingAttributes);
|
||||||
|
|
||||||
sel.split(',').forEach(s => {
|
sel.split(',').forEach(s => {
|
||||||
// Remove whitespace
|
// Remove whitespace
|
||||||
const selector = s.trim();
|
const selector = s.trim();
|
||||||
const className = selector.replace('.', '');
|
const className = selector.replace('.', '');
|
||||||
const stripped = selector.replace(/[[\]]/g, '');
|
const stripped = selector.replace(/[[\]]/g, '');
|
||||||
|
|
||||||
// Get the parts and value
|
// Get the parts and value
|
||||||
const parts = stripped.split('=');
|
const parts = stripped.split('=');
|
||||||
const key = parts[0];
|
const [key] = parts;
|
||||||
const value = parts.length > 1 ? parts[1].replace(/["']/g, '') : '';
|
const value = parts.length > 1 ? parts[1].replace(/["']/g, '') : '';
|
||||||
|
|
||||||
// Get the first character
|
// Get the first character
|
||||||
const start = selector.charAt(0);
|
const start = selector.charAt(0);
|
||||||
|
|
||||||
switch (start) {
|
switch (start) {
|
||||||
case '.':
|
case '.':
|
||||||
// Add to existing classname
|
// Add to existing classname
|
||||||
if (is.object(existing) && is.string(existing.class)) {
|
if (is.string(existing.class)) {
|
||||||
existing.class += ` ${className}`;
|
attributes.class = `${existing.class} ${className}`;
|
||||||
|
} else {
|
||||||
|
attributes.class = className;
|
||||||
}
|
}
|
||||||
|
|
||||||
attributes.class = className;
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case '#':
|
case '#':
|
||||||
@@ -168,7 +177,7 @@ export function getAttributesFromSelector(sel, existingAttributes) {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
return attributes;
|
return extend(existing, attributes);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Toggle hidden
|
// Toggle hidden
|
||||||
@@ -180,18 +189,19 @@ export function toggleHidden(element, hidden) {
|
|||||||
let hide = hidden;
|
let hide = hidden;
|
||||||
|
|
||||||
if (!is.boolean(hide)) {
|
if (!is.boolean(hide)) {
|
||||||
hide = !element.hasAttribute('hidden');
|
hide = !element.hidden;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hide) {
|
// eslint-disable-next-line no-param-reassign
|
||||||
element.setAttribute('hidden', '');
|
element.hidden = hide;
|
||||||
} else {
|
|
||||||
element.removeAttribute('hidden');
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
|
// Mirror Element.classList.toggle, with IE compatibility for "force" argument
|
||||||
export function toggleClass(element, className, force) {
|
export function toggleClass(element, className, force) {
|
||||||
|
if (is.nodeList(element)) {
|
||||||
|
return Array.from(element).map(e => toggleClass(e, className, force));
|
||||||
|
}
|
||||||
|
|
||||||
if (is.element(element)) {
|
if (is.element(element)) {
|
||||||
let method = 'toggle';
|
let method = 'toggle';
|
||||||
if (typeof force !== 'undefined') {
|
if (typeof force !== 'undefined') {
|
||||||
@@ -202,7 +212,7 @@ export function toggleClass(element, className, force) {
|
|||||||
return element.classList.contains(className);
|
return element.classList.contains(className);
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Has class name
|
// Has class name
|
||||||
@@ -218,14 +228,14 @@ export function matches(element, selector) {
|
|||||||
return Array.from(document.querySelectorAll(selector)).includes(this);
|
return Array.from(document.querySelectorAll(selector)).includes(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matches =
|
const method =
|
||||||
prototype.matches ||
|
prototype.matches ||
|
||||||
prototype.webkitMatchesSelector ||
|
prototype.webkitMatchesSelector ||
|
||||||
prototype.mozMatchesSelector ||
|
prototype.mozMatchesSelector ||
|
||||||
prototype.msMatchesSelector ||
|
prototype.msMatchesSelector ||
|
||||||
match;
|
match;
|
||||||
|
|
||||||
return matches.call(element, selector);
|
return method.call(element, selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Find all elements
|
// Find all elements
|
||||||
@@ -238,19 +248,6 @@ export function getElement(selector) {
|
|||||||
return this.elements.container.querySelector(selector);
|
return this.elements.container.querySelector(selector);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the focused element
|
|
||||||
export function getFocusElement() {
|
|
||||||
let focused = document.activeElement;
|
|
||||||
|
|
||||||
if (!focused || focused === document.body) {
|
|
||||||
focused = null;
|
|
||||||
} else {
|
|
||||||
focused = document.querySelector(':focus');
|
|
||||||
}
|
|
||||||
|
|
||||||
return focused;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Trap focus inside container
|
// Trap focus inside container
|
||||||
export function trapFocus(element = null, toggle = false) {
|
export function trapFocus(element = null, toggle = false) {
|
||||||
if (!is.element(element)) {
|
if (!is.element(element)) {
|
||||||
@@ -268,7 +265,7 @@ export function trapFocus(element = null, toggle = false) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Get the current focused element
|
// Get the current focused element
|
||||||
const focused = getFocusElement();
|
const focused = document.activeElement;
|
||||||
|
|
||||||
if (focused === last && !event.shiftKey) {
|
if (focused === last && !event.shiftKey) {
|
||||||
// Move focus to first element that can be tabbed if Shift isn't used
|
// Move focus to first element that can be tabbed if Shift isn't used
|
||||||
@@ -283,3 +280,18 @@ export function trapFocus(element = null, toggle = false) {
|
|||||||
|
|
||||||
toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false);
|
toggleListener.call(this, this.elements.container, 'keydown', trap, toggle, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Set focus and tab focus class
|
||||||
|
export function setFocus(element = null, tabFocus = false) {
|
||||||
|
if (!is.element(element)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set regular focus
|
||||||
|
element.focus({ preventScroll: true });
|
||||||
|
|
||||||
|
// If we want to mimic keyboard focus via tab
|
||||||
|
if (tabFocus) {
|
||||||
|
toggleClass(element, this.config.classNames.tabFocus);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -35,7 +35,6 @@ export function toggleListener(element, event, callback, toggle = false, passive
|
|||||||
|
|
||||||
// Allow multiple events
|
// Allow multiple events
|
||||||
const events = event.split(' ');
|
const events = event.split(' ');
|
||||||
|
|
||||||
// Build options
|
// Build options
|
||||||
// Default to just the capture boolean for browsers with no passive listener support
|
// Default to just the capture boolean for browsers with no passive listener support
|
||||||
let options = capture;
|
let options = capture;
|
||||||
@@ -73,10 +72,10 @@ export function off(element, events = '', callback, passive = true, capture = fa
|
|||||||
|
|
||||||
// Bind once-only event handler
|
// Bind once-only event handler
|
||||||
export function once(element, events = '', callback, passive = true, capture = false) {
|
export function once(element, events = '', callback, passive = true, capture = false) {
|
||||||
function onceCallback(...args) {
|
const onceCallback = (...args) => {
|
||||||
off(element, events, onceCallback, passive, capture);
|
off(element, events, onceCallback, passive, capture);
|
||||||
callback.apply(this, args);
|
callback.apply(this, args);
|
||||||
}
|
};
|
||||||
|
|
||||||
toggleListener.call(this, element, events, onceCallback, true, passive, capture);
|
toggleListener.call(this, element, events, onceCallback, true, passive, capture);
|
||||||
}
|
}
|
||||||
@@ -114,7 +113,7 @@ export function unbindListeners() {
|
|||||||
|
|
||||||
// Run method when / if player is ready
|
// Run method when / if player is ready
|
||||||
export function ready() {
|
export function ready() {
|
||||||
return new Promise(
|
return new Promise(resolve =>
|
||||||
resolve => (this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve)),
|
this.ready ? setTimeout(resolve, 0) : on.call(this, this.elements.container, 'ready', resolve),
|
||||||
).then(() => {});
|
).then(() => {});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,9 +2,18 @@
|
|||||||
// Plyr internationalization
|
// Plyr internationalization
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import is from './utils/is';
|
import is from './is';
|
||||||
import { getDeep } from './utils/objects';
|
import { getDeep } from './objects';
|
||||||
import { replaceAll } from './utils/strings';
|
import { replaceAll } from './strings';
|
||||||
|
|
||||||
|
// Skip i18n for abbreviations and brand names
|
||||||
|
const resources = {
|
||||||
|
pip: 'PIP',
|
||||||
|
airplay: 'AirPlay',
|
||||||
|
html5: 'HTML5',
|
||||||
|
vimeo: 'Vimeo',
|
||||||
|
youtube: 'YouTube',
|
||||||
|
};
|
||||||
|
|
||||||
const i18n = {
|
const i18n = {
|
||||||
get(key = '', config = {}) {
|
get(key = '', config = {}) {
|
||||||
@@ -15,6 +24,10 @@ const i18n = {
|
|||||||
let string = getDeep(config.i18n, key);
|
let string = getDeep(config.i18n, key);
|
||||||
|
|
||||||
if (is.empty(string)) {
|
if (is.empty(string)) {
|
||||||
|
if (Object.keys(resources).includes(key)) {
|
||||||
|
return resources[key];
|
||||||
|
}
|
||||||
|
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,8 +36,8 @@ const i18n = {
|
|||||||
'{title}': config.title,
|
'{title}': config.title,
|
||||||
};
|
};
|
||||||
|
|
||||||
Object.entries(replace).forEach(([key, value]) => {
|
Object.entries(replace).forEach(([k, v]) => {
|
||||||
string = replaceAll(string, key, value);
|
string = replaceAll(string, k, v);
|
||||||
});
|
});
|
||||||
|
|
||||||
return string;
|
return string;
|
||||||
@@ -16,8 +16,10 @@ const isNodeList = input => instanceOf(input, NodeList);
|
|||||||
const isElement = input => instanceOf(input, Element);
|
const isElement = input => instanceOf(input, Element);
|
||||||
const isTextNode = input => getConstructor(input) === Text;
|
const isTextNode = input => getConstructor(input) === Text;
|
||||||
const isEvent = input => instanceOf(input, Event);
|
const isEvent = input => instanceOf(input, Event);
|
||||||
|
const isKeyboardEvent = input => instanceOf(input, KeyboardEvent);
|
||||||
const isCue = input => instanceOf(input, window.TextTrackCue) || instanceOf(input, window.VTTCue);
|
const isCue = input => instanceOf(input, window.TextTrackCue) || instanceOf(input, window.VTTCue);
|
||||||
const isTrack = input => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind));
|
const isTrack = input => instanceOf(input, TextTrack) || (!isNullOrUndefined(input) && isString(input.kind));
|
||||||
|
const isPromise = input => instanceOf(input, Promise);
|
||||||
|
|
||||||
const isEmpty = input =>
|
const isEmpty = input =>
|
||||||
isNullOrUndefined(input) ||
|
isNullOrUndefined(input) ||
|
||||||
@@ -30,6 +32,11 @@ const isUrl = input => {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Must be string from here
|
||||||
|
if (!isString(input)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Add the protocol if required
|
// Add the protocol if required
|
||||||
let string = input;
|
let string = input;
|
||||||
if (!input.startsWith('http://') || !input.startsWith('https://')) {
|
if (!input.startsWith('http://') || !input.startsWith('https://')) {
|
||||||
@@ -56,8 +63,10 @@ export default {
|
|||||||
element: isElement,
|
element: isElement,
|
||||||
textNode: isTextNode,
|
textNode: isTextNode,
|
||||||
event: isEvent,
|
event: isEvent,
|
||||||
|
keyboardEvent: isKeyboardEvent,
|
||||||
cue: isCue,
|
cue: isCue,
|
||||||
track: isTrack,
|
track: isTrack,
|
||||||
|
promise: isPromise,
|
||||||
url: isUrl,
|
url: isUrl,
|
||||||
empty: isEmpty,
|
empty: isEmpty,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -2,7 +2,7 @@
|
|||||||
// Sprite loader
|
// Sprite loader
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
|
||||||
import Storage from './../storage';
|
import Storage from '../storage';
|
||||||
import fetch from './fetch';
|
import fetch from './fetch';
|
||||||
import is from './is';
|
import is from './is';
|
||||||
|
|
||||||
@@ -15,10 +15,10 @@ export default function loadSprite(url, id) {
|
|||||||
const prefix = 'cache';
|
const prefix = 'cache';
|
||||||
const hasId = is.string(id);
|
const hasId = is.string(id);
|
||||||
let isCached = false;
|
let isCached = false;
|
||||||
|
|
||||||
const exists = () => document.getElementById(id) !== null;
|
const exists = () => document.getElementById(id) !== null;
|
||||||
|
|
||||||
const update = (container, data) => {
|
const update = (container, data) => {
|
||||||
|
// eslint-disable-next-line no-param-reassign
|
||||||
container.innerHTML = data;
|
container.innerHTML = data;
|
||||||
|
|
||||||
// Check again incase of race condition
|
// Check again incase of race condition
|
||||||
@@ -33,7 +33,6 @@ export default function loadSprite(url, id) {
|
|||||||
// Only load once if ID set
|
// Only load once if ID set
|
||||||
if (!hasId || !exists()) {
|
if (!hasId || !exists()) {
|
||||||
const useStorage = Storage.supported;
|
const useStorage = Storage.supported;
|
||||||
|
|
||||||
// Create container
|
// Create container
|
||||||
const container = document.createElement('div');
|
const container = document.createElement('div');
|
||||||
container.setAttribute('hidden', '');
|
container.setAttribute('hidden', '');
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user