MP3 not creating v2 tag because already has v1 tag, not clear from api

Issue #146 open
Wang Pei created an issue

this issue occur when run it as java app on ubuntu 14.04 ;file title tag display "黑白配" on computer, but output "ºÚ°×Åä" on console .

File file = new File("/home/letv/Desktop/范玮琪 - 黑白配.mp3");
            if(file.exists()){
                AudioFile afile = AudioFileIO.read(file);
                Tag tag = afile.getTag();
                if (tag == null) {
                    tag = afile.createDefaultTag();
                    afile.setTag(tag);
                }
                System.out.println("title:"+tag.getValue(FieldKey.TITLE,
0));

            }

console:
             title:ºÚ°×Åä

Comments (16)

  1. IJabz repo owner

    I think that is simply because System.out will default to 8-bit character set and therefore cannot handle such characters

  2. Wang Pei reporter

    hi ijabz I think this problem is may not related to system.out.println;because i reproduce this problem when textView.settext(tag..getValue(FieldKey.TITLE,0)) and system.out.println on android, i think it may be relate to this song file or audioFile.commit(), there is my test code and result(test song file is same ):

    TagOptionSingleton.getInstance.setAndroid(true);
    
     if(file.exists()){
                    AudioFile afile = AudioFileIO.read(file);
                    Tag tag = afile.getTag();
                    if (tag == null) {
                        tag = afile.createDefaultTag();
                        afile.setTag(tag);
                    }
                  tag.setField(FieldKey.TITLE,好好学习);
                  afile.commit();
                 System.out.println(“####edit song### title:"+tag.getValue(FieldKey.TITLE,
                               0)+”  len:”+tag.getValue(FieldKey.TITLE,0).getBytes().length);
                              tag = AudioFileIO.read(file).getTag();
                              System.out.println("####edit song###
     title:"+tag.getValue(FieldKey.TITLE,0)+  len:+tag.getValue(FieldKey.TITLE,0).getBytes().length
    );
                }
    
    logcat:
             ####edit song### title:好好学习  len:12
              ####edit song### title:}}f'  len:4
    

    the result show that tag.getValue(field) is deferent before and after audioFile.commit()

  3. Wang Pei reporter

    hi ijabz i want to consulte u for ew doubts. if this issue is encoding format, which character do you use on commit and how can i get the character, or do i need to set encode format by tag.setEncoding(Charset)?

  4. Wang Pei reporter

    I tried again to use getBytes("UTF-8"), but the result is the same. then i use 'tag.setField(FieldKey.TITLE,new String(”好好学习”.getBytes("UTF-8"),"UTF-8")' ,and the result is the same.

  5. IJabz repo owner

    I found the problem your file already contains an ID3v tag but not an ID3v2 tag, so afile.getTag() returns the ID3v1 tag rather than null. But ID3v1 only supports ASCII so is unable to store the value properly. I can see this is confusing but Im not sure it is a bug, but if you change your code to

    Tag tag = afile.getTagOrCreateDefault();
    

    it will work because this will create a V2 tag if one missing regardless of whether or not thee is already a V1 tag.

  6. IJabz repo owner

    On 27/06/2016 10:23, wangpei wrote:

    It worked for me with your test file, if you cant get it working plese post your new code.

    Paul

  7. Wang Pei reporter

    hi ijabz

    your solution is ok.

                    AudioFile afile = AudioFileIO.read(file);
                    Tag tag = afile. getTagOrCreateDefault();
                    afile.setTag(tag); 
                    tag.setField(FieldKey.TITLE,好好学习);
                    afile.commit();
    

    but there is still some problem

    1.the Original file show title correct on ubuntu、mediastore of android (display “黑白配"),but garbled on mac、tag.getValue(FieldKey.TITLE,0)(display “ºÚ°×Åä").

    2.after add a ID3v2 tag,show title correct on mediastore of android 、mac、tag.getValue(FieldKey.TITLE,0). the file maybe have tow tag(v1&v2 tag),usually the platform will decode v2 tag, but there is a non-unified problem. of course ,this maybe is not a problem.

    anyway ,you have solved my problem by adding v2tag to modify id3 tag,thank you for your kind and solutions.

  8. Wang Pei reporter

    byte length of title is 6, so when u click on the right mouse button and select audio of properties on ubuntu,maybe it decode as “GBK"(charset for chinese),so show correct “黑白配”, but same option on mac or tag.getvalue,it decode as "iso-8859-1”, so show “ºÚ°×Åä". the file save id3tagv1 as GBK , but there is no sign show that ID3 is saved by GBK in id3tagv1 of the file. Or can only say: ubuntu is very good or by chance to correct decoding

  9. Log in to comment