-
Notifications
You must be signed in to change notification settings - Fork 86
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add media-error-dialog (#1024)
https://media-chrome-git-fork-luwes-error-dialog-mux.vercel.app/examples/vanilla/control-elements/media-error-dialog.html use of `<media-chrome-dialog>` here: https://media-chrome-git-fork-luwes-error-dialog-mux.vercel.app/examples/vanilla/control-elements/media-settings-menu.html - Simplified the media-chrome-dialog removing many CSS vars that are not essential. - Format the error message by overriding `MediaErrorDialog.formatErrorMessage(error)` - Change the error message via slots ```html <media-error-dialog mediaerrorcode="2"> <div slot="error-2">This is a custom message</div> </media-error-dialog> ``` - Supports custom media elements errors with any code and message. - Built with React SSR compatible `getTemplateHTML` static methods (could be nice to start working towards this) --------- Co-authored-by: Christian Pillsbury <cjpillsbury@gmail.com>
- Loading branch information
1 parent
0c161f4
commit 3fc95a2
Showing
19 changed files
with
620 additions
and
198 deletions.
There are no files selected for viewing
121 changes: 121 additions & 0 deletions
121
examples/vanilla/control-elements/media-error-dialog.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,121 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta name="viewport" content="width=device-width" /> | ||
<title>Media Error Dialog</title> | ||
<script type="module" src="../../../dist/index.js"></script> | ||
<script type="module"> | ||
import { CustomVideoElement } from 'https://cdn.jsdelivr.net/npm/custom-media-element/+esm'; | ||
|
||
class CustomVideo extends CustomVideoElement { | ||
#error; | ||
|
||
get error() { | ||
return this.#error ?? super.error; | ||
} | ||
|
||
set error(value) { | ||
this.#error = value; | ||
} | ||
} | ||
|
||
globalThis.customElements.define('custom-video', CustomVideo); | ||
</script> | ||
|
||
<style> | ||
h2 { | ||
margin-top: 2rem; | ||
} | ||
|
||
/** add styles to prevent CLS (Cumulative Layout Shift) */ | ||
media-controller:not([audio]) { | ||
display: grid; /* expands the container if preload=none */ | ||
max-width: 540px; /* allows the container to shrink if small */ | ||
aspect-ratio: 16 / 9; /* set container aspect ratio if preload=none */ | ||
} | ||
|
||
video, | ||
img[slot="poster"] { | ||
grid-area: 1 / 1; /* position poster img on top of video element */ | ||
width: 100%; /* prevents video to expand beyond its container */ | ||
} | ||
|
||
.examples { | ||
margin-top: 20px; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<h1>MediaErrorDialog</h1> | ||
|
||
<h2>Non existing mp4</h2> | ||
|
||
<media-controller defaultsubtitles> | ||
<custom-video | ||
slot="media" | ||
src="https://stream.mux.com/Sc89iWAyNkhJ3P1rQ02nrEdCFTnfT01CZ2KmaEcxXfB00/low.mp4" | ||
muted | ||
crossorigin | ||
></custom-video> | ||
<img slot="poster" src="https://image.mux.com/Sc89iWAyNkhJ3P1rQ02nrEdCFTnfT01CZ2KmaEcxXfB008/thumbnail.webp?time=13" /> | ||
<media-loading-indicator slot="centered-chrome" noautohide></media-loading-indicator> | ||
<media-error-dialog slot="dialog"></media-error-dialog> | ||
<media-control-bar> | ||
<media-play-button></media-play-button> | ||
<media-mute-button></media-mute-button> | ||
<media-time-range></media-time-range> | ||
<media-time-display></media-time-display> | ||
<media-fullscreen-button></media-fullscreen-button> | ||
</media-control-bar> | ||
</media-controller> | ||
|
||
<h2>Custom error code for custom media elements</h2> | ||
<script> | ||
function setError() { | ||
const video = document.querySelector('custom-video'); | ||
const customError = new Error('This is a custom error with code 42!'); | ||
customError.code = 42; | ||
video.error = customError; | ||
video.dispatchEvent(new Event('error')); | ||
} | ||
</script> | ||
<button onclick="setError()">Set error code 42</button> | ||
|
||
<div style="max-width: 540px"> | ||
<h2>Error 2 (MEDIA_ERR_NETWORK)</h2> | ||
<media-error-dialog mediaerrorcode="2"></media-error-dialog> | ||
|
||
<h2>Error 3 (MEDIA_ERR_DECODE)</h2> | ||
<media-error-dialog mediaerrorcode="3"></media-error-dialog> | ||
|
||
<h2>Error 4 (MEDIA_ERR_SRC_NOT_SUPPORTED)</h2> | ||
<media-error-dialog mediaerrorcode="4"></media-error-dialog> | ||
|
||
<h2>Error 5 (MEDIA_ERR_ENCRYPTED)</h2> | ||
<media-error-dialog mediaerrorcode="5"></media-error-dialog> | ||
|
||
<h2>Error 2 with custom error content via <code>error-2</code> slot</h2> | ||
<media-error-dialog mediaerrorcode="2"> | ||
<h3 slot="error-2">Custom Error 2</h3> | ||
<p slot="error-2">This is a custom message</p> | ||
</media-error-dialog> | ||
|
||
<h2>Error 2 with custom error title via <code>error-2-title</code> slot</h2> | ||
<media-error-dialog mediaerrorcode="2"> | ||
<h3 slot="error-2-title">Custom Error 2 Title</h3> | ||
</media-error-dialog> | ||
|
||
<h2>Error 2 with custom error message via <code>error-2-message</code> slot</h2> | ||
<media-error-dialog mediaerrorcode="2"> | ||
<p slot="error-2-message">This is a custom message</p> | ||
</media-error-dialog> | ||
|
||
</div> | ||
|
||
<br> | ||
|
||
<div class="examples"> | ||
<a href="../">View more examples</a> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.