@arcgis/core
Version:
ArcGIS Maps SDK for JavaScript: A complete 2D and 3D mapping and data visualization API
3 lines (2 loc) • 3.63 kB
JavaScript
/* COPYRIGHT Esri - https://js.arcgis.com/5.0.8/LICENSE.txt */
import{__decorate as e}from"tslib";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 d,addProxy as c,isBlobProtocol as l,isDataProtocol as p}from"../../core/urlUtils.js";import{property as u,subclass as m}from"../../core/accessorSupport/decorators.js";import h from"./MediaElementBase.js";import{mediaElementUrlProperty as y,mediaTypeProperty as v}from"./mediaUtils.js";import{whenVideoPlayable as g}from"./videoUtils.js";import{VideoElementSymbol as f}from"../../support/mediaLayerUtils.js";import{i as j}from"../../chunks/persistableUrlUtils.js";import{writer as U}from"../../core/accessorSupport/decorators/writer.js";var b;const w=Symbol("canplay");let V=class extends h{static{b=f}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 d=n(i);!j(d)?t[r]=d:s?.messages&&s.messages.push(new o("video-element:unsupported-video","video source cannot be an item resource"))}async _preProcessVideoUrl(e){if(d(e))return c(e);try{return await t(e,{method:"head"}),e}catch{try{return c(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(y)],V.prototype,"video",null),e([U("video")],V.prototype,"writeVideo",null),e([u(v)],V.prototype,"type",void 0),V=e([m("esri.layers.support.VideoElement")],V);export{V as default};