mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix audio in device
This commit is contained in:
@@ -210,7 +210,7 @@
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-options" src="assets/images/icons-add.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-options" src="assets/images/theme/gov/icons-add.svg"></ion-icon>
|
||||
</button>
|
||||
<button *ngIf="recording || lastAudioRecorded || !allowTyping" class="btn-no-color" (click)="deleteRecording(lastAudioRecorded)">
|
||||
<button *ngIf="recording || lastAudioRecorded || !allowTyping" class="btn-no-color" (click)="deleteRecording()">
|
||||
<fa-icon class="icon-size-27" icon="trash"></fa-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -34,6 +34,7 @@ import { SearchPage } from 'src/app/pages/search/search.page';
|
||||
import { ProcessesService } from 'src/app/services/processes.service';
|
||||
import { VoiceRecorder, VoiceRecorderPlugin, RecordingData, GenericResponse, CurrentRecordingStatus } from 'capacitor-voice-recorder';
|
||||
import { Filesystem, Directory, Encoding } from '@capacitor/filesystem';
|
||||
import { DomSanitizer } from '@angular/platform-browser';
|
||||
|
||||
@Component({
|
||||
selector: 'app-group-messages',
|
||||
@@ -108,8 +109,8 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
private AttachmentsService: AttachmentsService,
|
||||
private storage: Storage,
|
||||
private processesService: ProcessesService,
|
||||
|
||||
private CameraService: CameraService,
|
||||
private sanitiser: DomSanitizer,
|
||||
) {
|
||||
this.loggedUserChat = authService.ValidatedUserChat['data'];
|
||||
this.isGroupCreated = true;
|
||||
@@ -144,7 +145,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
console.log('MEMBER', value)
|
||||
})
|
||||
VoiceRecorder.requestAudioRecordingPermission();
|
||||
this.loadFiles();
|
||||
//this.loadFiles();
|
||||
}
|
||||
|
||||
setStatus(status: string) {
|
||||
@@ -237,15 +238,20 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async loadFiles() {
|
||||
Filesystem.readdir({
|
||||
path: '',
|
||||
directory: Directory.Data
|
||||
}).then(result => {
|
||||
console.log(result);
|
||||
this.storedFileNames = result.files.reverse();
|
||||
this.lastAudioRecorded = this.storedFileNames[0];
|
||||
this.getFile(this.lastAudioRecorded);
|
||||
|
||||
this.storage.get('fileName').then((fileName) => {
|
||||
this.lastAudioRecorded = fileName;
|
||||
})
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
@@ -260,6 +266,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
this.deleteRecording();
|
||||
this.allowTyping = false;
|
||||
console.log('Stop');
|
||||
if (!this.recording) {
|
||||
@@ -267,27 +274,28 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
this.recording = false;
|
||||
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
|
||||
console.log(result);
|
||||
this.recording = false;
|
||||
if (result.value && result.value.recordDataBase64) {
|
||||
const recordData = result.value.recordDataBase64;
|
||||
//console.log(recordData);
|
||||
const fileName = new Date().getTime() + ".wav";
|
||||
await Filesystem.writeFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data,
|
||||
data: recordData,
|
||||
//Save file
|
||||
this.storage.set('fileName',fileName);
|
||||
this.storage.set('recordData',result).then(() => {
|
||||
console.log('Audio recorded saved');
|
||||
})
|
||||
}
|
||||
})
|
||||
setTimeout(async () => {
|
||||
this.loadFiles();
|
||||
}, 500);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async deleteRecording(fileName){
|
||||
await Filesystem.deleteFile({
|
||||
directory: Directory.Data,
|
||||
path: fileName
|
||||
});
|
||||
async deleteRecording(){
|
||||
this.storage.remove('fileName');
|
||||
this.storage.remove('recordData');
|
||||
|
||||
this.allowTyping = true;
|
||||
this.lastAudioRecorded = '';
|
||||
this.loadFiles();
|
||||
@@ -363,7 +371,7 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
close() {
|
||||
this.modalController.dismiss();
|
||||
this.deleteRecording(this.lastAudioRecorded);
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
doRefresh(ev: any) {
|
||||
@@ -412,13 +420,20 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async sendAudio(fileName) {
|
||||
|
||||
const roomId = this.roomId
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
})
|
||||
const base64sound = audioFile.data;
|
||||
const base64Response = await fetch(`data:audio/aac;base64,${base64sound}`);
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = recordData.value.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
||||
}
|
||||
});
|
||||
|
||||
//Converting base64 to blob
|
||||
const base64Response = await fetch(this.audioRecorded);
|
||||
const blob = await base64Response.blob();
|
||||
|
||||
const formData = new FormData();
|
||||
@@ -431,15 +446,13 @@ export class GroupMessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link": `data:audio/aac;base64,${base64sound}`,
|
||||
"title_link": this.audioRecorded,
|
||||
"title_link_download": true,
|
||||
"type": "file"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
this.allowTyping = true;
|
||||
this.lastAudioRecorded = '';
|
||||
this.deleteRecording();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -187,7 +187,7 @@
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="chat-icon-options" src="assets/images/icons-add.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="chat-icon-options" src="assets/images/theme/gov/icons-add.svg"></ion-icon>
|
||||
</button>
|
||||
<button *ngIf="recording || lastAudioRecorded || !allowTyping" class="btn-no-color" (click)="deleteRecording(lastAudioRecorded)">
|
||||
<button *ngIf="recording || lastAudioRecorded || !allowTyping" class="btn-no-color" (click)="deleteRecording()">
|
||||
<fa-icon class="icon-size-27" icon="trash"></fa-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -149,7 +149,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
this.wsChatMethodsService.getUserOfRoom(this.roomId).then((value) => {
|
||||
console.log('MEMBER', value)
|
||||
})
|
||||
this.loadFiles();
|
||||
//this.loadFiles();
|
||||
VoiceRecorder.requestAudioRecordingPermission();
|
||||
this.getChatMembers();
|
||||
/* Filesystem.mkdir({
|
||||
@@ -200,15 +200,20 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
|
||||
async loadFiles() {
|
||||
Filesystem.readdir({
|
||||
path: '',
|
||||
directory: Directory.Data
|
||||
}).then(result => {
|
||||
console.log(result);
|
||||
this.storedFileNames = result.files.reverse();
|
||||
this.lastAudioRecorded = this.storedFileNames[0];
|
||||
this.getFile(this.lastAudioRecorded);
|
||||
|
||||
this.storage.get('fileName').then((fileName) => {
|
||||
this.lastAudioRecorded = fileName;
|
||||
})
|
||||
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(recordData.value.recordDataBase64);
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = this.sanitiser.bypassSecurityTrustResourceUrl(`data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
startRecording() {
|
||||
@@ -218,11 +223,14 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
return;
|
||||
}
|
||||
this.recording = true;
|
||||
VoiceRecorder.startRecording();
|
||||
VoiceRecorder.startRecording()
|
||||
.then((result: GenericResponse) => console.log(result.value))
|
||||
.catch(error => console.log(error));
|
||||
this.calculateDuration();
|
||||
}
|
||||
|
||||
stopRecording() {
|
||||
this.deleteRecording();
|
||||
this.allowTyping = false;
|
||||
console.log('Stop');
|
||||
if (!this.recording) {
|
||||
@@ -230,76 +238,33 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}
|
||||
this.recording = false;
|
||||
VoiceRecorder.stopRecording().then(async (result: RecordingData) => {
|
||||
console.log(result);
|
||||
this.recording = false;
|
||||
if (result.value && result.value.recordDataBase64) {
|
||||
const recordData = result.value.recordDataBase64;
|
||||
//console.log(recordData);
|
||||
//this.myAudio = recordData;
|
||||
const fileName = new Date().getTime() + ".wav";
|
||||
await Filesystem.writeFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data,
|
||||
data: recordData,
|
||||
//Save file
|
||||
this.storage.set('fileName',fileName);
|
||||
this.storage.set('recordData',result).then(() => {
|
||||
console.log('Audio recorded saved');
|
||||
})
|
||||
}
|
||||
})
|
||||
setTimeout(async () => {
|
||||
this.loadFiles();
|
||||
}, 500);
|
||||
}, 1000);
|
||||
}
|
||||
|
||||
async deleteRecording(fileName){
|
||||
await Filesystem.deleteFile({
|
||||
directory: Directory.Data,
|
||||
path: fileName
|
||||
});
|
||||
async deleteRecording(){
|
||||
this.storage.remove('fileName');
|
||||
this.storage.remove('recordData');
|
||||
|
||||
this.allowTyping = true;
|
||||
this.lastAudioRecorded = '';
|
||||
this.loadFiles();
|
||||
}
|
||||
|
||||
async playFile(fileName?: any) {
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
})
|
||||
console.log(audioFile);
|
||||
const base64sound = audioFile.data;
|
||||
|
||||
this.audioRecorded = `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();
|
||||
|
||||
}
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
handlePress(id?: string) {
|
||||
@@ -324,7 +289,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
close() {
|
||||
this.modalController.dismiss();
|
||||
this.deleteRecording(this.lastAudioRecorded);
|
||||
this.deleteRecording();
|
||||
}
|
||||
|
||||
load() {
|
||||
@@ -404,27 +369,20 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
async sendAudio(fileName) {
|
||||
|
||||
const roomId = this.roomId
|
||||
|
||||
const audioFile = await Filesystem.readFile({
|
||||
path: fileName,
|
||||
directory: Directory.Data
|
||||
})
|
||||
console.log(audioFile);
|
||||
const base64sound = audioFile.data;
|
||||
|
||||
const audioRef = new Audio(`data:audio/aac;base64,${base64sound}`)
|
||||
|
||||
console.log(audioRef);
|
||||
this.storage.get('recordData').then((recordData) => {
|
||||
console.log(recordData);
|
||||
if(recordData.value.recordDataBase64.includes('data:audio')){
|
||||
this.audioRecorded = recordData.value.recordDataBase64;
|
||||
}
|
||||
else{
|
||||
this.audioRecorded = `data:${recordData.value.mimeType};base64,${recordData.value.recordDataBase64}`;
|
||||
}
|
||||
});
|
||||
|
||||
//Converting base64 to blob
|
||||
const base64 = await fetch(base64sound);
|
||||
const base64Response = await fetch(`data:audio/aac;base64,${base64sound}`);
|
||||
console.log(base64Response);
|
||||
|
||||
const base64Response = await fetch(this.audioRecorded);
|
||||
const blob = await base64Response.blob();
|
||||
|
||||
console.log(blob);
|
||||
|
||||
const formData = new FormData();
|
||||
formData.append("blobFile", blob);
|
||||
|
||||
@@ -435,15 +393,13 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
},
|
||||
attachments: [{
|
||||
"title": fileName ,
|
||||
"title_link": `data:audio/aac;base64,${base64sound}`,
|
||||
"title_link": this.audioRecorded,
|
||||
"title_link_download": true,
|
||||
"type": "file"
|
||||
}],
|
||||
temporaryData: formData
|
||||
})
|
||||
|
||||
this.allowTyping = true;
|
||||
this.lastAudioRecorded = '';
|
||||
this.deleteRecording();
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user