Created
July 14, 2018 09:10
-
-
Save yakimelon/6f308d411f15be6ac1f7430e9effc36c to your computer and use it in GitHub Desktop.
This file contains 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
import AVFoundation | |
import UIKit | |
// レイヤーをAVPlayerLayerにする為のラッパークラス. | |
class AVPlayerView : UIView { | |
// UIViewのサブクラスを作りlayerClassメソッドをオーバーライドしてAVPlayerLayerに差し替える | |
override class var layerClass: AnyClass { | |
return AVPlayerLayer.self | |
} | |
// AVPlayerのgetterとsetter | |
var player: AVPlayer { | |
get { | |
let layer: AVPlayerLayer = self.layer as! AVPlayerLayer | |
return layer.player! | |
} | |
set(newValue) { | |
let layer: AVPlayerLayer = self.layer as! AVPlayerLayer | |
layer.player = newValue | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment