Set duration time for webm files based on provided duration url param

This commit is contained in:
hadi 2023-10-18 15:01:59 +02:00
parent 1ffe1876c5
commit 8fa2f565b6

View File

@ -130,15 +130,24 @@ class multi_video extends HTMLElement {
{ {
let value = _value.split(','); let value = _value.split(',');
let video = null; let video = null;
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');
if (value[i].match(/&duration=/))
{
// 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),
loadedmetadata: false, loadedmetadata: false,
timeupdate: false, timeupdate: false,
duration: 0, duration: duration ? duration : 0,
previousDurations: 0, previousDurations: 0,
currentTime: 0, currentTime: 0,
active: false, active: false,
@ -201,7 +210,7 @@ class multi_video extends HTMLElement {
}); });
if (allReady) { if (allReady) {
this._videos.forEach(_item => { this._videos.forEach(_item => {
_item.duration = _item.node.duration; _item.duration = _item.duration ? _item.duration : _item.node.duration;
_item.previousDurations = _item.index > 0 ? this._videos[_item.index-1]['duration'] + this._videos[_item.index-1]['previousDurations'] : 0; _item.previousDurations = _item.index > 0 ? this._videos[_item.index-1]['duration'] + this._videos[_item.index-1]['previousDurations'] : 0;
}); });
this.duration = this.__duration(); this.duration = this.__duration();