【问题标题】:How to get nowplaying infomation in Thirdparty music application?如何在第三方音乐应用程序中获取现在播放信息?
【发布时间】:2012-08-18 11:00:16
【问题描述】:

我想获取正在播放的信息。

所以,按照以下代码:

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

但是这段代码可以从默认的 iPod 应用程序中获取正在播放的信息。

如何在第三方音乐应用程序中获取正在播放的信息? (例如:Mobile Safari、Youtube App、gMusic、Melodies 等)。

【问题讨论】:

    标签: objective-c ios mpmusicplayercontroller mpnowplayinginfocenter


    【解决方案1】:

    我认为这是不可能的。 documentation 声明 MPNowPlayingInfoCenter 仅用于设置锁屏信息。

    这里是a related question

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-10-03
      • 1970-01-01
      相关资源
      最近更新 更多