Вопрос

Right now, I'm getting information of the currently played song using:

MPMusicPlayerController *controller = [MPMusicPlayerController iPodMusicPlayer];

However, this only works for tracks that are actually playing through the iPod player.

I want to know if there is a way to get this same type of information from other apps that take over the iPod music player dock. Apps like Spotify, Downcast, Instacast, etc.

Это было полезно?

Решение 2

After further investigation, it seems that it is only possible to get the metadata from the iPod player.

Другие советы

Not exactly sure what you're looking for but you can probably get metadata from the actual files using AVURLAsset. I've used this to find metadata for mp3 and m4a files but there might be other formats available. See Docs for specifics.

AVURLAsset *asset = [[AVURLAsset alloc] initWithUrl:@"song.mp3" options:nil];
if (asset != nil)
{
    NSArray *formatArray = asset.availableMetadataFormats;
    if ([formatArray count] > 0)
    {
        NSArray *array = [asset metadataForFormat:[formatArray objectAtIndex:0];
        NSString *artist = @"";
        NSString *songTitle = @"";

        for (AVMetadataItem *metadata in array)
        {
             if ([metadata.commonKey isEqualToString:@"artist"])
                artist = metadata.stringValue;
             else if ([metadata.commonKey isEqualToString:@"title"])
                songTitle = metadata.stringValue;
             etc, ...
        }
     }
}
Лицензировано под: CC-BY-SA с атрибуция
Не связан с StackOverflow
scroll top