Quantcast
Channel: Ionic Framework - Ionic Forum
Viewing all articles
Browse latest Browse all 48981

I need to record Audio for my Ionic Capacitor app

$
0
0

Hi!
As the title says, I need to be able to record an audio file in my mobile application.
I am using Ionic 6 / Capacitor / Angular.
Following the documentation it seemed something quite simple to achieve, until I started testing in android studio.
The plugin in question is the following (so I can use it in my app)

import {Media, MediaObject} from '@ionic-native/media/ngx';

The functions with which I handle the recording are:

//This is called by the button on the view
record(){
   this.isRecording?this.stopRecord():this.startRecord()
   this.isRecording = !this.isRecording
}

startRecord(){
    this.fireAuth.fireauth.onAuthStateChanged((user) => {
      if (user) {
        let now = new Date();
        console.log('Recording...')
        this.newFile = this.media.create('file:///sdcard//Download/'+user.uid+'-'+this.formatDate(now)+'.mp3');
        this.newFile.startRecord();
      }else{
        console.log('Error: No Auth')
      }
    })
  }
  stopRecord(){
    console.log('Finished record!')
    this.newFile.stopRecord();
    this.newFile.release();
  }

With this what I can get are basically errors in the Android Studio console :confused:

when startRecord() is called

V/Capacitor/Plugin: To native (Cordova plugin): callbackId: INVALID, service: Media, action: create, actionArgs: ["28dcbcf9-4453-bb1b-8faf-74c13e4ec29c","file:\/\/\/sdcard\/\/Download\/xZpEzJ12P2dblXAxG7Wpo2J2xpf2-20210604010355.mp3"]
I/Capacitor/Console: File: http://localhost/tab1-tab1-module.js - Line 189 - Msg: Grabando
V/Capacitor/Plugin: To native (Cordova plugin): callbackId: INVALID, service: Media, action: startRecordingAudio, actionArgs: ["28dcbcf9-4453-bb1b-8faf-74c13e4ec29c","file:\/\/\/sdcard\/\/Download\/xZpEzJ12P2dblXAxG7Wpo2J2xpf2-20210604010355.mp3"]
W/System.err: java.io.FileNotFoundException: /storage/emulated/0/tmprecording-1622783035225.3gp: open failed: EPERM (Operation not permitted)
        at libcore.io.IoBridge.open(IoBridge.java:492)
W/System.err:     at java.io.RandomAccessFile.<init>(RandomAccessFile.java:289)
        at java.io.RandomAccessFile.<init>(RandomAccessFile.java:152)
        at android.media.MediaRecorder.prepare(MediaRecorder.java:1091)
        at org.apache.cordova.media.AudioPlayer.startRecording(AudioPlayer.java:161)
        at org.apache.cordova.media.AudioHandler.startRecordingAudio(AudioHandler.java:287)
        at org.apache.cordova.media.AudioHandler.promptForRecord(AudioHandler.java:543)
        at org.apache.cordova.media.AudioHandler.execute(AudioHandler.java:118)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:107)
W/System.err:     at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:51)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:183)
        at android.os.HandlerThread.run(HandlerThread.java:67)
    Caused by: android.system.ErrnoException: open failed: EPERM (Operation not permitted)
        at libcore.io.Linux.open(Native Method)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
W/System.err:     at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542)
        at libcore.io.IoBridge.open(IoBridge.java:478)
    	... 15 more

and, whe stopRecord() is called:

V/Capacitor/Plugin: To native (Cordova plugin): callbackId: INVALID, service: Media, action: stopRecordingAudio, actionArgs: ["28dcbcf9-4453-bb1b-8faf-74c13e4ec29c"]
I/Capacitor/Console: File: http://localhost/tab1-tab1-module.js - Line 199 - Msg: Grabacion terminada
E/AudioPlayer: /storage/emulated/0/tmprecording-1622783035225.3gp: open failed: ENOENT (No such file or directory)
    java.io.FileNotFoundException: /storage/emulated/0/tmprecording-1622783035225.3gp: open failed: ENOENT (No such file or directory)
        at libcore.io.IoBridge.open(IoBridge.java:492)
        at java.io.FileInputStream.<init>(FileInputStream.java:160)
        at org.apache.cordova.media.AudioPlayer.moveFile(AudioPlayer.java:216)
        at org.apache.cordova.media.AudioPlayer.stopRecording(AudioPlayer.java:311)
        at org.apache.cordova.media.AudioHandler.stopRecordingAudio(AudioHandler.java:298)
        at org.apache.cordova.media.AudioHandler.execute(AudioHandler.java:121)
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98)
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132)
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:107)
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:51)
        at android.os.MessageQueue.nativePollOnce(Native Method)
        at android.os.MessageQueue.next(MessageQueue.java:335)
        at android.os.Looper.loop(Looper.java:183)
        at android.os.HandlerThread.run(HandlerThread.java:67)
     Caused by: android.system.ErrnoException: open failed: ENOENT (No such file or directory)
        at libcore.io.Linux.open(Native Method)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
        at libcore.io.BlockGuardOs.open(BlockGuardOs.java:254)
        at libcore.io.ForwardingOs.open(ForwardingOs.java:166)
        at android.app.ActivityThread$AndroidOs.open(ActivityThread.java:7542)
        at libcore.io.IoBridge.open(IoBridge.java:478)
        at java.io.FileInputStream.<init>(FileInputStream.java:160) 
        at org.apache.cordova.media.AudioPlayer.moveFile(AudioPlayer.java:216) 
        at org.apache.cordova.media.AudioPlayer.stopRecording(AudioPlayer.java:311) 
        at org.apache.cordova.media.AudioHandler.stopRecordingAudio(AudioHandler.java:298) 
        at org.apache.cordova.media.AudioHandler.execute(AudioHandler.java:121) 
        at org.apache.cordova.CordovaPlugin.execute(CordovaPlugin.java:98) 
        at org.apache.cordova.PluginManager.exec(PluginManager.java:132) 
        at com.getcapacitor.MessageHandler.callCordovaPluginMethod(MessageHandler.java:107) 
        at com.getcapacitor.MessageHandler.postMessage(MessageHandler.java:51) 
        at android.os.MessageQueue.nativePollOnce(Native Method) 
        at android.os.MessageQueue.next(MessageQueue.java:335) 
        at android.os.Looper.loop(Looper.java:183) 
        at android.os.HandlerThread.run(HandlerThread.java:67) 
V/Capacitor/Plugin: To native (Cordova plugin): callbackId: INVALID, service: Media, action: release, actionArgs: ["28dcbcf9-4453-bb1b-8faf-74c13e4ec29c"]

…and this creates a file in the directory, but it is a 0 byte audio file that cannot be opened.

I have read quite a few solutions, like:

but no one has served me, they all give me that damn error “callback: INVALID” and an audio file that cannot be opened with 0 bytes !!

Can anybody help me? I am desperate to find a solution to this problem :frowning:
Thanks in advance to everyone u.u

1 post - 1 participant

Read full topic


Viewing all articles
Browse latest Browse all 48981

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>