bugfix
This commit is contained in:
parent
86f6872006
commit
df8e7f36dd
BIN
bricks/.DS_Store
vendored
BIN
bricks/.DS_Store
vendored
Binary file not shown.
@ -11,17 +11,19 @@ class AudioPlayer extends JsWidget {
|
||||
super(options);
|
||||
this.url = opt.url;
|
||||
this.audio = this._create('audio');
|
||||
// this.audio.autoplay = this.opts.autoplay;
|
||||
this.audio.controls = true;
|
||||
if (this.opts.autoplay){
|
||||
this.audio.addEventListener('canplay', this.play_audio.bind(this));
|
||||
}
|
||||
this.audio.style.width = "100%"
|
||||
var s = this._create('source');
|
||||
s.src = this.opts.url;
|
||||
this.audio.appendChild(s);
|
||||
this.source = this._create('source');
|
||||
this.source.src = this.opts.url;
|
||||
this.audio.appendChild(this.source);
|
||||
this.dom_element.appendChild(this.audio);
|
||||
}
|
||||
set_source(url){
|
||||
this.source.src = url;
|
||||
}
|
||||
toggle_play(){
|
||||
if (this.audio.paused){
|
||||
this.audio.play();
|
||||
@ -31,4 +33,62 @@ class AudioPlayer extends JsWidget {
|
||||
}
|
||||
}
|
||||
|
||||
class AudioRecorder extends HBox {
|
||||
construction(opts){
|
||||
super(opts);
|
||||
this.start_icon = opts.start_icon || bricks_image('start_recording.png');
|
||||
this.stop_icon = opts.stop_icon || bricks_image('stop_recording.png');
|
||||
this.img = Image();
|
||||
this.img.src = this.start_icon;
|
||||
this.player = AudioPlayer();
|
||||
this.add_widget(this.img);
|
||||
this.add_widget(this.player);
|
||||
this.img.addListener('click', this.btn_clicked.bind(this));
|
||||
this.recorder = null;
|
||||
this.chunks = [];
|
||||
}
|
||||
start_recording(){
|
||||
if (!this.recorder){
|
||||
navigator.mediaDevices.getUserMedia({ audio: true })
|
||||
.then(stream => {
|
||||
const audioContext = new (window.AudioContext || window.webkitAudioContext)();
|
||||
const mediaStreamSource = audioContext.createMediaStreamSource(stream);
|
||||
|
||||
this.recorder = new MediaRecorder(mediaStreamSource.stream, { mimeType: 'audio/wav' });
|
||||
|
||||
this.chunks = [];
|
||||
|
||||
this.recorder.addEventListener('dataavailable', event => {
|
||||
this.chunks.push(event.data);
|
||||
});
|
||||
|
||||
this.recorder.addEventListener('end', () => {
|
||||
const blob = new Blob(chunks, { type: 'audio/wav' });
|
||||
console.log('Audio recorded and saved as blob:', blob);
|
||||
this.player.set_source(URL.createObjectURL(blob));
|
||||
});
|
||||
})
|
||||
.catch(error => console.error('Error accessing the microphone:', error));
|
||||
}
|
||||
this.recorder.start();
|
||||
}
|
||||
stop_recording(){
|
||||
if(this.recorder){
|
||||
this.recorder.stop();
|
||||
}
|
||||
}
|
||||
btn_clicked(){
|
||||
if (!this.isRecording){
|
||||
this.img.src = this.stop_icon;
|
||||
this.isRecording = true;
|
||||
this.start_recording();
|
||||
} else {
|
||||
this.img.src = this.start_icon;
|
||||
this.isRecording = false;
|
||||
this.stop_recording();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Factory.register('AudioPlayer', AudioPlayer);
|
||||
Factory.register('AudioRecorder', AudioRecorder);
|
||||
|
@ -21,12 +21,13 @@ if [ ! -d ../dist/docs ];then
|
||||
rm -rf ../dist/docs
|
||||
mkdir ../dist/docs
|
||||
fi
|
||||
if [ ! -d ../dist/imgs ];then
|
||||
rm -rf ../dist/imgs
|
||||
mkdir ../dist/imgs
|
||||
fi
|
||||
|
||||
cp -a css/* ../dist/css
|
||||
cp -a imgs/* ../dist/imgs
|
||||
cp -a ../examples ../dist
|
||||
cp -a ../docs ../dist
|
||||
cp -a ../dist/* ~/www/wwwroot/bricks
|
||||
# cd ../dist
|
||||
# cp -a * ~/www/wwwroot/bricks
|
||||
cp -a ../examples/* ../dist/examples
|
||||
cp -a ../docs/* ../dist/docs
|
||||
|
||||
|
BIN
bricks/imgs/start_recording.png
Normal file
BIN
bricks/imgs/start_recording.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 16 KiB |
BIN
bricks/imgs/stop_recording.png
Normal file
BIN
bricks/imgs/stop_recording.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 17 KiB |
@ -1,16 +0,0 @@
|
||||
| 页面名称 | html文件 | js文件 | 说明文件是否完成 |
|
||||
| ------------ | -------- | ------ | ---------------- |
|
||||
| accordion | √ | √ | √ |
|
||||
| audio | √ | √ | √ |
|
||||
| aggrid | x | √ | x |
|
||||
| button | √ | √ | √ |
|
||||
| datagrid | √ | √ | x(html页面报错) |
|
||||
| docs | √ | x | √ |
|
||||
| editabletree | √ | √ | √ |
|
||||
| error | √ | x | x(无html页面) |
|
||||
| message | √ | √ | √ |
|
||||
| tab | √ | √ | √ |
|
||||
| toolbar | √ | √ | √ |
|
||||
| tree | √ | √ | √ |
|
||||
| video | √ | √ | √ |
|
||||
|
Loading…
Reference in New Issue
Block a user