Skip to content

Instantly share code, notes, and snippets.

@Jesse-calkin
Created March 28, 2018 17:22
Show Gist options
  • Save Jesse-calkin/b91800937f65c63b79c9b1969f997a6b to your computer and use it in GitHub Desktop.
Save Jesse-calkin/b91800937f65c63b79c9b1969f997a6b to your computer and use it in GitHub Desktop.
An AVFoundation Playground for displaying video via AVPlayer
//: An `AVFoundation` Playground for playing video with `AVPlayer`. Using just a bare `AVPlayer`, there will be no playback controls.
import UIKit
import PlaygroundSupport
import AVFoundation
class MyViewController : UIViewController {
// Other example streams can be found here: https://developer.apple.com/streaming/examples/
let url = URL(string: "http://devimages.apple.com/iphone/samples/bipbop/bipbopall.m3u8")!
func setupPlayer() {
let player = AVPlayer(url: url)
let playerLayer = AVPlayerLayer(player: player)
playerLayer.frame = view.frame
view.layer.addSublayer(playerLayer)
player.play()
}
override func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
setupPlayer()
}
}
PlaygroundPage.current.liveView = MyViewController()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment