TEAM LICENSES: Save money and learn new skills through a Hacking with Swift+ team license >>

AVPlayer Button

Forums > iOS

Hello,

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 {
      subview.removeFromSuperview()
    }

    routePickerView.addSubview(childViewController.view)

    if let parentVC = test.parentViewController {
      uiViewController.buttonIsAdded = true
      parentVC.addChild(childViewController)

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

~Nils

3      

Hacking with Swift is sponsored by String Catalog.

SPONSORED Get accurate app localizations in minutes using AI. Choose your languages & receive translations for 40+ markets!

Localize My App

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.