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

标签 ios streaming shoutcast

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

编辑:尝试 https://github.com/AlvaroFranco/AFSoundManager现在。

最佳答案

你应该像这样为你的播放器注册一个 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 的一个实例。

关于ios - 如何在 iOS 中更新歌曲名称 shoutcast?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29806640/

相关文章:

streaming - 如何将RTP/H264流写入文件

html - Shoutcast 流媒体和 HTML5 音频播放器

ios - iOS 支持的 SSL/TLS 版本和密码是什么?

ios - 将 UIKit 坐标转换为 SpriteKit 坐标

python - SageMaker 脚本模式 + 管道模式

flash - 当前流式传输视频的最佳方式是什么?

c# - 无法在 Windows Phone 8 上使用带有 backgroundAudio 的端口播放 shoutcast ip

javascript - HTML5 音频缓冲区不断增加 JS 堆大小

c# - 是否可以在 iOS 应用程序的导航 Controller 中实现 Split View Controller ?

ios - 删除表格 View 中的下划线