I am putting n avplayer inside of a view controller to customize some other elements of the view controller but I still want the playback and scrubbing controls used in AVPlayerViewController. Is there a way to enable these controls for the Avplayer when I am not using AvPlayerViewcontroller?
No. The usual solution (explicitly advised by Apple) is to use the AVPlayerViewController as an embedded view controller - i.e., make your view controller a custom parent view controller and the AVPlayerViewController its child, and now you can place its view (the movie and the controls) inside your view as a subview in good order. Example (from my book; self
is your view controller):
let url = // whatever
let player = AVPlayer(URL:url)
let av = AVPlayerViewController()
av.player = player
av.view.frame = // whatever
self.addChildViewController(av)
self.view.addSubview(av.view)
av.didMoveToParentViewController(self)
来源:https://stackoverflow.com/questions/33677527/avplayer-with-playback-controls-of-avplayerviewcontroller