0
I am making an application (Ionic4, typescript, Node.js) for recording and playing audio where the user records the sound and after the audio is presented with a play button; Soon after the user gives permission to store data and access the microphone, the application closes without any error in the Debugger.
Follow the code of . html and . ts
Audios.page.html
<ion-row>
<ion-col>
<ion-button expand="full" (click)="capturarAudio()">Gravar áudio</ion-button>
</ion-col>
</ion-row>
<ion-list>
<ion-item *ngFor="let arquivo of mediaFiles" tappable (click)="play(arquivo)" text-wrap>
{{ file.name }}
<p>{{file.size / 1000 / 1000 | number }} MB </p>
</ion-item>
</ion-list>
Audios.pagets.
import { Component, OnInit } from '@angular/core';
import { MediaCapture } from '@ionic-native/media-capture/ngx';
import { IonicStorageModule } from '@ionic/storage';
import { Media, MediaObject } from '@ionic-native/media/ngx';
import { File } from '@ionic-native/file/ngx';
import { Storage } from '@ionic/storage';
const MEDIA_FILES_KEY = 'mediafiles';
@Component({
selector: 'app-audios',
templateUrl: './audios.page.html',
styleUrls: ['./audios.page.scss'],
})
export class AudiosPage implements OnInit {
mediaFiles = [];
constructor(private mediaCapture: MediaCapture, private storage: Storage, private media: Media, private file: File) {
}
ionViewDidLoad(){
this.storage.get(MEDIA_FILES_KEY).then(res => {
this.mediaFiles = JSON.parse(res) || [];
});
}
capturarAudio(){
this.mediaCapture.captureAudio().then( res => {
this.storeMediaFiles(res);
})
}
play(myFile){
console.log('play', myFile);
if (myFile.name.indexOf('.wav') > -1){
const audioFile: MediaObject = this.media.create(myFile.localURL)
audioFile.play();
}
}
storeMediaFiles(files){
console.log('storage:', files);
this.storage.get(MEDIA_FILES_KEY).then(res => {
if (res) {
let arr = JSON.parse(res);
arr = arr.concat(files);
this.storage.set(MEDIA_FILES_KEY, JSON.stringify(arr))
} else {
this.storage.set(MEDIA_FILES_KEY, JSON.stringify(files))
}
this.mediaFiles = this.mediaFiles.concat(files);
})
}
ngOnInit() {
}
}
EDIT1: Taking a look at Logcat I get this error:
E/PluginManager: Uncaught exception from plugin
android.content.ActivityNotFoundException: No Activity found to handle Intent { act=android.provider.MediaStore.RECORD_SOUND }
at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1899)
at android.app.Instrumentation.execStartActivity(Instrumentation.java:1589)
at android.app.Activity.startActivityForResult(Activity.java:4229)
at org.apache.cordova.CordovaActivity.startActivityForResult(CordovaActivity.java:343)
at android.app.Activity.startActivityForResult(Activity.java:4187)
at org.apache.cordova.CordovaInterfaceImpl.startActivityForResult(CordovaInterfaceImpl.java:68)
at org.apache.cordova.mediacapture.Capture.captureAudio(Capture.java:234)
at org.apache.cordova.mediacapture.Capture.execute(Capture.java:132)
at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
at org.apache.cordova.CordovaBridge.jsExec(CordovaBridge.java:59)
at org.apache.cordova.engine.SystemExposedJsApi.exec(SystemExposedJsApi.java:41)
at android.os.MessageQueue.nativePollOnce(Native Method)
at android.os.MessageQueue.next(MessageQueue.java:323)
at android.os.Looper.loop(Looper.java:136)
at android.os.HandlerThread.run(HandlerThread.java:61)
This may have to do with the plugin you installed. Installed some?
– Marconi
Only the necessary, media-capture.
– rzp
You are testing on a mobile phone or in the Browser ?
– Vinicius Lourenço
I’m running on mobile, I tested in two and both happens the same thing
– rzp