1

現在プレイ中の情報を知りたいです。

したがって、次のコードは次のとおりです。

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;
    }
}

しかし、このコードは Defautl iPod アプリケーションから再生中の情報を取得できます。

サードパーティの音楽アプリで再生中の情報を取得するには? (例: モバイル Safari、Youtube アプリ、gMusic、Melodies など)。

4

1 に答える 1

1

これはありえないと思います。ドキュメントには、MPNowPlayingInfoCenter はロック画面の情報を設定するためだけのものであると記載されています。

ここに関連する質問があります。

于 2012-09-21T08:54:36.827 に答える