[英]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.