-
Notifications
You must be signed in to change notification settings - Fork 321
Open
Description
Hello everyone, I'm trying to make an application for recording android audios through PCM files.
I'm getting this error "cannot open device 0 for card 1: Permission denied" when trying to use the pcm_open method.
Enabled permissions
private boolean isPermissionGranted() {
return ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.WRITE_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_EXTERNAL_STORAGE) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.RECORD_AUDIO) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CONTACTS) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_PHONE_STATE) == PackageManager.PERMISSION_GRANTED
&& ActivityCompat.checkSelfPermission(MainActivity.this, Manifest.permission.READ_CALL_LOG) == PackageManager.PERMISSION_GRANTED;
}
private void askPermission() {
ActivityCompat.requestPermissions(this, new String[]{
Manifest.permission.RECORD_AUDIO,
Manifest.permission.READ_EXTERNAL_STORAGE,
Manifest.permission.WRITE_EXTERNAL_STORAGE,
Manifest.permission.READ_CONTACTS,
Manifest.permission.READ_PHONE_STATE,
Manifest.permission.READ_CALL_LOG
}, REQUEST_PERMISSION_CODE);
}
For the read and write permissions of the files I tried to do it this way
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("chmod 777 /dev/snd/*\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
} catch(Exception e) {
}
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("chmod 777 -r /dev/snd\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
} catch(Exception e) {
}
try {
Process su = Runtime.getRuntime().exec("su");
DataOutputStream outputStream = new DataOutputStream(su.getOutputStream());
outputStream.writeBytes("chmod 777 -r /dev\n");
outputStream.flush();
outputStream.writeBytes("exit\n");
outputStream.flush();
su.waitFor();
} catch(Exception e) {
}
Here where I make the config assignments, and the card and device definition
int card = 1;
int device = 0;
struct pcm_config config;
struct pcm *pcm;
config.channels = 2;
config.rate = 44100;
config.period_size = 1024;
config.period_count = 4;
config.format = PCM_FORMAT_S16_LE;
config.start_threshold = 0;
config.stop_threshold = 0;
config.silence_threshold = 0;
pcm = pcm_open(card, device, PCM_IN, &config);
if (!pcm) {
...
} else {
std::string error = pcm_get_error(pcm);
__android_log_print(ANDROID_LOG_ERROR, "MyApp", "PCM not ready: %s\n", pcm_get_error(pcm));
}
Do you know if it is possible to capture the audios that way?
Do I need to configure something else?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels