read mp3 id3 tags

July 29, 2012   ·   0 Comments

Screen Shot 2012-07-29 at 1.16.14 PM
It's not possible with remote mp3 file... :(
i try all the day, nothing working,
local file working, great.
-(void)Fun_mp3{

    /*
    NSString *audioFilePath = [[NSString stringWithUTF8String:@"a1.mp3"]
                               stringByExpandingTildeInPath];        // 2
    NSURL *audioURL2 = [NSURL fileURLWithPath:audioFilePath];      // 3
    */

    NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"a1" ofType:@"mp3"];
    NSURL *audioURL = [NSURL fileURLWithPath:urlPath];
 //   NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
 //   [webViewOutlet loadRequest:urlRequest];

    AudioFileID audioFile;                                        // 4
    OSStatus theErr = noErr;                                      // 5
    theErr = AudioFileOpenURL((CFURLRef)audioURL,
                              kAudioFileReadPermission,
                              0,
                              &audioFile);                        // 6
    assert (theErr == noErr);                                     // 7
    UInt32 dictionarySize = 0;                                    // 8
    theErr = AudioFileGetPropertyInfo (audioFile,
                                       kAudioFilePropertyInfoDictionary,
                                       &dictionarySize,
                                       0);                        // 9
    assert (theErr == noErr);                                     // 10
    CFDictionaryRef dictionary;                                   // 11
    theErr = AudioFileGetProperty (audioFile,
                                   kAudioFilePropertyInfoDictionary,
                                   &dictionarySize,
                                   &dictionary);                  // 12
    assert (theErr == noErr);                                     // 13
    NSLog (@"dictionary: %@", dictionary);                        // 14
    CFRelease (dictionary);                                       // 15
    theErr = AudioFileClose (audioFile);                          // 16
    assert (theErr == noErr);                                     // 17

}

-(void)Fun_mp3{

    /*
    NSString *audioFilePath = [[NSString stringWithUTF8String:@"a1.mp3"]
                               stringByExpandingTildeInPath];        // 2
    NSURL *audioURL2 = [NSURL fileURLWithPath:audioFilePath];      // 3
    */

    NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"a1" ofType:@"mp3"];
    NSURL *audioURL = [NSURL fileURLWithPath:urlPath];

    AudioFileID audioFile;                                        // 4
    OSStatus theErr = noErr;                                      // 5
    theErr = AudioFileOpenURL((CFURLRef)audioURL,
                              kAudioFileReadPermission,
                              0,
                              &audioFile);                        // 6
    assert (theErr == noErr);                                     // 7
    UInt32 dictionarySize = 0;                                    // 8
    theErr = AudioFileGetPropertyInfo (audioFile,
                                       kAudioFilePropertyInfoDictionary,
                                       &dictionarySize,
                                       0);                        // 9
    assert (theErr == noErr);                                     // 10
    CFDictionaryRef dictionary;                                   // 11
    theErr = AudioFileGetProperty (audioFile,
                                   kAudioFilePropertyInfoDictionary,
                                   &dictionarySize,
                                   &dictionary);                  // 12
    assert (theErr == noErr);                                     // 13
    NSLog (@"dictionary: %@", dictionary);                        // 14

 //   NSDictionary * powerDic = (NSDictionary *)IOPSGetPowerSourceDescription(array, r);
    NSString * album = [dictionary objectForKey:@"album"];
    NSLog (@"album: %@", album);
    NSString * artist = [dictionary objectForKey:@"artist"];
    NSLog (@"artist: %@", artist);
    NSString * genre = [dictionary objectForKey:@"genre"];
    NSLog (@"genre: %@", genre);
    NSString * title = [dictionary objectForKey:@"title"];
    NSLog (@"title: %@", title);
    NSString * year = [dictionary objectForKey:@"year"];
    NSLog (@"year: %@", year);

    CFRelease (dictionary);                                       // 15
    theErr = AudioFileClose (audioFile);                          // 16
    assert (theErr == noErr);                                     // 17

}

on ARC and remote mp3

-(void)Fun_mp3:(NSString*) i_songURL{
    NSString  *filePath;
    NSString *stringURL =i_songURL;
    NSURL  *url = [NSURL URLWithString:stringURL];
    NSData *urlData = [NSData dataWithContentsOfURL:url];
    if ( urlData )
    {
        NSArray       *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString  *documentsDirectory = [paths objectAtIndex:0];

        filePath = [NSString stringWithFormat:@"%@/%@", documentsDirectory,@"temp.mp3"];
        [urlData writeToFile:filePath atomically:YES];
    }

 //   NSString *urlPath = [[NSBundle mainBundle] pathForResource:@"a1" ofType:@"mp3"];
    NSURL *audioURL = [NSURL fileURLWithPath:filePath];
    //   NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
    //   [webViewOutlet loadRequest:urlRequest];

    AudioFileID audioFile;                                        // 4
    OSStatus theErr = noErr;                                      // 5
    theErr = AudioFileOpenURL((__bridge CFURLRef)audioURL,
                              kAudioFileReadPermission,
                              0,
                              &audioFile);                        // 6
    assert (theErr == noErr);                                     // 7
    UInt32 dictionarySize = 0;                                    // 8
    theErr = AudioFileGetPropertyInfo (audioFile,
                                       kAudioFilePropertyInfoDictionary,
                                       &dictionarySize,
                                       0);                        // 9
    assert (theErr == noErr);                                     // 10
    CFDictionaryRef dictionary;                                   // 11
    theErr = AudioFileGetProperty (audioFile,
                                   kAudioFilePropertyInfoDictionary,
                                   &dictionarySize,
                                   &dictionary);                  // 12
    assert (theErr == noErr);                                     // 13
    NSLog (@"dictionary: %@", dictionary);                        // 14

  //  NSLog (@"dictionary: %@", dictionary);                        // 14

    //   NSDictionary * powerDic = (NSDictionary *)IOPSGetPowerSourceDescription(array, r);
    NSString * album = [(__bridge NSDictionary*)dictionary objectForKey:@"album"];
    albumLabel.text=album;
    NSLog (@"album: %@", album);
    NSString * artist = [(__bridge NSDictionary*)dictionary objectForKey:@"artist"];
    NSLog (@"artist: %@", artist);
    artistLabel.text=artist;

    NSString * genre = [(__bridge NSDictionary*)dictionary objectForKey:@"genre"];
    NSLog (@"genre: %@", genre);
    NSString * title = [(__bridge NSDictionary*)dictionary objectForKey:@"title"];
    NSLog (@"title: %@", title);
    titleLabel.text=title;

    NSString * year = [(__bridge NSDictionary*)dictionary objectForKey:@"year"];
    NSLog (@"year: %@", year);

    CFRelease (dictionary);                                       // 15

    theErr = AudioFileClose (audioFile);                          // 16
    assert (theErr == noErr);                                     // 17

}

http://d.hatena.ne.jp/terazzo/20120107/1325967445

shareShare on FacebookShare on Google+Share on LinkedInEmail this to someonePrint this pageBuffer this pageDigg thisFlattr the authorShare on RedditPin on PinterestShare on StumbleUponShare on TumblrTweet about this on Twitter

By


Readers Comments (0)


You must be logged in to post a comment.

PowenKo’s Online Store

powenko_arduinoBook
iOS Tutorial9

Amazon

adsbygoogle

Recent Posts

Categories

Amazon