简体   繁体   中英

Cordova 6.5.0 fails recording audio using cordova-plugin-media FAILED renaming /storage/emulated/0/tmprecording-1489806941198.3gp

I'm trying to record audio using cordova-plugin-media on Cordova 6.5.0. When I run the method it returns me as 'OK' and calls the success callback function, but when this function tries to get the file, the file doesn't exists.

If I just specify the filename the file is placed at /storage/emulated/0/filename.mp3 but this path is inaccessible to the application. So, when I specify to save using cordova.file.cacheDirectory as reference, it fires an error on the background, but in javascript interface, it still calling the success callback function.

Taking a look at logcat, I found something like this:

E AudioPlayer: FAILED renaming /storage/emulated/0/tmprecording-1489806941198.3gp to /data/user/0/com.app/cache/recordedData-23-58cca65df12bf.mp3

I've been searching around internet and I found similar errors related to Cordova 3.5.0 as being a BUG but I'm using Cordova 6.5.0, may the BUG still happening?

Also I already checked app's privileges and all needed privileges are already granted. For example:

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

I've tried using cordova.file.dataDirectory instead cordova.file.cacheDirectory , but I still having no success.

Here goes a piece of the code:

 audioCtx = new Media(
            cordova.file.cacheDirectory + currentMediaFile,
            uploadMediaCapture
        );
        //console.log("Recording audio.");
        audioCtx.startRecord();

Anyone got any clue about how to solve this issue?

Android can not move the file from /storage to /data The silly part is that moveFile method does not return false if the files can't be moved therefore the Success callback is still called.

So the solution is to replace cordova.file.cacheDirectory with cordova.file.externalCacheDirectory or cordova.file.externalDataDirectory

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM