简体   繁体   English

如何在我的iOS应用中播放广播? Swift和AVFoundation

[英]How can I stream radio in my iOS app? Swift and AVFoundation

I am currently using AVFoundation. 我目前正在使用AVFoundation。 The problem is that if I find a .m3u the stream works but I can not find the .m3u for any radio station. 问题是,如果我找到.m3u,则该流有效,但找不到任何广播电台的.m3u。 I am trying to get this one to work. 我正在努力使这一工作。 http://player.listenlive.co/35821 http://player.listenlive.co/35821

Here is my code 这是我的代码

   @IBOutlet weak var playButton: UIButton!
 var player:AVPlayer = AVPlayer(URL: NSURL(string: "http://player.listenlive.co/35821/en"))

@IBAction func buttonPressed(sender: AnyObject) {
    toggle()
}

func toggle() {
    if playButton.titleLabel?.text == "Play" {
        playRadio()
    } else {
        pauseRadio()
    }
}

func playRadio() {
    player.play()
    playButton.setTitle("Pause", forState: UIControlState.Normal)
}

func pauseRadio() {
    player.pause()
    playButton.setTitle("Play", forState: UIControlState.Normal)
}

override func viewDidLoad() {
    super.viewDidLoad()
    playButton.setTitle("Play", forState: UIControlState.Normal)

}

The URL you are using is wrong. 您使用的网址错误。 You need to have the direct URL to the m3u8 file. 您需要具有指向m3u8文件的直接URL。 Many m3u8s can be found here - https://stackoverflow.com/questions/10104301/hls-streaming-video-url-need-for-testing 在这里可以找到许多m3u8- https: //stackoverflow.com/questions/10104301/hls-streaming-video-url-need-for-testing

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 iOS Swift stream 音频来自使用 AVFoundation 的shoutcast 或icecast - iOS Swift stream audio from shoutcast or icecast using AVFoundation 如何处理从我的swift应用程序摇动ios设备的支持? - How can I handle support for shaking the ios device from my swift app? 如何使用 Swift 为 iOS 应用程序将拟我表情贴纸添加到我的表情符号键盘 - How can I add Memoji stickers to my emoji keyboard using Swift for an iOS app 如何使用Swift将相同的背景图像添加到ios应用程序的所有视图中? - How can I add the same background image to all views in my ios app using swift? 如何使用 swift 从我的 ios 应用程序通过 WhatsApp 向特定联系人发送消息? - How can I send message to specific contact through WhatsApp from my ios app using swift? 如何在我的 iOS 应用程序(Swift 5)中检查 Google 身份验证状态 - How can I check for Google authentication status in my iOS app (Swift 5) 如何使用Swift调试我的iOS应用程序 - How do I debug my iOS app with Swift 如何将Swift IOS应用程序与Pinterest集成? - How do I Integrate my Swift IOS app with Pinterest? 我可以将 iOS 应用程序视图流式传输到 Chromecast - Can I stream iOS App Views to the Chromecast 鉴于与实时Feed流的深层链接,如何在iOS中的应用中显示此直播? - Given a deep-link to a live-feed stream, how can I display this livestream within my app in iOS?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM