Fix set video src and duration not working

This commit is contained in:
hadi 2023-11-13 12:50:23 +01:00
parent 2740632bdb
commit 415cbdf5b2

View File

@ -28,6 +28,7 @@ type VideoTagsArray = Array<{
// Create a class for the element // Create a class for the element
class multi_video extends HTMLElement { class multi_video extends HTMLElement {
private _src : string = '';
/** /**
* shadow dom container * shadow dom container
* @private * @private
@ -111,7 +112,7 @@ class multi_video extends HTMLElement {
switch(name) switch(name)
{ {
case 'src': case 'src':
this.__buildVideoTags(newVal); this.src = newVal;
break; break;
case 'type': case 'type':
this._videos.forEach(_item => { this._videos.forEach(_item => {
@ -132,25 +133,20 @@ class multi_video extends HTMLElement {
/** /**
* init/update video tags * init/update video tags
* @param _value * @param array|string _value
* @private * @private
*/ */
private __buildVideoTags (_value) private __buildVideoTags (_value)
{ {
let value = _value.split(','); let value = Array.isArray(_value) ? _value : _value.split(',');
let video = null; let video = null;
let duration = 0; let duration = 0;
for (let i=0;i<value.length;i++) for (let i=0;i<value.length;i++)
{ {
video = document.createElement('video'); video = document.createElement('video');
// get duration from url duration param which is necessary for setting duration time of webm file
if (value[i].match(/&duration=/)) let params = new URLSearchParams(value[i].match(/\?.*/)[0]);
{ duration = parseInt(params.get('duration')||'0');
// get duration from url duration param which is necessary for setting duration time of webm file
let params = new URLSearchParams(value[i]);
duration = parseInt(params.get('duration'));
value[i] = value[i].replace(/&duration.*/, '');
}
video.src = value[i]; video.src = value[i];
this._videos[i] = { this._videos[i] = {
node:this._wrapper.appendChild(video), node:this._wrapper.appendChild(video),
@ -249,8 +245,9 @@ class multi_video extends HTMLElement {
*/ */
set src(_value) set src(_value)
{ {
this._src = _value;
let value = _value.split(','); let value = _value.split(',');
this._wrapper.children.forEach(_ch=>{ Array.from(this._wrapper?.children)?.forEach(_ch=>{
_ch.remove(); _ch.remove();
}); });
this.__buildVideoTags(value); this.__buildVideoTags(value);
@ -262,7 +259,7 @@ class multi_video extends HTMLElement {
*/ */
get src () get src ()
{ {
return this.src; return this._src;
} }
/** /**