tvOS 9~ Experiments - Native AVKit VideoPlayer - appleTv.
current movie, watermark image from : NASA Official Videos
-
= XCode 7.1 beta~.
-
= Swift 2.
-
= tvOS 9.0
Tested on tvOS 9.0 Simulator.
To support HTTP hosted : add the Boolean type Value to YES
for NSAllowsArbitraryLoads
in app's info.plist
file.
Create a new Swift file
import Foundation
import UIKit
import AVKit
class VideoPlayerViewController: AVPlayerViewController {
// MARK: - Properties
let overlay = UIView(frame: CGRectMake(0, 0, 285, 225))
let watermark = "your_image_name"
var url = "http://www.your_url_string"
// MARK: - Lifecycle
override func viewDidLoad() {
super.viewDidLoad()
setVideoPlayer()
}
// MARK: - Set video player for view
func setVideoPlayer() {
// watermark overlay (logo tv by example..)
overlay.addSubview(UIImageView(image: UIImage(named: watermark)))
contentOverlayView?.addSubview(overlay)
// AVPlayer Instance with NSURL
player = AVPlayer(URL: NSURL(string: url)!)
// Just Play!
player?.play()
}
}
Configure your storyboard with AVKit Player View Controller Object Library.
To run the example project, download or clone the repo.