iOS的在线广播流问题 [英] iOS online radio streaming questions

查看:197
本文介绍了iOS的在线广播流问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要创建应用程序,提供在线广播流(的Icecast),preferably .OGG格式。
所以,我有下一个问题:

I have to create app that provides online radio streaming (icecast), preferably .ogg format. So I have next questions:


  1. 如何播放的 .OGG 格式的音频流?是否有任何支持
    类?因为我找不到任何,所以我认为这是不可能的
    不使用许多位运算 CFNetwork的 CoreAudio的
    AudioToolbox (我不看cocos2d的,因为它是荒谬)
    我错了吗

  2. 我在播放MP3流现在(没有可能性.OGG我)。一世
    试图用 AVPlayer MPMovieMediaController ,由 AudioSreaming LIB
    MattGallagher和DigitalDJ
    ,然后这些解决方案都不能
    为我提供元数​​据访问。

  1. How can I play .ogg format audio stream? Are there any supported classes? Because I can't find any, so I think that it is impossible without many bitwise operations using CFNetwork, CoreAudio, AudioToolbox etc. (I don't look at cocos2d, because it's ridiculous) Am i wrong?
  2. I'm playing mp3 stream for now (no possibility for .ogg for me). I tried to use AVPlayer, MPMovieMediaController, AudioSreaming lib by MattGallagher and by DigitalDJ, and none of these solutions can't provides me metadata access.

对于AVPlayer:

   -(void)playButtonPressed:(id)sender
    {
        NSURL *grindURL = [NSURL URLWithString:@"http://radio.goha.ru:8000/grind.fm"];
                    grindFMPlayer = [[AVPlayer alloc] initWithURL:grindURL];
                    [grindFMPlayer.currentItem addObserver:self forKeyPath:@"status" options:0 context:nil]; 
                    AVPlayerItem *item = grindFMPlayer.currentItem;
                    [grindFMPlayer play];
    }

-(void)stopButtonPressed:(id)sender
{
            AVURLAsset *ass = grindFMPlayer.currentItem.asset;
            NSArray *arr = [ass commonMetadata];
            NSArray *it_meta = [grindFMPlayer.currentItem timedMetadata];
            [grindFMPlayer pause];
}

改编 it_meta计数总是 0 ,没有歌曲\\艺术家\\任何元数据。

同为 MPMovieMediaController ,metadataUpdate从来不叫

arr and it_meta count always 0, no song\artist\any metadata.
The same for the MPMovieMediaController, metadataUpdate never called

streamAudioPlayer = [[MPMoviePlayerController alloc] 
                                                   initWithContentURL:[NSURL URLWithString:@"http://radio.goha.ru:8000/grind.fm"];
                streamAudioPlayer.movieSourceType = MPMovieSourceTypeStreaming;
                [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(MetadataUpdate:) name:MPMoviePlayerTimedMetadataUpdatedNotification object:nil];
[streamAudioPlayer play];

和停止按钮的方法:

and in stop button method:

timedMeta = [streamAudioPlayer timedMetadata];
            if ([streamAudioPlayer timedMetadata]!=nil && [[streamAudioPlayer timedMetadata] count] > 0) 
            {
                NSLog(@"metadata count = %d", [[streamAudioPlayer timedMetadata] count]);
                for (MPTimedMetadata *metadata in [streamAudioPlayer timedMetadata]) 
                {
                    NSLog(@"description %@", metadata.allMetadata);
                    if ([[metadata.allMetadata valueForKey:@"key"] isEqualToString:@"title"]) 
                    {
                        NSString *text = [metadata.allMetadata valueForKey:@"value"];
                        NSString* filename = text;
                    }
                }
            }

[streamAudioPlayer timedMetadata] 始终为零。

我试过

  • https://github.com/mattgallagher/AudioStreamer
  • https://github.com/DigitalDJ/AudioStreamer

这2个项目,Shoutcast一样的Icecast和 - 的http://www.mikejablonski.org/2009/04/17/reading-shoutcast-metadata-from-a-stream/

These 2 projects for shoutcast and icecast - http://www.mikejablonski.org/2009/04/17/reading-shoutcast-metadata-from-a-stream/

但仍然没有运气来获取当前正在播放的曲目信息,只在取得 Shoutcast一样应用

But still have no luck to get current playing track info, which only obtains in SHOUTcast app as

1 元='StreamTitle ='

2日 元=''比特率='128000'
(所以我觉得我必须处理的字节从 HTTP 头反应或这样的事情?但跆拳道,这是Shoutcast的元数据,但我的radiostream是的Icecast。不知道)

我会感谢任何帮助!

2nd metadata = '' and bitrate = '128000'
(So I think I have to have deal with bytes from http headers response or something like this? but wtf, it's shoutcast metadata, but my radiostream is icecast. Have no idea)
I would be grateful for any help!

推荐答案

的Icecast和Shoutcast的是互相兼容。不同之处在于它们为响应HTTP GET请求的方式。当你发送一个HTTP GET请求到icecast服务,它将与一个HTTP 200 OK响应答复。响应头将包含冰雪-BR值,冰冷-metaint,冰冷的名称,冰冷的流派和结冰的URL键。

Icecast and Shoutcast are compatible with each other. The difference lies in the way they respond to a HTTP GET request. When you send a HTTP GET request to an Icecast server it will reply with a HTTP 200 OK response. The response headers will contain values for the icy-br, icy-metaint, icy-name, icy-genre and icy-url keys.

当你发送一个HTTP GET请求到SHOUTcast服务器就会以ICY 200 OK响应响应。在这种情况下,你必须分析响应数据,因为元数据将不会在响应头可用。

When you send a HTTP GET request to a Shoutcast server it will respond with a ICY 200 OK response. In this case you'll have to parse the response data because the metadata will not be available in the response headers.

最重要的元数据,关键是冰冷的,metaint键。此值会告诉你的元数据的频率流中发送。有关分析这些元数据的详细信息看看这个网站: Shoutcast的元数据协议

The most important metadata key is the icy-metaint key. This value will tell you how often the metadata is sent in the stream. For more information about parsing this metadata have a look at this website: Shoutcast Metadata Protocol

要播放OGG流,您需要使用开源的FFmpeg库。这个库可以编译为iOS平台和用于连接和去code OGG流。

To play ogg streams you'll need to use the open source FFmpeg library. This library can be compiled for the iOS platform and used to connect and decode ogg streams.

这篇关于iOS的在线广播流问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆