4

I have a doubt I read these tutorials just to get the clear understanding of the SAF introduced in kitkat in higher version of android How to use the new SD card access API presented for Android 5.0 (Lollipop)?

How to persist permission in android API 19 (KitKat)?

Android API below 19 equivalent for ContentResolver takePersistableUriPermission

Android Gallery on KitKat returns different Uri for Intent.ACTION_GET_CONTENT

Now i have a question when the intent is fired and i get select the sd card to get the uritree from the intent which i am getting but is the root tree I will have to iterate through the uri to get the specific file uri. Now the question is I have mp3 files in my phone and I want to edit that specific file which is selected so how can i get that selected files uri from the tree and edit it?I tried editing directly using file but it makes my mp3 file disappear and i dont want to fire SAF intent again n again so how to check is user has given permission to sd card or not? P.S. I am using jaudio tagger for editing the tags of mp3 files. THANK YOU!! I have got answers of almost everything in this question Now the issue if I am using jaudio tagger library for tagging mp3 files which takes File as a objects but android 4.4 and above wont let u modify File objects so I just want to knw the alternative how can i edit File objects in 4.4 above?

Community
  • 1
  • 1
Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26
  • AFAIK jaudio tagger doen't accept a documentFile object. What do you mean by "I tried editing directly using file" ? Documents in a removable storage cannot be edited by File objects. – Malith Lakshan Jun 11 '16 at 04:33
  • i meant like this it changes the tags but first it disappears and when i restart my phone then it shows in my phone. AudioFile f = AudioFileIO.read(testFile); Tag tag = f.getTag(); tag.setField(FieldKey.ARTIST,"Kings of Leon"); f.commit(); – Reyansh Mishra Jun 11 '16 at 04:41
  • Reyansh, did you manage to get to the bottom of this? I face the same issue(s) using both jaudiotagger (for flac) and jid3 (for mp3) I know that jid3 actually creates a temporary file before it finally sync (writes) the mp3. Thi s process will fail on the external sdcard. – Theo Jun 05 '17 at 14:57
  • Yeah I have got it, once I am done with the proper code Ill answer it. It like your need to copy the external sd card file into the internal storage then edit it and place it again at its place you need to deal with DocumentFile little bit. If you just want to read the logic behind it have a look into https://github.com/timusus/Shuttle/tree/dev/app/src/main/java/com/simplecity/amp_library/tagger – Reyansh Mishra Jun 05 '17 at 16:17

2 Answers2

1

This is how I did it, first copy the file from the sdcard to the phone memory and then do the desired changes and cut and paste the file again at its original place. Example is here where I am editing the tag of mp3 file which is in the sdcard:-

https://github.com/reyanshmishra/Rey-MusicPlayer/tree/master/app/src/main/java/com/boom/music/player/TagEditor

Reyansh Mishra
  • 1,879
  • 1
  • 14
  • 26
0

The library you refer to is called JaudioTagger, and it does not and most probably will never accept DocumentFile. The Storage Access Framework is Google's invention and far from any standard. And JaudioTagger is written for portability.

However, I finally managed to get JaudioTagger mostly running with SAF, but had to substantially modify it, even to rewrite some functions. Basically I replaced all File and RandomAccessFile with my own classes, and additionally the handling of temporary files and renaming must be rewritten (e.g. the scheme: copy original file, change copy, remove original file, rename copy to original name).

In fact it might be easier to use the native TagLib instead, because that already accepts a special C++ class as input. All I did was to create such C++ class whose basis is a file descriptor derived from ParcelFileDescriptor derived from Uri derived from DocumentFile.

Finally one might come to the conclusion that the Storage Access Framework is somewhat suboptimal.