[vorbis-dev] Reading tags (again)...

Scott Wheeler scott at slackorama.net
Sun Nov 11 21:16:50 PST 2001



Ok, so I finally got the id3/mp3 end of things worked out for the next 
release of QTagger and I'm back to implementing tag reading for Ogg Vorbis.  

I've got some code that will read tags, but I haven't been able to figure out 
how to write them.  Here's the code that I'm using.  It's a fine C/C++ mix.  
The code will eventually be in a C++ app, so I don't mind throwing in some 
C++'isms.
===
#include <iostream.h>
#include <vorbis/vorbisfile.h>

int main()
{
  FILE *fp;
  OggVorbis_File *ovFile;
  vorbis_comment *ovComment;

  //  ovFile=malloc(sizeof(OggVorbis_File));
  ovFile=new OggVorbis_File;
  
  fp=fopen("foo.ogg","rw");
  ov_open(fp,ovFile,NULL,0);

  ovComment=ov_comment(ovFile,-1);
  if(ovComment->user_comments)
    {
      printf("has comments - %i\n",ovComment->comments);
      for(int i=0;i<ovComment->comments;i++)
        {
          cout << ovComment->user_comments[i] << endl;
        }
      //      vorbis_comment_add_tag(ovComment, "title", "Cheese Bar");
      //      ovComment->user_comments[0]="title=Cheese Bar";
    }
  else
    {
      printf("doesn't have comments\n");
    }

  //  ov_clear(ovFile);
  fclose(fp);
  
  return(0);
}
===

So, this reads things just fine.  And, yes, I know it's ugly.  I don't care 
at the moment.  The two commented out lines:

// vorbis_comment_add_tag(ovComment, "title", "Cheese Bar");
// ovComment->user_comments[0]="title=Cheese Bar";

Do little more than cause seg faults.  I found the undocumented function 
vorbis_comment_add_tag() and hoped to do something useful with it.  It seems 
that I can update the tags, but can't write them back to the files.

Oh, and if sufficiently prodded, once I get this all done, I may come up with 
a mini-howto for external taggers.

Thanks!

-Scott Wheeler

--- >8 ----
List archives:  http://www.xiph.org/archives/
Ogg project homepage: http://www.xiph.org/ogg/
To unsubscribe from this list, send a message to 'vorbis-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Vorbis-dev mailing list