如何在iOS中更新歌曲名称shoutcast?

时间:2015-04-22 19:02:55

标签: ios streaming shoutcast

我正在尝试为Shoutcast上的电台创建一个iphone应用。我正在使用streamingkit(https://github.com/tumtumtum/StreamingKit)来播放音乐,但我不确定如何获得当前歌曲和艺术家名称。有没有人曾经这样做过或知道如何准确地获得歌曲名称和艺术家?

修改:立即尝试https://github.com/AlvaroFranco/AFSoundManager

2 个答案:

答案 0 :(得分:1)

你应该为你的玩家注册一个KVO

[playerItem addObserver:self forKeyPath:@"timedMetadata" options:NSKeyValueObservingOptionNew context:nil];

然后像这样使用它来更新UI:

- (void) observeValueForKeyPath:(NSString*)keyPath ofObject:(id)object change:(NSDictionary*)change context:(void*)context {
    if ([keyPath isEqualToString:@"timedMetadata"])
    {
        AVPlayerItem* playerItem = object;

        for (AVMetadataItem* metadata in playerItem.timedMetadata)
        {
            //Assign metadata to nsstring info
            NSString *info = [NSString stringWithFormat:@"%@", metadata.stringValue];
            MPMediaItemArtwork *albumArt = [[MPMediaItemArtwork alloc] initWithImage:[UIImage imageNamed:@"poster.png"]];

            NSMutableDictionary *nowPlayingInfo = [[NSMutableDictionary alloc] init];
            [nowPlayingInfo setObject:[NSString stringWithFormat:@"Now playing - %@", info] forKey:MPMediaItemPropertyArtist];
            [nowPlayingInfo setObject:info forKey:MPMediaItemPropertyTitle];
            [nowPlayingInfo setObject:albumArt forKey:MPMediaItemPropertyArtwork];

            [MPNowPlayingInfoCenter defaultCenter].nowPlayingInfo = nowPlayingInfo;

            NSLog(@"Now Playing: %@", info);

            NSArray *metadata = [info componentsSeparatedByString: @"- "];

            self.artist.text = [metadata objectAtIndex:0];
            self.song.text = [metadata objectAtIndex:1];

        }
    }
}

注意:playerItem是AVPlayerItem的一个实例。

答案 1 :(得分:0)

为什么不从shoutcast服务器获取当前的歌曲和艺术家名称?以下页面允许您检索:

Current song:     http://yourstream:port/currentsong?sid=#
Last 20 songs:    http://yourstream:port/played.html?sid#

可以在Shoutcast Public pages

找到更多内容