【问题标题】:How to play a radio station on button press in iOS如何在 iOS 中按下按钮播放广播电台
【发布时间】:2014-10-15 21:55:57
【问题描述】:

当有人按下播放单选按钮时,我想播放电台。但是,它不起作用。

这是我的代码:

NSURL *url = [NSURL URLWithString:@"http://www.radio.net.pk/"];

NSData *data = [NSData dataWithContentsOfURL:url];
AVAudioPlayer *audio = [[AVAudioPlayer alloc] initWithData:data error:nil];
[audio play];

【问题讨论】:

  • 看看这个演示:-github.com/hamedh/Radio
  • 感谢您给我帮助。请告诉我如何在此演示中更改我的链接。这样当应用程序启动时,它应该会流式传输我的电台声音。
  • 在演示项目中使用“http”搜索,然后用演示链接替换您的链接
  • 亲爱的,我已经用那个链接替换了我的 http 链接,但没有缓冲。请给我一些其他电台链接来试试。谢谢。

标签: ios objective-c iphone avaudioplayer radio


【解决方案1】:

AVAudioPlayer 类只允许您播放 iOS 和 OS X 中可用的任何音频格式的声音

这意味着,AVAudioPlayer 类不支持基于 HTTP URL 的流式音频。 initWithContentsOfURL: 使用的 URL 必须是本地路径 URL。

因此,您应该将 NSData 保存在本地(使用不同的块)并使用 AVAudioPlayer 播放它。

【讨论】:

    【解决方案2】:

    它永远不会起作用。

    radio.net.pk 是否提供任何 API?

    datWithContentsOfURL 将返回您尝试使用AVAudioPlayer 播放的HTML 字符串 !!。请再次浏览该网站并检查是否有任何开发者 API

    【讨论】:

      【解决方案3】:
      // Using this Cannel
      
      NSURL *url6 = [NSURL    URLWithString:@"http://sc6.spacialnet.com:35464/"]
      layerItem = [AVPlayerItem playerItemWithURL:_strTemp]; // add url to playerItem
      
      player = [AVPlayer playerWithPlayerItem:playerItem]; // add player item to AVAudioPlayer
      player = [AVPlayer playerWithURL:_strTemp]
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-11-02
        • 2015-05-01
        相关资源
        最近更新 更多