This commit is contained in:
yumoqing 2024-03-20 15:44:25 +08:00
parent 1937541daf
commit 517b8f0d4d
4 changed files with 27 additions and 15 deletions

View File

@ -1,5 +1,5 @@
var bricks = window.bricks || {}; var bricks = window.bricks || {};
bricks.Accordion = class oops extends bricks.VBox { bricks.Accordion = class extends bricks.VBox {
/* /*
{ {
item_size: item_size:

View File

@ -1,5 +1,5 @@
var bricks = window.bricks || {}; var bricks = window.bricks || {};
bricks.AG_Grid = class oops extends bricks.JsWidget { bricks.AG_Grid = class extends bricks.JsWidget {
/* /*
{ {
dataurl: dataurl:

View File

@ -12,7 +12,7 @@ var formatMs=function(ms,all){
return t; return t;
}; };
bricks.AudioPlayer = class oops extends bricks.JsWidget { bricks.AudioPlayer = class extends bricks.JsWidget {
/* /*
{ {
url: url:
@ -54,13 +54,18 @@ bricks.AudioPlayer = class oops extends bricks.JsWidget {
} }
bricks.AudioRecorder = class oops extends bricks.HBox { bricks.AudioRecorder = class extends bricks.HBox {
/* /*
{
"upload_url":
"icon_rate":
"upload_resp":"text", or "json", or "bin"
}
we need this module: we need this module:
https://gitee.com/xiangyuecn/Recorder https://gitee.com/xiangyuecn/Recorder
events: events:
record_started record_started
record_finished wavdata record_ended
realtime record wave show need a another package realtime record wave show need a another package
we only use the wav file format we only use the wav file format
*/ */
@ -68,7 +73,7 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
super(opts); super(opts);
this.start_icon = opts.start_icon || bricks_resource('imgs/start_recording.png'); 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.stop_icon = opts.stop_icon || bricks_resource('imgs/stop_recording.png');
this.rec_btn = new bricks.Icon({url:this.start_icon }); this.rec_btn = new bricks.Icon({url:this.start_icon, rate:this.icon_rate });
// this.player = new bricks.AudioPlayer({url:"",width:'80px'}); // this.player = new bricks.AudioPlayer({url:"",width:'80px'});
this.rec_time = new bricks.Text({text:" record time", i18n:false, wrap:false, width:'120px'}); this.rec_time = new bricks.Text({text:" record time", i18n:false, wrap:false, width:'120px'});
this.upload_url = opts.upload_url; this.upload_url = opts.upload_url;
@ -79,9 +84,8 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
this.mic_opened = false; this.mic_opened = false;
this.add_widget(this.rec_btn); this.add_widget(this.rec_btn);
this.add_widget(this.rec_time); this.add_widget(this.rec_time);
// this.add_widget(this.player);
this.recordData = null; this.recordData = null;
this.bind('record_finished', this.upload.bind(this)); this.bind('record_ended', this.upload.bind(this));
} }
rec_btn_pressed(){ rec_btn_pressed(){
bricks.debug(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon); bricks.debug(this.rec_btn.url, ':url:', this.start_icon, this.stop_icon);
@ -161,7 +165,6 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
bricks.debug("5JuL::未打开录音"); bricks.debug("5JuL::未打开录音");
return; return;
}; };
// this.pause_recording();
this.rec.stop(function(blob,duration){ this.rec.stop(function(blob,duration){
var localURL = this.URL.createObjectURL(blob); var localURL = this.URL.createObjectURL(blob);
var d = { var d = {
@ -170,14 +173,12 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
duration:duration duration:duration
} }
this.recordData = d; this.recordData = d;
// this.player.set_source(this.recordData.url); this.dispatch('record_ended', d);
this.dispatch('record_finished', d);
}.bind(this),function(msg){ }.bind(this),function(msg){
bricks.debug("kGZO::录音失败:"); bricks.debug("kGZO::录音失败:");
}); });
this.recClose(); this.recClose();
this.dispatch('record_ended');
} }
upload = async function(){ upload = async function(){
if(!this.recordData){ if(!this.recordData){
@ -196,7 +197,18 @@ bricks.AudioRecorder = class oops extends bricks.HBox {
params:form params:form
}); });
bricks.debug('ret=', ret); bricks.debug('ret=', ret);
this.dispatch('uploaded', ret) if (!this.upload_resp){
this.upload_resp = 'text';
}
data = null;
if (this.upload_resp == 'text'){
data = await ret.text();
} else if (this.upload_resp == 'json'){
data = await ret.json();
} else if (this.upload_resp == 'bin'){
data = await ret.bin();
}
this.dispatch('uploaded', data)
} }
download(){ download(){
if(!this.recordData){ if(!this.recordData){

View File

@ -1,5 +1,5 @@
var bricks = window.bricks || {}; var bricks = window.bricks || {};
bricks.Image = class oops extends bricks.JsWidget { bricks.Image = class extends bricks.JsWidget {
/* /*
{ {
url: url:
@ -49,7 +49,7 @@ bricks.Icon = class extends bricks.Image {
} }
} }
bricks.BlankIcon = class oops extends bricks.JsWidget { bricks.BlankIcon = class extends bricks.JsWidget {
constructor(opts){ constructor(opts){
super(opts); super(opts);
this.rate = opts.rate || 1; this.rate = opts.rate || 1;