* force fullscreen events to trigger on plyr element (media element in iOS) and not fullscreen container * Fixing "missing code in detail" for PlyrEvent type When using typescript and listening for youtube statechange event, it is missing the code property definition inside the event (even though it is provided in the code). By making events a map of key-value, we can add easily custom event type for specific event name. Since YouTube "statechange" event differs from the basic PlyrEvent, I added a new Event Type "PlyrStateChangeEvent" having a code property corresponding to a YoutubeState enum defined by the YouTube API documentation. This pattern follows how addEventListener in the lib.dom.d.ts is defined. * Update link to working dash.js demo (was broken) * Fix PreviewThumbnailsOptions type According to the docs, the `src` should also accept an array of strings. * fix issue #1872 * Check if key is a string before attempt --plyr checking * Fix for Slow loading videos not autoplaying * Fix for Slow loading videos not autoplaying * Network requests are not cancelled after the player is destroyed * Fix for apect ratio problem when using Vimeo player on mobile devices (issue #1940) * chore: update packages and linting * Invoke custom listener on triggering fullscreen via double-click * Fix volume when unmuting from volume 0 * adding a nice Svelte plugin that I found * Add missing unit to calc in media query * Assigning player's lastSeekTime on rewind/fast forward to prevent immediate controls hide on mobile * Fix youtube not working when player is inside shadow dom * v3.6.2 * ESLint to use common config * add BitChute to users list * Fix aspect ratio issue * Revert noCookie change * feat: demo radius tweaks * fix: poster image shouldn’t receive click events * chore: package updates * chore: linting * feat: custom controls option for embedded players * Package upgrades * ESLint to use common config * Linting changes * Update README.md * chore: formatting * fix: revert pointer events change for poster * fix: hack for Safari 14 not repainting Vimeo embed on entering fullscreen * fix: demo using custom controls for YouTube * doc: Add STROLLÿN among the list of Plyr users * Fixes #2005 * fix: overflowing volume slider * chore: clean up CSS * fix: hide poster when not using custom controls * Package upgrades * ESLint to use common config * Linting changes * chore: revert customControls default option (to prevent breaking change) * docs: changelog for v3.6.3 Co-authored-by: Som Meaden <som@theprojectsomething.com> Co-authored-by: akuma06 <demon.akuma06@gmail.com> Co-authored-by: Jonathan Arbely <dev@jonathanarbely.de> Co-authored-by: Takeshi <iwatakeshi@users.noreply.github.com> Co-authored-by: Hex <hex@codeigniter.org.cn> Co-authored-by: Syed Husain <syed.husain@appspace.com> Co-authored-by: Danielh112 <Daniel@sbgsportssoftware.com> Co-authored-by: Danil Stoyanov <d.stoyanov@corp.mail.ru> Co-authored-by: Guru Prasad Srinivasa <gurupras@buffalo.edu> Co-authored-by: Stephane Fortin Bouchard <stephane.f.bouchard@gmail.com> Co-authored-by: Zev Averbach <zev@averba.ch> Co-authored-by: Vincent Orback <hello@vincentorback.se> Co-authored-by: trafium <trafium@gmail.com> Co-authored-by: xansen <27698939+xansen@users.noreply.github.com> Co-authored-by: zoomerdev <59863739+zoomerdev@users.noreply.github.com> Co-authored-by: Mikaël Castellani <mikael.castellani@gmail.com> Co-authored-by: dirkjf <d.j.faber@outlook.com>
159 lines
4.6 KiB
JavaScript
159 lines
4.6 KiB
JavaScript
// ==========================================================================
|
|
// Plyr source update
|
|
// ==========================================================================
|
|
|
|
import { providers } from './config/types';
|
|
import html5 from './html5';
|
|
import media from './media';
|
|
import PreviewThumbnails from './plugins/preview-thumbnails';
|
|
import support from './support';
|
|
import ui from './ui';
|
|
import { createElement, insertElement, removeElement } from './utils/elements';
|
|
import is from './utils/is';
|
|
import { getDeep } from './utils/objects';
|
|
|
|
const source = {
|
|
// Add elements to HTML5 media (source, tracks, etc)
|
|
insertElements(type, attributes) {
|
|
if (is.string(attributes)) {
|
|
insertElement(type, this.media, {
|
|
src: attributes,
|
|
});
|
|
} else if (is.array(attributes)) {
|
|
attributes.forEach((attribute) => {
|
|
insertElement(type, this.media, attribute);
|
|
});
|
|
}
|
|
},
|
|
|
|
// Update source
|
|
// Sources are not checked for support so be careful
|
|
change(input) {
|
|
if (!getDeep(input, 'sources.length')) {
|
|
this.debug.warn('Invalid source format');
|
|
return;
|
|
}
|
|
|
|
// Cancel current network requests
|
|
html5.cancelRequests.call(this);
|
|
|
|
// Destroy instance and re-setup
|
|
this.destroy.call(
|
|
this,
|
|
() => {
|
|
// Reset quality options
|
|
this.options.quality = [];
|
|
|
|
// Remove elements
|
|
removeElement(this.media);
|
|
this.media = null;
|
|
|
|
// Reset class name
|
|
if (is.element(this.elements.container)) {
|
|
this.elements.container.removeAttribute('class');
|
|
}
|
|
|
|
// Set the type and provider
|
|
const { sources, type } = input;
|
|
const [{ provider = providers.html5, src }] = sources;
|
|
const tagName = provider === 'html5' ? type : 'div';
|
|
const attributes = provider === 'html5' ? {} : { src };
|
|
|
|
Object.assign(this, {
|
|
provider,
|
|
type,
|
|
// Check for support
|
|
supported: support.check(type, provider, this.config.playsinline),
|
|
// Create new element
|
|
media: createElement(tagName, attributes),
|
|
});
|
|
|
|
// Inject the new element
|
|
this.elements.container.appendChild(this.media);
|
|
|
|
// Autoplay the new source?
|
|
if (is.boolean(input.autoplay)) {
|
|
this.config.autoplay = input.autoplay;
|
|
}
|
|
|
|
// Set attributes for audio and video
|
|
if (this.isHTML5) {
|
|
if (this.config.crossorigin) {
|
|
this.media.setAttribute('crossorigin', '');
|
|
}
|
|
if (this.config.autoplay) {
|
|
this.media.setAttribute('autoplay', '');
|
|
}
|
|
if (!is.empty(input.poster)) {
|
|
this.poster = input.poster;
|
|
}
|
|
if (this.config.loop.active) {
|
|
this.media.setAttribute('loop', '');
|
|
}
|
|
if (this.config.muted) {
|
|
this.media.setAttribute('muted', '');
|
|
}
|
|
if (this.config.playsinline) {
|
|
this.media.setAttribute('playsinline', '');
|
|
}
|
|
}
|
|
|
|
// Restore class hook
|
|
ui.addStyleHook.call(this);
|
|
|
|
// Set new sources for html5
|
|
if (this.isHTML5) {
|
|
source.insertElements.call(this, 'source', sources);
|
|
}
|
|
|
|
// Set video title
|
|
this.config.title = input.title;
|
|
|
|
// Set up from scratch
|
|
media.setup.call(this);
|
|
|
|
// HTML5 stuff
|
|
if (this.isHTML5) {
|
|
// Setup captions
|
|
if (Object.keys(input).includes('tracks')) {
|
|
source.insertElements.call(this, 'track', input.tracks);
|
|
}
|
|
}
|
|
|
|
// If HTML5 or embed but not fully supported, setupInterface and call ready now
|
|
if (this.isHTML5 || (this.isEmbed && !this.supported.ui)) {
|
|
// Setup interface
|
|
ui.build.call(this);
|
|
}
|
|
|
|
// Load HTML5 sources
|
|
if (this.isHTML5) {
|
|
this.media.load();
|
|
}
|
|
|
|
// Update previewThumbnails config & reload plugin
|
|
if (!is.empty(input.previewThumbnails)) {
|
|
Object.assign(this.config.previewThumbnails, input.previewThumbnails);
|
|
|
|
// Cleanup previewThumbnails plugin if it was loaded
|
|
if (this.previewThumbnails && this.previewThumbnails.loaded) {
|
|
this.previewThumbnails.destroy();
|
|
this.previewThumbnails = null;
|
|
}
|
|
|
|
// Create new instance if it is still enabled
|
|
if (this.config.previewThumbnails.enabled) {
|
|
this.previewThumbnails = new PreviewThumbnails(this);
|
|
}
|
|
}
|
|
|
|
// Update the fullscreen support
|
|
this.fullscreen.update();
|
|
},
|
|
true,
|
|
);
|
|
},
|
|
};
|
|
|
|
export default source;
|