cordova-plugin-media icon indicating copy to clipboard operation
cordova-plugin-media copied to clipboard

Detection of missing microphone access permission

Open mario-van-zadel opened this issue 2 years ago • 2 comments

Feature Request

Motivation Behind Feature

When using the plugin for recording some audio, the user probably denied accessing the microphone (by using the operation system's permission system). Currently there seems to be no explicit way to detect his. onError doesn't inform the developer about the denied permission request.

Feature Description

When accessing the microphone, the user get's a permission request from by the OS. If the user denies the request, the onError observable should inform the user about the issue when trying to use the device's microphone.

Workaround

To detect issues with recording the audio, it's possible to check the media's status after e.g. 1 second. If there are some issues with starting the recording, the status stays at MEDIA_NONE (instead of switching to MEDIA_RUNNING).

this.mediaObject.onStatusUpdate.subscribe(status => {
    this.mediaObjectStatus = status;
});

this.mediaObject.startRecord();

// Check the media's status after 1 second.
setTimeout(() => {
    if (this.mediaObjectStatus === this.media.MEDIA_NONE) {
        alert('Recording failed. Please check the permissions for accessing the microphone');
    }
}, 1000);

mario-van-zadel avatar Jun 26 '22 09:06 mario-van-zadel

@mario-van-zadel setTimeout solution is not working, I need to use document.addEventListener('resume');

One more thing I found for android platform. I am using cordova-diagnostic-plugin to check diagnostic.getExternalStorageAuthorizationStatus.

First time: return NOT_REQUESTED Rejected 1 time: return DENIED_ONCE Rejected 2 time: return NOT_REQUESTED (it should be DENIED_ALWAYS) ** And app will never popup ask for permission even close and restart app.

If accepted: return GRANTED

sonicwong avatar Dec 02 '22 04:12 sonicwong

I'm having the same issue, but once permission is denied, the mediaObject does not do anything, I'm not able to get any subscriptions to fire (which may be intended?) I've tried

  • onStatusUpdate
  • successCallback
  • errorCallback
  • onSuccess
  • onError

The last two do work when permissions are granted. I was thinking about using getCurrentAmplitude (which resolves 0 when permissions not granted during record/play) to check if anything was happening, but not sure I like that or not.

PabbleDabble avatar Jun 13 '23 20:06 PabbleDabble