Basically I am trying to play an m3u8 (HLS Live Stream) using AVPlayer in Cocoa Swift. I'm relatively new to the language, so basically grabbed some example code for playing local video files and tried modifying it to play a live stream... But get this instead:
http://i.stack.imgur.com/bU9GM.png
This is what I got so far (commented lines are to play local file, which does work):
import Cocoa import AVKit import Foundation import AVFoundation class ViewController: NSViewController { @IBOutlet weak var playerView: AVPlayerView! var videoPlayer:AVPlayer! override func viewDidLoad() { super.viewDidLoad() //let path = NSBundle.mainBundle().pathForResource("sample", ofType: "mov") //var fileURL = NSURL(fileURLWithPath: path!) let fileURL = NSURL(string: "http://qthttp.apple.com.edgesuite.net/1010qwoeiuryfg/sl.m3u8") let avAsset = AVURLAsset(URL: fileURL!, options: nil) let playerItem = AVPlayerItem(asset: avAsset) videoPlayer = AVPlayer(playerItem: playerItem) playerView.player = videoPlayer videoPlayer.play() } override var representedObject: AnyObject? { didSet { // Update the view, if already loaded. } } }
Any help on how to make this code work, or lead me in the right direction is much appreciated!