UNPKG

@arcgis/core

Version:

ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API

6 lines (5 loc) 3.87 kB
/* All material copyright ESRI, All Rights Reserved, unless otherwise specified. See https://js.arcgis.com/4.33/esri/copyright.txt for details. */ import{_ as e}from"../../chunks/tslib.es6.js";import t from"../../request.js";import o from"../../core/Error.js";import r from"../../core/Logger.js";import{clamp as s}from"../../core/mathUtils.js";import{renderingSanitizer as i}from"../../core/sanitizerUtils.js";import{makeAbsolute as n,isAbsolute as a,getProxyRule as c,addProxy as d,isBlobProtocol as l,isDataProtocol as p}from"../../core/urlUtils.js";import{property as u}from"../../core/accessorSupport/decorators/property.js";import"../../core/has.js";import"../../core/RandomLCG.js";import{subclass as m}from"../../core/accessorSupport/decorators/subclass.js";import{writer as h}from"../../core/accessorSupport/decorators/writer.js";import y from"./MediaElementBase.js";import{mediaElementUrlProperty as v,mediaTypeProperty as f}from"./mediaUtils.js";import{whenVideoPlayable as g}from"./videoUtils.js";import{VideoElementSymbol as j}from"../../support/mediaLayerUtils.js";import{i as U}from"../../chunks/persistableUrlUtils.js";var b;const w=Symbol("canplay");let V=class extends y{static{b=j}constructor(e){super(e),this.autoplay=!0,this.content=null,this.type="video",this[b]=!0}load(){const e=this.video;return"string"==typeof e?this.addResolvingPromise(this._preProcessVideoUrl(e).then((async e=>{const t=document.createElement("video");return t.src=i.sanitizeUrl(n(e)),t.crossOrigin="anonymous",t.autoplay=this.autoplay,t.muted=!0,t.loop=!0,t.playsInline=!0,this._loadVideo(t).then((()=>{this._set("content",t)}))}))):e instanceof HTMLVideoElement?this.addResolvingPromise(this._loadVideo(e).then((()=>{this._set("content",e)}))):this.addResolvingPromise(Promise.reject(new o("video-element:invalid-video-type","Invalid video type",{video:e}))),Promise.resolve(this)}get contentWidth(){return this.content?.videoWidth??0}get contentHeight(){return this.content?.videoHeight??0}get currentTime(){return this.content?.currentTime}set currentTime(e){if(!this.content)return;const t=s(e,0,this.content.duration);"fastSeek"in this.content?this.content.fastSeek(t):this.content.currentTime=t,this.content.play().then((()=>{this.content?.pause()})).catch((()=>{}))}get duration(){return this.content?.duration}set video(e){"not-loaded"===this.loadStatus?this._set("video",e):r.getLogger(this).error("#video","video cannot be changed after the element is loaded.")}writeVideo(e,t,r,s){if(!e)return void(s?.messages&&s.messages.push(new o("video-element:unsupported-video","video source is missing")));const i=_(e)?e:null;if(!i)return void(s?.messages&&s.messages.push(new o("video-element:unsupported-video","video source must be an absolute url")));!a(i)&&s?.blockedRelativeUrls&&s.blockedRelativeUrls.push(i);const c=n(i);!U(c)?t[r]=c:s?.messages&&s.messages.push(new o("video-element:unsupported-video","video source cannot be an item resource"))}async _preProcessVideoUrl(e){if(c(e))return d(e);try{return await t(e,{method:"head"}),e}catch{try{return d(e,!0)}catch{return e}}}async _loadVideo(e){"anonymous"!==e.crossOrigin&&(e.crossOrigin="anonymous",l(e.src)||(e.src=e.src));try{await g(e,(e=>this.addHandles(e,w))),this.autoplay&&await e.play().catch((e=>{throw console.error(e),e}))}finally{this.removeHandles(w)}}};function _(e){return"string"==typeof e&&!p(e)&&!l(e)}e([u()],V.prototype,"autoplay",void 0),e([u({readOnly:!0})],V.prototype,"content",void 0),e([u({readOnly:!0})],V.prototype,"contentWidth",null),e([u({readOnly:!0})],V.prototype,"contentHeight",null),e([u({type:Number})],V.prototype,"currentTime",null),e([u({type:Number})],V.prototype,"duration",null),e([u(v)],V.prototype,"video",null),e([h("video")],V.prototype,"writeVideo",null),e([u(f)],V.prototype,"type",void 0),V=e([m("esri.layers.support.VideoElement")],V);export{V as default};