Learn-iOS-Swift-by-Examples/MPRemoteCommandSample/MPRemoteCommandSample-TV/PlayerView.swift

37 lines
890 B
Swift
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

/*
Copyright (C) 2016 Apple Inc. All Rights Reserved.
See LICENSE.txt for this samples licensing information
Abstract:
`PlayerView` is a subclass of `UIView` with a layerClass of `AVPlayerLayer`.
*/
import UIKit
import AVFoundation
class PlayerView: UIView {
// MARK: Properties
/// The `AVPlayer` associated with the `AVPlayerLayer` of `PlayerView`.
var player: AVPlayer? {
get {
return playerLayer().player
}
set {
playerLayer().player = newValue
}
}
override class var layerClass: AnyClass {
return AVPlayerLayer.self
}
/// This is a convenience method for easily getting the layer associated with the `PlayerView` casted as an `AVPlayerLayer`.
func playerLayer() -> AVPlayerLayer {
return layer as! AVPlayerLayer
}
}