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