1

I want to get nowplaying infomation.

So, following this code:

NSDictionary *info = [[MPNowPlayingInfoCenter defaultCenter] nowPlayingInfo];
NSString *title = [info valueForKey:MPMediaItemPropertyTitle];
NSLog(@"%@",title);
MPMusicPlayerController *pc = [MPMusicPlayerController iPodMusicPlayer];
MPMediaItem *playingItem = [pc nowPlayingItem];
if (playingItem) {
    NSInteger mediaType = [[playingItem valueForProperty:MPMediaItemPropertyMediaType] integerValue];
    if (mediaType == MPMediaTypeMusic) {
        NSString *songTitle = [playingItem valueForProperty:MPMediaItemPropertyTitle];
        NSString *albumTitle = [playingItem valueForProperty:MPMediaItemPropertyAlbumTitle];
        NSString *artist = [playingItem valueForProperty:MPMediaItemPropertyArtist];
        NSString *genre = [playingItem valueForProperty:MPMediaItemPropertyGenre];
        TweetTextField.text = [NSString stringWithFormat:@"#nowplaying %@ - %@ / %@ #%@", artist, songTitle, albumTitle,genre];
        MPMediaItemArtwork *artwork = [playingItem valueForProperty:MPMediaItemPropertyArtwork];
        CGSize newSize = CGSizeMake(250, 250);
        UIGraphicsBeginImageContext(newSize);
        [[artwork imageWithSize:CGSizeMake(100.0, 100.0)] drawInRect:CGRectMake(0, 0, newSize.width, newSize.height)];
        UIImage* newImage = UIGraphicsGetImageFromCurrentImageContext();
        UIGraphicsEndImageContext();
        _imageView.image = newImage;
    }
    if (_imageView.image == nil){
    } else {
        _tableView.alpha=0.5;
    }
}

But this code can get nowplaying infomation from Defautl iPod Application.

How to get nowplaying infomation in Thirdparty music application? (e.g.: Mobile Safari, Youtube App, gMusic, Melodies etc).

4

1 回答 1

1

I think this isn't possible. The documentation states that MPNowPlayingInfoCenter is only for setting information on the lock screen.

Here is a related question.

于 2012-09-21T08:54:36.827 回答