IOS 8 Swift AVAudioPlayer play remote audio (wowza server)

David Turton picture David Turton · Sep 18, 2014 · Viewed 22.1k times · Source

I am not an IOS programmer but I need a simple app to play an audio stream from a wowza server. Here is my code, I get no errors but also no audio. Any guidances or help?

    import UIKit
    import AVFoundation

    class ViewController: UIViewController {

         var player = AVAudioPlayer()

        override func viewDidLoad() {
            super.viewDidLoad()

            var fileURL: NSURL = NSURL(string: "http://url----.com/playlist.m3u8")

            var error:NSError?
            player = AVAudioPlayer(contentsOfURL: fileURL, error: &error)

            if player.prepareToPlay() && player.play(){
                println("yes")
            } else {
                println("no")
            }
        }

Answer

2075 picture 2075 · Nov 28, 2014

This worked for me:

var player = AVPlayer()

func configureView() {

    let url = "http://stream.your.url.com"
    let playerItem = AVPlayerItem( URL:NSURL( string:url ) )
    player = AVPlayer(playerItem:playerItem)
    player.rate = 1.0;
    player.play()

}