I have local video playback using AVPlayerand AVPlayerLayer(Swift, iOS 8.2), and I need to resize AVPlayerLayer( introPlayerLayer) when its parent view ( introView) is resized, including changing orientation. So far, nothing I tried seems to work, but playerLayerhas the wrong size and position.
AVPlayerconfigured using local mp4 video, and AVPlayerLayerinitialized using this player. The layer is then added as a sublevel to the parent view.
Here is my code:
func playIntro() {
let path = NSBundle.mainBundle().pathForResource("intro", ofType: "mp4")
let url = NSURL.fileURLWithPath(path!)
let introPlayer = AVPlayer(URL: url)
introPlayer.allowsExternalPlayback = false
var introPlayerLayer = AVPlayerLayer(player: introPlayer)
introView.layer.addSublayer(introPlayerLayer)
introPlayerLayer.frame = introView.bounds
NSNotificationCenter.defaultCenter().addObserver(self, selector: "playerDidFinishPlaying:", name: AVPlayerItemDidPlayToEndTimeNotification, object: introPlayer.currentItem)
introView.hidden = false
introPlayer.play()
}
AVPlayerLayer UIView, (UIView), " " https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/AVFoundationPG/Articles/02_Playback.html. , PlayerView ( Objective-C) Swift?
.