From fc49ab285e00391f1b822c6dd39e0ad89239ac7d Mon Sep 17 00:00:00 2001 From: bonjinnorenka <32708102+bonjinnorenka@users.noreply.github.com> Date: Sat, 26 Aug 2023 00:48:41 +0900 Subject: [PATCH] fix playing related bugs --- assets/js/invidious_iframe_api.js | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/assets/js/invidious_iframe_api.js b/assets/js/invidious_iframe_api.js index cc8a259f..d08829f1 100644 --- a/assets/js/invidious_iframe_api.js +++ b/assets/js/invidious_iframe_api.js @@ -26,6 +26,8 @@ class invidious_embed{ Player(element,options){ this.player_status = -1; this.error_code = 0; + this.volume = 100; + this.eventobject = {ready:[],ended:[],error:[],ratechange:[],volumechange:[],waiting:[],timeupdate:[],loadedmetadata:[],play:[],seeking:[],seeked:[],playerresize:[],pause:[],statechange:[]}; var replace_elemnt; if(element===undefined||element===null){ throw 'please set element id or HTMLElement'; @@ -79,6 +81,7 @@ class invidious_embed{ this.player_iframe = document.createElement("iframe"); this.loaded = false; this.addEventListener('loadedmetadata',()=>{this.event_executor('ready');this.loaded=true}); + this.addEventListener('loadedmetadata',()=>{this.setVolume(this.volume)}); this.player_iframe.src = iframe_src; if(options.width!==undefined&&typeof options.width==='number'){ this.player_iframe.width = options.width; @@ -98,7 +101,6 @@ class invidious_embed{ this.player_iframe.height = this.player_iframe.width * (9/16); } this.player_iframe.style.border = "none"; - this.eventobject = {ready:[],ended:[],error:[],ratechange:[],volumechange:[],waiting:[],timeupdate:[],loadedmetadata:[],play:[],seeking:[],seeked:[],playerresize:[],pause:[],statechange:[]}; replace_elemnt.replaceWith(this.player_iframe); this.eventdata = {}; return this; @@ -198,6 +200,7 @@ class invidious_embed{ } setVolume(volume){ volume = Number(volume); + this.volume = volume; if(volume!==NaN&&volume!=undefined&&volume>=0&&volume<=100){ this.postMessage({eventname:'setvolume',value:volume/100}); } @@ -276,7 +279,7 @@ class invidious_embed{ startSeconds = option.startSeconds; } if(option.endSeconds!==undefined&&typeof option.endSeconds==='number'&&option.endSeconds>=0){ - startSeconds = option.endSeconds; + endSeconds = option.endSeconds; } } if(mediaContetUrl.length>0){ @@ -355,9 +358,6 @@ class invidious_embed{ getVideoUrl(){ return this.target_origin + "/watch?v=" + this.videoId; } - getVideoTitle(){//original function - return this.promise_send_event('gettitle'); - } async getVideoEmbedCode(){ var title = await this.getVideoTitle(); return ''; @@ -370,6 +370,9 @@ class invidious_embed{ window.addEventListener('message',(ms)=>{this.receiveMessage(ms)}); this.message_wait = {getvolume:[],getmutestatus:[],getduration:[],getcurrenttime:[],getplaybackrate:[],getavailableplaybackrates:[],gettitle:[]}; } + async getVideoData(){ + return {video_id:this.videoId,title:this.promise_send_event('gettitle')}; + } } function invidious_ready(func){ if(typeof func==='function'){