我要在两个屏幕上播放相同的视频,同时保持寻道时间。这样我AVPlayer
就可以在这些屏幕中重用实例。第一次AVPlayer
工作正常,但每当它被重用时,播放器的帧从左上角动画以适合播放开始时的目标视图。
喜欢, https://www.dropbox.com/s/8ieb4bnb0rsn9ig/ezgif.com-gif-maker.gif?dl=0
代码看起来像,
if myObj._playerResult != nil {
_player = myObj._playerResult //reuse player instance
} else {
// First create an AVPlayerItem
let playerItem : AVPlayerItem = AVPlayerItem(URL: NSURL(string:sVideoUrl as String))
_player = AVPlayer(playerItem: playerItem)
}
playerController = AVPlayerViewController()
playerController?.showsPlaybackControls = false
playerController?.player = _player
playerController!.view.frame = targetView.bounds
targetView.addSubview(playerController!.view)
_player?.play()