This commit is contained in:
tiago.kayaya
2022-03-10 16:26:43 +01:00
parent 00afc6d918
commit 43b7e4ade0
3 changed files with 43 additions and 31 deletions
@@ -180,6 +180,15 @@
<button hidden (click)="startRecording()">Start Recording</button>
<button hidden (click)="stopRecording()">Stop Recording</button>
<audio *ngIf="audioRecorded" controls [src]="audioRecorded">
</audio>
<audio controls>
<source src="assets/audio/Audiorecord.mp3" type="audio/ogg">
<source src="assets/audio/Audiorecord.mp3" type="audio/mpeg">
Your browser does not support the audio element.
</audio>
<div class="width-100">
<span *ngIf="!lastAudioRecorded">{{durationDisplay}}</span>
<span *ngIf="lastAudioRecorded" (click)="playFile(lastAudioRecorded)">{{lastAudioRecorded}}</span>
+34 -31
View File
@@ -87,6 +87,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
allowTyping = true;
storedFileNames = [];
lastAudioRecorded = '';
audioRecorded:any = "";
durationDisplay = '';
duration = 0;
@ViewChild('recordbtn', { read: ElementRef }) recordBtn: ElementRef;
@@ -237,7 +238,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
})
}
})
setTimeout(() => {
setTimeout(async () => {
this.loadFiles();
}, 500);
}
@@ -260,11 +261,40 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
console.log(audioFile);
const base64sound = audioFile.data;
this.fileOpener.open('C:/Users/tiago.kayaya/Downloads/Audiorecord','audio/wav')
//this.audioRecorded = `data:audio/aac;base64,${base64sound}`;
/* const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
console.log(this.audioRecorded);
//this.fileOpener.open('C:/Users/tiago.kayaya/Downloads/Audiorecord','audio/wav')
const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
//this.audioRecorded = audioRef;
//console.log(audioRef);
audioRef.oncanplaythrough = () => audioRef.play();
audioRef.load(); */
audioRef.load();
//this.getFile(fileName);
}
async getFile(fileName?:any){
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data
})
//console.log(audioFile);
const base64sound = audioFile.data;
//Converting base64 to blob
const base64 = await fetch(base64sound);
//console.log(base64);
const base64Response = await fetch(`data:audio/ogg;base64,${base64sound}`);
//console.log(base64Response);
this.audioRecorded = base64Response.url;
console.log(this.audioRecorded);
}
@@ -381,33 +411,6 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
const roomId = this.roomId
/* const file: any = await this.fileService.getFileFromDevice(audio);
console.log('Add file', file)
const blob = new Blob([file],{type: file.type})
console.log('Add file', blob)
const formData = new FormData();
formData.append("blobFile", blob);
let pdfBase64;
this.blobToBase64(blob).then(res => {
console.log('Base64 pdf', res);
this.wsChatMethodsService.getDmRoom(roomId).send({
file: {
"type": file.type,
"guid": '',
},
attachments: [{
"title": file.name ,
"title_link": res,
"title_link_download": true,
"type": "file"
}],
temporaryData: formData
})
}); */
const audioFile = await Filesystem.readFile({
path: fileName,
directory: Directory.Data