Hi Dave,
Below is the Java code I use, with no effective deletion wether the file being in private folder or Music one (/storage/emulated/0/Music/ or /sdcard/Music/).
I checked from the plugin I have the permissions READ_EXTERNAL_STORAGE and WRITE_EXTERNAL_STORAGE (but I don't have MANAGE_MEDIA).
As you see I try 3 times with different methods (this is just one of my many tries):
// ====================================================================
private String DeleteFile(Bundle b) throws Exception {
String path = b.getString("p1");
File file = new File(path);
file.delete();
if(file.exists()){
file.getCanonicalFile().delete();
if(file.exists()){
m_ctx.deleteFile(file.getName());
}
}
if (file.exists())
return "Failed";
else
return "Success";
}
// ====================================================================
I have to do this because I noticed that file deletion takes about 100 ms + (files_in_dir * 10ms). So deleting a file in a folder with 1000, will take about 10 seconds. I don't have access to DS code, so why this delay when other apps delete files without any delay, whatever the number of files in the same directory ?
On a side note those calls could be optimized :
- ListFolder: I get 50x speedup in java (see the code below)
- IsFolder : I get only 2.5x speedup
- GetMetaData (see code below) : same speed for one call but given that app.GetMetaData returns a string, with comma delimited result, it is not possible to split the result correctly when there is already commas in the artist, title, etc. So I return a JSON string that is easy to parse. That way I save 30 ms per extra tag fetched (because i only make one call, when with app.GetMetaData I have to make one different call for each tag).
// ====================================================================
private String ListFolder(Bundle b) throws Exception {
Log.d(TAG, "Got ListFolder");
String dir = b.getString("p1");
File directory = new File(dir);
File[] files = directory.listFiles();
ArrayList<String> paths = new ArrayList();
for (File f : files) {
paths.add(f.getPath());
}
JSONArray jsonArray = new JSONArray(paths);
String s = jsonArray.toString();
return s;
}
// ====================================================================
private String GetMetaData(Bundle b) throws JSONException {
String path = b.getString("p1");
MediaMetadataRetriever retriever = new MediaMetadataRetriever();
retriever.setDataSource(path);
String artist = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ARTIST);
String title = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_TITLE);
String album = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_ALBUM);
String duration = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_DURATION);
String bitrate = retriever.extractMetadata(MediaMetadataRetriever.METADATA_KEY_BITRATE);
JSONObject json = new JSONObject();
json.put("artist", artist);
json.put("title", title);
json.put("album", album);
json.put("artist", artist);
json.put("duration", duration);
json.put("bitrate", bitrate);
return json.toString();
}
// ====================================================================
Greetings
Pascal G.