用OBJC写ID3标签

时间:2016-02-29 03:59:31

标签: ios objective-c macos tags id3

所以我需要将新的ID3标签写入音频文件。我尝试使用2种方法。

第一

我使用的是Core Audio,只能读取标签,比如

-(void)getInformationAudioFile {
//get title and artist information audio file

//read raw ID3Tag size
UInt32 id3DataSize = 0;
char *rawID3Tag = NULL;
AudioFileGetPropertyInfo(inputFile,
                         kAudioFilePropertyID3Tag,
                         &id3DataSize,
                         NULL);

rawID3Tag = (char *)malloc(id3DataSize);

//read raw ID3Tag
AudioFileGetProperty(inputFile,
                     kAudioFilePropertyID3Tag,
                     &id3DataSize,
                     rawID3Tag);

CFDictionaryRef piDict = nil;
UInt32 piDataSize = sizeof(piDict);

//this key returns some other dictionary, which works also in iPod library
AudioFormatGetProperty(kAudioFormatProperty_ID3TagToDictionary,
                       id3DataSize,
                       rawID3Tag,
                       &piDataSize,
                       &piDict);

free(rawID3Tag);

NSDictionary *tagsDictionary = (__bridge NSDictionary*)piDict;

NSLog (@"dictionary: %@", tagsDictionary);

self->_title = [tagsDictionary objectForKey:@"TIT2"];
if(!self.title)
    self->_title = self.url.path.lastPathComponent.stringByDeletingPathExtension;

self->_artist = [tagsDictionary objectForKey:@"TPE1"];
if(!self.artist)
    self->_artist = @"Unknown artist";

self->_album = [tagsDictionary objectForKey:@"TALB"];
if(!self.album)
    self->_album = @"Unknown album";

self->_genre = [tagsDictionary objectForKey:@"TCON"];
if(!self.genre)
    self->_genre = @"Unknown genre";

self->_year = [tagsDictionary objectForKey:@"TYER"];
if(!self.year)
    self->_year = @"Unknown year";

CFRelease(piDict); }

我不知道如何更改文件标记。

第二

所以我找到了使用TagLib的另一种方法 我找到了很多例子,其中有人使用这个库和objc读取文件。并没有找到如何编写标签的例子。

所以我想知道如何编写ID3标签?

抱歉我的英文。

0 个答案:

没有答案