From 536adc7887a11f59209117705cdef41b8cd3ad40 Mon Sep 17 00:00:00 2001 From: yumoqing Date: Thu, 26 Dec 2024 10:33:39 +0800 Subject: [PATCH] bugfix --- bricks/audio.js | 67 ++++++++++++-- bricks/binstreaming.js | 22 +++++ bricks/build.sh | 1 + bricks/css/bricks.css | 2 +- bricks/header.tmpl | 20 ++-- bricks/input.js | 44 ++++++++- bricks/jsoncall.js | 11 ++- bricks/utils.js | 204 +++++++++++++++++++++++++++++++---------- 8 files changed, 300 insertions(+), 71 deletions(-) diff --git a/bricks/audio.js b/bricks/audio.js index a93774c..8c088e5 100644 --- a/bricks/audio.js +++ b/bricks/audio.js @@ -26,7 +26,7 @@ bricks.AudioPlayer = class extends bricks.JsWidget { this.audio = this._create('audio'); this.audio.controls = true; if (this.opts.autoplay){ - this.audio.addEventListener('canplay', this.play_audio.bind(this)); + this.audio.addEventListener('canplay', this.play.bind(this)); } this.audio.style.width = "100%" this.dom_element.appendChild(this.audio); @@ -34,6 +34,58 @@ bricks.AudioPlayer = class extends bricks.JsWidget { this.set_source(this.url); } } + + set_stream_urls(response){ + async function* dyn_urls(response) { + const reader = response.body.getReader(); + var value; + var done; + while (true){ + done, value = await reader.read(); + if (value.done){ + console.log('done=', done, 'value=', value); + break; + } + let result = ''; + for (let i = 0; i < value.value.length; i++) { + result += String.fromCharCode(value.value[i]); + } + console.log('audio set url=', result); + yield result; + } + } + this.url_generator = dyn_urls(response); + this.srcList = []; + schedule_once(this.load_queue_url.bind(this), 0.1); + } + async load_queue_url(){ + while (true){ + var d = await this.url_generator.next(); + if (d.done){ + return; + } + this.srcList.push({played:false, url:d.value}); + if (this.srcList.length < 2 ){ + await this.play_srclist(); + this.audio.addEventListener('ended', + this.play_srclist.bind(this)); + } + } + } + async play_srclist(evnet){ + if (event && ! this.audio.ended){ + return; + } + for (var i=0;i - - - + + + - - - + + +