IOS: get file metadata

I have an mp3 file on the server. I want to get this information about the file, like the size of this file, artist name, album name, when the file was created, when it was changed, etc. I want all this information.

Is it possible to get this information without actually downloading the entire file? Using NSURLConnectionor otherwise?

EDIT:

The following code does not give me the required information, that is, a file created by the name of the artist, etc.

    NSError *rerror = nil;
    NSURLResponse *response = nil;

    NSURL *url = [NSURL URLWithString:@"http://link.to.mp3"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];
    [request setHTTPMethod:@"HEAD"];

    NSData *result = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&rerror];
    NSString *resultString = [[[NSString alloc] initWithData:result encoding:NSUTF8StringEncoding] autorelease];

    NSLog(@"URL: %@", url);
    NSLog(@"Request: %@", request);
    NSLog(@"Result (NSData): %@", result);
    NSLog(@"Result (NSString): %@", resultString);
    NSLog(@"Response: %@", response);
    NSLog(@"Error: %@", rerror);

    if ([response isMemberOfClass:[NSHTTPURLResponse class]]) {
        NSLog(@"AllHeaderFields: %@", [((NSHTTPURLResponse *)response) allHeaderFields]);
    }

"AllHeaderFields":

AllHeaderFields: {
    "Cache-Control" = "max-age=0";
    Connection = "keep-alive";
    "Content-Encoding" = gzip;
    "Content-Type" = "text/plain; charset=ascii";
    Date = "Fri, 17 Feb 2012 12:44:59 GMT";
    Etag = 19202n;
    Pragma = public;
    Server = dbws;
    "x-robots-tag" = "noindex,nofollow";
}
+5
source share
3 answers

Yes and no. Things like file size and modification date are often part of the HEAD response. But not always: with lots of dynamic URLs you won’t get all the information.

, MP3 ID3, , HEAD. ID3 , , ID3. NSURLConnection, , HTTP.

+1

ID3, MP3 ( , ) API. AVFoundation.

- AVAsset , , AVURLAsset. AVAsset NSArray commonMetadata. commonMetadata AVMetadataItem, , , URL- . AVMetadataItem commonKey . commonKeys , NSDictionary, commonKey key value object. :

-(NSDictionary *)dictionaryOfMetadataFromAsset:(AVAsset *)asset{
    NSMutableDictionary *metaData = [[NSMutableDictionary alloc] init];
    for (AVMetadataItem *item in asset.commonMetadata) {
        if (item.value && item.commonKey){
            [metaData setObject:item.value forKey:item.commonKey];
        }
    }
    return [metaData copy];
}

AVAsset . MP3 URL-:

NSURL *mp3URL = [NSURL URLWithString:@"http://'AddressOfMP3File'"];
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:mp3URL options:nil];
NSDictionary *metaDict = [self dictionaryOfMetadataFromAsset:asset];
NSLog(@"Available Metadata :%@",metaDict.allKeys);
NSLog(@"title:%@",[metaDict objectForKey:@"title"]);

, MP3 . , ; . AVURLAsset , .

AVAsset, AVPlayerItem AVPlayer .

+4

, NSURLConnection.

, HEAD , , , connection:didReceiveResponse: connection:didReceiveData:

Admittedly, I have not read your entire question. It is not possible to get ID3 information, but you should be able to get the file size and possibly the creation date, etc.

This answer gives good information on how to get ID3 information. You will need to set up a php page to examine the server side mp3 file and return exactly this information that you need, and not the whole mp3.

+2
source

All Articles