diff --git a/bricks/audio.js b/bricks/audio.js index 9bfd7e3..d4437d7 100755 --- a/bricks/audio.js +++ b/bricks/audio.js @@ -50,17 +50,22 @@ bricks.AudioPlayer = class oops extends bricks.JsWidget { bricks.AudioRecorder = class oops extends bricks.HBox { /* + we need this module: + https://gitee.com/xiangyuecn/Recorder events: record_started record_finished wavdata + realtime record wave show need a another package + we only use the wav file format */ constructor(opts){ super(opts); this.start_icon = opts.start_icon || bricks_resource('imgs/start_recording.png'); this.stop_icon = opts.stop_icon || bricks_resource('imgs/stop_recording.png'); this.rec_btn = new bricks.Icon({url:this.start_icon }); - this.player = new bricks.AudioPlayer({url:"",width:'80px'}); - this.rec_time = new bricks.Text({text:"", i18n:false, width:'120px'}); + // this.player = new bricks.AudioPlayer({url:"",width:'80px'}); + this.rec_time = new bricks.Text({text:" record time", i18n:false, wrap:false, width:'120px'}); + this.upload_url = opts.upload_url; this.rec_btn.bind('click', this.rec_btn_pressed.bind(this)) this.URL = window.URL||webkitURL; this.rec = null; @@ -68,8 +73,9 @@ bricks.AudioRecorder = class oops extends bricks.HBox { this.mic_opened = false; this.add_widget(this.rec_btn); this.add_widget(this.rec_time); - this.add_widget(this.player); + // this.add_widget(this.player); this.recordData = null; + this.bind('record_finished', this.upload.bind(this)); } rec_btn_pressed(){ console.log(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon); @@ -88,8 +94,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox { // document.querySelector(".recpowerx").style.width=powerLevel+"%"; //可视化图形绘制 // wave.input(buffers[buffers.length-1],powerLevel,bufferSampleRate); - this.rec_time.text = formatMs(bufferDuration,1); - console.log(this.rec_time.text); + this.rec_time.set_text(' ' + formatMs(bufferDuration,1)); } recOpen(){ @@ -114,6 +119,8 @@ bricks.AudioRecorder = class oops extends bricks.HBox { recClose(){ if(this.rec){ this.rec.close(); + this.rec = null; + this.mic_opened = false; }else{ console.log('close recorder error'); }; @@ -159,26 +166,31 @@ bricks.AudioRecorder = class oops extends bricks.HBox { duration:duration } this.recordData = d; - this.player.set_source(this.recordData.url); + // this.player.set_source(this.recordData.url); this.dispatch('record_finished', d); }.bind(this),function(msg){ console.log("kGZO::录音失败:"); }); } - async upload(){ + upload = async function(){ if(!this.recordData){ console.log("DUTn::请先录音,然后停止后再上传"); return; }; - var blob=this.recordData.blob; + if(!this.upload_url){ + return; + } + var blob=this.recordData.data; + console.log('blob=', blob, this.recordData); var form=new FormData(); form.append("audiofile",blob,"recorder.wav"); - var hj = HttpJson() - var ret = await hj.post(this.upload_url,{ + var jpost = bricks.jpost + var ret = await jpost(this.upload_url,{ params:form }); console.log('ret=', ret); + this.recClose(); this.dispatch('updated', ret) } download(){ diff --git a/bricks/bricks.js b/bricks/bricks.js index d399db9..0152589 100755 --- a/bricks/bricks.js +++ b/bricks/bricks.js @@ -121,7 +121,7 @@ bricks.buildBind = function(w, desc){ return; } var event = desc.event; - buildEventBind(w, widget, event, desc); + bricks.buildEventBind(w, widget, event, desc); } bricks.buildEventBind = function(from_widget, widget, event, desc){ diff --git a/bricks/build.sh b/bricks/build.sh index 5cc85e4..088f2f4 100755 --- a/bricks/build.sh +++ b/bricks/build.sh @@ -8,7 +8,7 @@ SOURCES=" factory.js uitypesdef.js utils.js i18n.js widget.js \ miniform.js wterm.js " echo ${SOURCES} cat ${SOURCES} > ../dist/bricks.js -uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js +# uglifyjs --compress --mangle -- ../dist/bricks.js > ../dist/bricks.min.js if [ ! -d ../dist/css ];then rm -rf ../dist/css mkdir ../dist/css diff --git a/bricks/widget.js b/bricks/widget.js index 3300732..04b0fce 100755 --- a/bricks/widget.js +++ b/bricks/widget.js @@ -239,7 +239,10 @@ bricks.TextBase = class extends bricks.JsWidget { if (! this.i18n){ return; } - this.text = this._i18n._(this.otext); + this.set_text(this.otext); + } + set_text(text){ + this.text = text; this.dom_element.innerHTML = this.text; }