Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

AVPlayer with playback controls of avplayerviewcontroller

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?

like image 923
tnek316 Avatar asked Nov 12 '15 17:11

tnek316


People also ask

What is AVKit framework in IOS?

AVKit is a high-level framework for building media user interfaces, complete with playback controls, chapter navigation, Picture-in-Picture, audio routing, support for subtitles and closed captioning, Siri and Now Playing integration, and support for keyboard, Touch Bar, and remote control.

What is Avplayerlayer?

AVPlayer is a player for which the player layer displays visual output. It is a controller object used to manage the playback and timing a media asset. You can use an AVPlayer to play local and remote file-based media, such as QuickTime movies and MP3 audio files.


Video Answer


1 Answers

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 (self is your view controller):

let url = // whatever
let player = AVPlayer(URL:url)
let avPlayerViewController = AVPlayerViewController()
avPlayerViewController.player = player
avPlayerViewController.view.frame = // whatever
self.addChild(avPlayerViewController)
self.view.addSubview(avPlayerViewController.view)
avPlayerViewController.didMove(toParent: self)
like image 188
matt Avatar answered Sep 28 '22 09:09

matt