문제

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