UPGRADE YOUR SKILLS: Learn advanced Swift and SwiftUI on Hacking with Swift+! >>

AVPlayer Button

Forums > iOS


At the moment I try to add a Button to an AVPlayer. From the documentation it isn't clear to me how you can do this.

Here is an example what I mean:

The apple developer app has this copy button. But it isn't clear to me how to add one by reading just the documentation. It is clearly an AVPlayer and not a custom controller implementation, because a vanilla player looks nearly the same:

Any idea how to archive this without implementing a controller ui by myself? I just want to add a way to adjust video quality without reinventing the wheel.

I was able to place a button there, but I was not able to resize it:

This is what I did to archive this:

let childViewController = SelfSizingHostingController(rootView: self.child)

childViewController.view.translatesAutoresizingMaskIntoConstraints = false
childViewController.view.contentMode = .scaleAspectFitt

if let test = uiViewController.view.subviews.first?.subviews[1].subviews[4] {
    test.contentMode = .scaleAspectFit

    let routePickerView = AVRoutePickerView() // just try to test if only special views work

    for subview in routePickerView.subviews {


    if let parentVC = test.parentViewController {
      uiViewController.buttonIsAdded = true

      self.copyConstraints(sourceView: test.subviews.first!, toView: routePickerView)
      test.insertSubview(routePickerView, at: 0)
      childViewController.didMove(toParent: parentVC)



Hacking with Swift is sponsored by RevenueCat

SPONSORED Take the pain out of configuring and testing your paywalls. RevenueCat's Paywalls allow you to remotely configure your entire paywall view without any code changes or app updates.

Learn more here

Sponsor Hacking with Swift and reach the world's largest Swift community!

Archived topic

This topic has been closed due to inactivity, so you can't reply. Please create a new topic if you need to.

All interactions here are governed by our code of conduct.

Unknown user

You are not logged in

Log in or create account

Link copied to your pasteboard.