Created
March 28, 2018 17:22
-
-
Save Jesse-calkin/b91800937f65c63b79c9b1969f997a6b to your computer and use it in GitHub Desktop.
An AVFoundation Playground for displaying video via AVPlayer
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| //: 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