jaudiotagger POPULARIMETER tag

351 Views Asked by At

I am migrating my app from using org.blinkenlights.jid3 to jaudiotagger. I have successfully implemented most of the mp3 tags but am struggling with the POPM tag. I am trying to read the POPM by gettting the frame. It appears to be the correct method as the code recongnises the three methods

(Long irating = popmframe.getRating();
Long cnt = popmframe.getCounter();
String mail = popmframe.getEmailToUser()). 

What should I put in the brackets FrameBodyPOPM popmframe = id3v24tag.getFrame( );. Using JID3 I achieved the result as follows:

try {

                ID3V2_3_0Tag ID3V2_3_0Tag =     (org.blinkenlights.jid3.v2.ID3V2_3_0Tag) MediaFile.getID3V2Tag();
                if (null != ID3V2_3_0Tag) {
                    for (int i = 0; i < ID3V2_3_0Tag.getPOPMFrames().length; i++) {
                        if (ID3V2_3_0Tag.getPOPMFrames()[i] != null) {
                            rating = ID3V2_3_0Tag.getPOPMFrames()[i].getPopularity();
                            break;
                        }
                    }
                }
                rating = rating / 50;
            } catch (ID3Exception e) {
                e.printStackTrace();
            }

using jaudiotagger I have so far the following code:

          try {
        MP3File musicFile = (MP3File) AudioFileIO.read(SourceFile);

        if (musicFile != null && musicFile.hasID3v2Tag()) {
            ID3v24Tag id3v24tag = musicFile.getID3v2TagAsv24();
            FrameBodyPOPM popmframe = id3v24tag.getFrame(??????);
            Long irating = popmframe.getRating();
            Long cnt = popmframe.getCounter();
            String mail = popmframe.getEmailToUser();

        }
    } catch (CannotReadException | IOException | TagException
            | ReadOnlyFileException | InvalidAudioFrameException e5) {
        throw e5;
    }

For the question marks it reports String but when I enter a string such as "POPM" it reports required: org.jaudiotagger.tag.id3.framebody FramebodyPOPM , found java.lang.Object

Anybody who can show how to read and write the POPM tag using jaudiotagger library?

update: I believe that the value should be a frame identifier so

FrameBodyPOPM popmframe = (FrameBodyPOPM) id3v24tag.getFrame(ID3v24Frames.FRAME_ID_POPULARIMETER);

compiles but results in an error:

java.lang.ClassCastException: org.jaudiotagger.tag.id3.ID3v24Frame cannot be cast to org.jaudiotagger.tag.id3.framebody.FrameBodyPOPM

But if I make popmframe an ID3v24Frame, the 3 methods are no longer available so I think the FrameBodyPOPM is the correct way.

1

There are 1 best solutions below

2
On

Resolved the issue. below code works as expected.

         try {
        MP3File musicFile = (MP3File) AudioFileIO.read(SourceFile);

        if (musicFile != null && musicFile.hasID3v2Tag()) {
            ID3v23Frame frame = (ID3v23Frame) musicFile.getID3v2Tag().getFrame(ID3v24Frames.FRAME_ID_POPULARIMETER);
            FrameBodyPOPM body = (FrameBodyPOPM) frame.getBody();
            String mail = body.getEmailToUser();
            Long irating = body.getRating();
            Long cnt = body.getCounter();
        }
    } catch (CannotReadException | IOException | TagException
            | ReadOnlyFileException | InvalidAudioFrameException e5) {
        throw e5;
    }