Logo Search packages:      
Sourcecode: taglib-sharp version File versions

static AttachedPictureFrame TagLib::Id3v2::AttachedPictureFrame::Get ( Tag  tag,
string  description,
PictureType  type,
bool  create 
) [inline, static]

Gets a specified picture frame from the specified tag, optionally creating it if it does not exist.

Parameters:
tag A Tag object to search in.
description A string specifying the description to match.
type A PictureType specifying the picture type to match.
create A bool specifying whether or not to create and add a new frame to the tag if a match is not found.
Returns:
A AttachedPictureFrame object containing the matching frame, or if a match wasn't found and create is .

Sets a cover image with a description. Because Get(Tag,string,PictureType,bool) is used, if the program is called again with the same audio file and desciption, the picture will be overwritten with the new one.

                using TagLib;
                using TagLib.Id3v2;

                public static class SetId3v2Cover
                {
                  public static void Main (string [] args)
                  {
                        if (args.Length != 3)
                              throw new ApplicationException (
                                    "USAGE: SetId3v2Cover.exe AUDIO_FILE PICTURE_FILE DESCRIPTION");

Create the file. Can throw file to TagLib# exceptions.
                        File file = File.Create (args [0]);

Get or create the ID3v2 tag.
                        TagLib.Id3v2.Tag tag = file.GetTag (TagTypes.Id3v2, true) as TagLib.Id3v2.Tag;
                        if (tag == null)
                              throw new ApplicationException ("File does not support ID3v2 tags.");

Create a picture. Can throw file related exceptions.
                        TagLib.Picture picture = TagLib.Picture.CreateFromPath (args [1]);

Get or create the picture frame.
                        AttachedPictureFrame frame = AttachedPictureFrame.Get (
                              tag, args [2], PictureType.FrontCover, true);

Set the data from the picture.
                        frame.MimeType = picture.MimeType;
                        frame.Data     = picture.data;

Save the file.
                        file.Save ();
                  }
                }

Definition at line 497 of file AttachedPictureFrame.cs.

References Description, and Type.

            {
                  AttachedPictureFrame apic;
                  foreach (Frame frame in tag.GetFrames (FrameType.APIC)) {
                        apic = frame as AttachedPictureFrame;
                        
                        if (apic == null)
                              continue;
                        
                        if (description != null && apic.Description != description)
                              continue;
                        
                        if (type != PictureType.Other && apic.Type != type)
                              continue;
                        
                        return apic;
                  }
                  
                  if (!create)
                        return null;
                  
                  apic = new AttachedPictureFrame ();
                  apic.Description = description;
                  apic.Type = type;
                  
                  tag.AddFrame (apic);
                  
                  return apic;
            }


Generated by  Doxygen 1.6.0   Back to index