This is a generic media viewer/player web component originally designed to display Cardano NFTs.
It supports the following media:
- Images
- Videos
- Audio files
- Web documents (HTML/Javascript/Css)
- PDF and plain text documents
- 3D models
And features:
- IPFS & Arweave URLs support (including gateway setting)
- Data URLs support (for example used in on-chain NFTs)
- Follows the open-wc recommendation
npm i nftcdn-media-player
<script type="module">
import 'nftcdn-media-player/nftcdn-media-player.js';
</script>
<nftcdn-media-player src="URL" type="MIME" name="NAME"></nftcdn-media-player>
Name | Requirement | Default | Description |
---|---|---|---|
src |
mandatory | undefined | media URL |
type |
mandatory except for images | undefined | media/mime type |
name |
required for WCAG compliance | undefined | unique media name |
ipfsgateway * |
optional | https://ipfs.io | IPFS gateway |
argateway * |
optional | https://arweave.net | Arweave gateway |
autoplay |
optional | true | Play automatically. Supported by audio and video media. Implies muted when enabled for videos. |
* JavaScript properties are ipfsGateway
and arGateway
.
image/*
:<img>
element browsers supported formatsvideo/*
:<video>
element browsers supported formatsaudio/*
:<audio>
element browsers supported formatstext/html
: HTML/Javascript/Css versions supported by browsersapplication/pdf
: using browsers native PDF viewertext/plain
model/gltf+json, model/gltf-binary
: versions supported by<model-viewer>
The following underlying elements are used:
Type | Element |
---|---|
image | <img> |
video | <video> |
audio | <audio> |
html | <iframe> |
<object> |
|
text | <object> |
gltf | <model-viewer> |
The following events are supported by the <nftcdn-media-playezr>
custom element when the underlying element used supports them:
Event | Description |
---|---|
load | Fires when the media has successfully loaded. |
error | Fires when the media failed to load. |
The original event from the underlying element is stored in the custom event detail
property.
Example:
<nftcdn-media-player
src="ipfs://bafybeidnye5ohaqjliyriep2huapmgfgzuo7zlaeqe3rv6dxvu5yb46igm"
onload="console.log('loaded', event.detail)"
onerror="console.log('error', event.detail)"
></nftcdn-media-player>
All the component parts can be styled using CSS ::part
pseudo element:
Type | CSS Selector |
---|---|
image | nftcdn-media-player::part(img) |
video | nftcdn-media-player::part(video) |
audio | nftcdn-media-player::part(audio) |
html | nftcdn-media-player::part(iframe) |
nftcdn-media-player[type="application/pdf"]::part(object) | |
text | nftcdn-media-player[type="text/plain"]::part(object) |
gltf | nftcdn-media-player::part(model-viewer) |
For example, to change the way images fill the viewer container:
<style>
nftcdn-media-player::part(img) {
object-fit: fill;
}
</style>
The Storybook is build on commits with GitHub Actions and published online to GitHub Pages:
https://nftcdn.github.io/media-player
To run a local instance of the Storybook, run
npm run storybook
To build a production version of Storybook, run
npm run storybook:build
npm start
To run a local development server that serves the basic demo located in demo/index.html
To scan the project for linting and formatting errors, run
npm run lint
To automatically fix linting and formatting errors, run
npm run format
To execute a single test run:
npm run test
To run the tests in interactive watch mode run:
npm run test:watch
Pull requests must maintain 100% code coverage.