-
Notifications
You must be signed in to change notification settings - Fork 26
feat: lazy-loading player #1017
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
364925d
feat: lazy-loading player
tsi 1ab0150
Merge branch 'master' into VIDEO-18457-lazy-player
tsi 9c2431a
chore: examples
tsi f752696
Merge branch 'VIDEO-18457-lazy-player' of https://github.com/cloudina…
tsi 86148e2
chore: improve bundle size
tsi 46768c3
chore: e2e
tsi 494af4a
chore: e2e
tsi 6ceccbf
chore: e2e
tsi 8b7727f
Merge branch 'master' into VIDEO-18457-lazy-player
tsi 8dbee25
fix: getCloudinaryConfigFromOptions
tsi cd9aec3
chore: naming
tsi 69c3b42
chore: examples
tsi 455f4de
chore: lazy posters
tsi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,119 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8" /> | ||
| <title>Cloudinary Video Player - Lazy player (ESM)</title> | ||
| <link | ||
| href="https://res.cloudinary.com/cloudinary-marketing/image/upload/f_auto,q_auto/c_scale,w_32,e_hue:290/creative_staging/cloudinary_internal/Website/Brand%20Updates/Favicon/cloudinary_web_favicon_192x192.png" | ||
| rel="icon" | ||
| type="image/png" | ||
| /> | ||
| <link rel="icon" type="image/svg+xml" href="/vite.svg" /> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> | ||
| </head> | ||
| <body> | ||
| <div class="container p-4 col-12 col-md-9 col-xl-6"> | ||
| <nav class="nav mb-2"> | ||
| <a href="/index.html"><< Back to examples index</a> | ||
| </nav> | ||
| <h1>Cloudinary Video Player</h1> | ||
| <h3 class="mb-3">Lazy player (with poster URL)</h3> | ||
| <p class="text-muted small mb-2">Uses an explicit <code>poster</code> URL. Custom accent color and logo configured.</p> | ||
|
|
||
| <video | ||
| id="player" | ||
| playsinline | ||
| controls | ||
| muted | ||
| class="cld-video-player cld-fluid" | ||
| width="500" | ||
| ></video> | ||
|
|
||
| <button type="button" id="btn-load" class="btn btn-sm btn-outline-primary mt-2 mb-3">Load Player</button> | ||
| <p class="text-muted small mb-3"> | ||
| Click the player or the button above to initialize. The button calls <code>player.loadPlayer()</code>. | ||
| </p> | ||
|
|
||
| <h3 class="mt-4">Scroll to load (auto-built poster)</h3> | ||
| <p class="text-muted small mb-2">No <code>poster</code> URL - built automatically from <code>cloudName</code> and <code>publicId</code>. Custom colors configured.</p> | ||
| <p class="text-muted small mb-3"> | ||
| Scroll down - the player loads automatically when it enters the viewport. | ||
| </p> | ||
|
|
||
| <div style="height: 80vh; display: flex; color: #aaa; font-size: 2rem;"> | ||
| ↓ ↓ ↓ ↓ ↓ ↓ ↓ | ||
| </div> | ||
|
|
||
| <video | ||
| id="player-scroll" | ||
| playsinline | ||
| controls | ||
| muted | ||
| loop | ||
| class="cld-video-player cld-fluid" | ||
| width="500" | ||
| ></video> | ||
|
|
||
| <h3 class="mt-4">Example code:</h3> | ||
| <pre><code class="language-javascript"> | ||
| import { player as createPlayer } from 'cloudinary-video-player/lazy'; | ||
| import 'cloudinary-video-player/cld-video-player.min.css'; | ||
|
|
||
| // With explicit poster URL | ||
| const player = await createPlayer('my-video', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| poster: 'https://res.cloudinary.com/demo/video/upload/so_0,f_auto,q_auto/sea_turtle.jpg', | ||
| lazy: true, | ||
| colors: { accent: '#ff4081' } | ||
| }); | ||
| // await player.loadPlayer(); | ||
|
|
||
| // Auto-built poster from cloudName + publicId | ||
| createPlayer('my-video', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| lazy: { loadOnScroll: true }, | ||
| colors: { base: '#0d1b2a', accent: '#00b4d8' } | ||
| }); | ||
| </code></pre> | ||
| </div> | ||
|
|
||
| <script type="module"> | ||
| import { player as createPlayer } from 'cloudinary-video-player/lazy'; | ||
| import 'cloudinary-video-player/cld-video-player.min.css'; | ||
|
|
||
| (async () => { | ||
| const player = await createPlayer('player', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| poster: 'https://res.cloudinary.com/demo/video/upload/so_0,f_auto,q_auto/sea_turtle.jpg', | ||
| lazy: true, | ||
| colors: { accent: '#ff4081' }, | ||
| logoImageUrl: 'https://res.cloudinary.com/demo/image/upload/c_scale,w_100/cloudinary_logo.png', | ||
| logoOnclickUrl: 'https://cloudinary.com' | ||
| }); | ||
|
|
||
| document.getElementById('btn-load').addEventListener('click', () => { | ||
| if (player && typeof player.loadPlayer === 'function') { | ||
| player.loadPlayer(); | ||
| } | ||
| }); | ||
|
|
||
| createPlayer('player-scroll', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| lazy: { loadOnScroll: true }, | ||
| colors: { base: '#0d1b2a', accent: '#00b4d8' } | ||
| }); | ||
| })(); | ||
| </script> | ||
|
|
||
| <link | ||
| href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" | ||
| rel="stylesheet" | ||
| integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" | ||
| crossorigin="anonymous" | ||
| /> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,120 @@ | ||
| <!DOCTYPE html> | ||
| <html lang="en"> | ||
| <head> | ||
| <meta charset="utf-8"> | ||
| <meta name="viewport" content="width=device-width, initial-scale=1" /> | ||
| <title>Cloudinary Video Player - Lazy player</title> | ||
| <link href="https://res.cloudinary.com/cloudinary-marketing/image/upload/f_auto,q_auto/c_scale,w_32/v1597183771/creative_staging/cloudinary_internal/Website/Brand%20Updates/Favicon/cloudinary_web_favicon_192x192.png" rel="icon" type="image/png"> | ||
|
|
||
| <!-- Bootstrap --> | ||
| <link href="https://stackpath.bootstrapcdn.com/bootstrap/4.3.1/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-ggOyR0iXCbMQv3Xipma34MD+dH/1fQ784/j6cY/iJTQUOhcWr7x9JvoRxT2MZw1T" crossorigin="anonymous"> | ||
|
|
||
| <!-- highlight.js --> | ||
| <link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/styles/solarized-light.min.css"> | ||
| <script src="//cdnjs.cloudflare.com/ajax/libs/highlight.js/9.12.0/highlight.min.js"></script> | ||
| <script>hljs.initHighlightingOnLoad();</script> | ||
|
|
||
| <script type="text/javascript" src="./scripts.js?lazy"></script> | ||
|
|
||
| <script type="text/javascript"> | ||
| (function () { | ||
| var player = null; | ||
|
|
||
| async function initLazyPlayer() { | ||
| player = await cloudinary.player('player', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| poster: 'https://res.cloudinary.com/demo/video/upload/so_0,f_auto,q_auto/sea_turtle.jpg', | ||
| lazy: true, | ||
| colors: { accent: '#ff4081' }, | ||
| logoImageUrl: 'https://res.cloudinary.com/demo/image/upload/c_scale,w_100/cloudinary_logo.png', | ||
| logoOnclickUrl: 'https://cloudinary.com' | ||
| }); | ||
|
|
||
| cloudinary.player('player-scroll', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| lazy: { loadOnScroll: true }, | ||
| colors: { accent: '#ff4081' } | ||
| }); | ||
| } | ||
|
|
||
| window.addEventListener('load', function () { | ||
| initLazyPlayer(); | ||
| document.getElementById('btn-load').addEventListener('click', function () { | ||
| if (player && typeof player.loadPlayer === 'function') { | ||
| player.loadPlayer(); | ||
| } | ||
| }); | ||
| }); | ||
| })(); | ||
| </script> | ||
| </head> | ||
| <body> | ||
| <div class="container p-4 col-12 col-md-9 col-xl-6"> | ||
| <nav class="nav mb-2"> | ||
| <a href="./index.html"><< Back to examples index</a> | ||
| </nav> | ||
| <h1>Cloudinary Video Player</h1> | ||
| <h3 class="mb-3">Lazy player (with poster URL)</h3> | ||
| <p class="text-muted small mb-2">Uses an explicit <code>poster</code> URL. Custom accent color and logo configured.</p> | ||
|
|
||
| <video | ||
| id="player" | ||
| playsinline | ||
| controls | ||
| muted | ||
| class="cld-video-player cld-fluid" | ||
| width="500"> | ||
| </video> | ||
|
|
||
| <button type="button" id="btn-load" class="btn btn-sm btn-outline-primary mt-2 mb-3">Load Player</button> | ||
| <p class="text-muted small mb-3"> | ||
| Click the player or the button above to initialize. The button calls <code>player.loadPlayer()</code>. | ||
| </p> | ||
|
|
||
| <h3 class="mt-4">Scroll to load (auto-built poster)</h3> | ||
| <p class="text-muted small mb-2">No <code>poster</code> URL - built automatically from <code>cloudName</code> and <code>publicId</code>. Custom colors configured.</p> | ||
| <p class="text-muted small mb-3"> | ||
| Scroll down - the player loads automatically when it enters the viewport. | ||
| </p> | ||
|
|
||
| <div style="height: 80vh; display: flex; color: #aaa; font-size: 2rem;"> | ||
| ↓ ↓ ↓ ↓ ↓ ↓ ↓ | ||
| </div> | ||
|
|
||
| <video | ||
| id="player-scroll" | ||
| playsinline | ||
| controls | ||
| muted | ||
| loop | ||
| class="cld-video-player cld-fluid" | ||
| width="500"> | ||
| </video> | ||
|
|
||
| <h3 class="mt-4">Example code:</h3> | ||
| <pre> | ||
| <code class="language-javascript"> | ||
| // With explicit poster URL | ||
| const player = await cloudinary.player('my-video', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| poster: 'https://res.cloudinary.com/demo/video/upload/so_0,f_auto,q_auto/sea_turtle.jpg', | ||
| lazy: true, | ||
| colors: { accent: '#ff4081' } | ||
| }); | ||
| // await player.loadPlayer(); | ||
|
|
||
| // Auto-built poster from cloudName + publicId | ||
| cloudinary.player('my-video', { | ||
| cloudName: 'demo', | ||
| publicId: 'sea_turtle', | ||
| lazy: { loadOnScroll: true }, | ||
| colors: { base: '#0d1b2a', accent: '#00b4d8' } | ||
| }); | ||
| </code> | ||
| </pre> | ||
| </div> | ||
| </body> | ||
| </html> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| import pick from 'lodash/pick'; | ||
| import { CLOUDINARY_CONFIG_PARAM } from '../video-player.const'; | ||
| import { convertKeysToSnakeCase } from './object'; | ||
|
|
||
| export const getCloudinaryConfigFromOptions = (options) => { | ||
| if (options.cloudinaryConfig) { | ||
| return options.cloudinaryConfig; | ||
| } | ||
|
|
||
| const snakeCaseCloudinaryConfig = pick(convertKeysToSnakeCase(options), CLOUDINARY_CONFIG_PARAM); | ||
| return Object.assign({}, snakeCaseCloudinaryConfig); | ||
| }; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.