vidstack
Version:
Build awesome media experiences on the web.
68 lines (64 loc) • 2.26 kB
JavaScript
import { $$_create_walker, $$_effect, $$_attr, $$_ref, $$_create_template } from 'maverick.js/dom';
import { isString } from 'maverick.js/std';
const AUDIO_EXTENSIONS = /\.(m4a|m4b|mp4a|mpga|mp2|mp2a|mp3|m2a|m3a|wav|weba|aac|oga|spx)($|\?)/i;
const AUDIO_TYPES = /* @__PURE__ */ new Set([
"audio/mpeg",
"audio/ogg",
"audio/3gp",
"audio/mp4",
"audio/webm",
"audio/flac"
]);
const VIDEO_EXTENSIONS = /\.(mp4|og[gv]|webm|mov|m4v)(#t=[,\d+]+)?($|\?)/i;
const VIDEO_TYPES = /* @__PURE__ */ new Set([
"video/mp4",
"video/webm",
"video/3gp",
"video/ogg",
"video/avi",
"video/mpeg"
]);
const HLS_VIDEO_EXTENSIONS = /\.(m3u8)($|\?)/i;
const HLS_VIDEO_TYPES = /* @__PURE__ */ new Set([
// Apple sanctioned
"application/vnd.apple.mpegurl",
// Apple sanctioned for backwards compatibility
"audio/mpegurl",
// Very common
"audio/x-mpegurl",
// Very common
"application/x-mpegurl",
// Included for completeness
"video/x-mpegurl",
"video/mpegurl",
"application/mpegurl"
]);
function isHLSSrc({ src, type }) {
return typeof src === "string" && HLS_VIDEO_EXTENSIONS.test(src) || HLS_VIDEO_TYPES.has(type);
}
function isMediaStream(src) {
return typeof window.MediaStream !== "undefined" && src instanceof window.MediaStream;
}
const $$_templ = /* @__PURE__ */ $$_create_template(`<!$><audio preload="none" aria-hidden="true"></audio>`), $$_templ_2 = $$_templ;
class AudioProviderLoader {
kh;
canPlay({ src, type }) {
return isString(src) ? AUDIO_EXTENSIONS.test(src) || AUDIO_TYPES.has(type) || src.startsWith("blob:") && type === "audio/object" : type === "audio/object";
}
mediaType() {
return "audio";
}
async load() {
return new (await import('./provider.js')).AudioProvider(this.kh);
}
render($store) {
return (() => {
const [$$_root, $$_walker] = $$_create_walker($$_templ_2);
$$_effect(() => $$_attr($$_root, "controls", $store.controls()));
$$_effect(() => $$_attr($$_root, "crossorigin", $store.crossorigin()));
$$_ref($$_root, (el) => void (this.kh = el));
return $$_root;
})();
}
}
export { AudioProviderLoader as A, HLS_VIDEO_EXTENSIONS as H, VIDEO_EXTENSIONS as V, HLS_VIDEO_TYPES as a, isMediaStream as b, VIDEO_TYPES as c, isHLSSrc as i };