Mp4s can end up with two types of genre

Issue #48 closed
IJabz repo owner created an issue

From https://java.net/jira/browse/JAUDIOTAGGER-442

With Mp4s obviously there is a distinction between "valid" and custom genres.

If I start off with a track with a valid genre like "Ethnic" and want to change this into a custom genre like "myOwnGenre" I run into a problem, if I use the generic FieldKey:

I write the custom genre with au.getTag().setField(FieldKey.GENRE, "myOwnGenre"); au.commit(); Now I have 2 genres in the file, because jaudiotagger added a Mp4TagTextField withoug removing the old Mp4GenreField. That's not really what I intended. I wanted to replace it, not add it. The problem shows when I retrieve the genre with String s = au.getTag().getFirst(FieldKey.GENRE); because I get the valid genre and not my newly set custom genre.

Of course I can access the custom genre with String s = au.getTag().getFirst(Mp4FieldKey.GENRE_CUSTOM.getFieldName()); but that's illogical and contradictory to the generic approach.

Comments (2)

  1. IJabz reporter

    This may be an old issue because the setField() code does currently delete other genre field

    public void setField(FieldKey genericKey, String value) throws KeyNotFoundException, FieldDataInvalidException
        {
            TagField tagfield = createField(genericKey,value);
    
            if(genericKey==FieldKey.GENRE)
            {
                if(tagfield.getId().equals(GENRE.getFieldName()))
                {
                    this.deleteField(Mp4FieldKey.GENRE_CUSTOM);
                }
                else if(tagfield.getId().equals(GENRE_CUSTOM.getFieldName()))
                {
                    this.deleteField(Mp4FieldKey.GENRE);
                }
            }
            setField(tagfield);
        }
    

    but now added test to proof it

    however there is a related bug in deleteField(FieldKey genericKey) that meant only one of the fields was being deleted so fixed and added test for that as well.

        else if(genericKey == FieldKey.GENRE)
        {
            super.deleteField(Mp4FieldKey.GENRE.getFieldName());
            super.deleteField(Mp4FieldKey.GENRE_CUSTOM.getFieldName());
        }
    
  2. Log in to comment