Implementations
We provide two PlayerProtocol
implementations that you can choose from depending on your case.
Using them is a bit different but they all share the same functionality from the PlayerProtocol
protocol.
- A default implementation called
Player
- A UIKit-specific implementation called
PlayerViewController
. It conforms to the player protocol by delegating to aPlayer
under the hood.
The default player
Player
is the low level implementation that, unlike the others, is detached from
the UI. You will typically hold the default instance in the "view model" layer of your app.
let player = Player()
Attaching to the UI
In order to show the UI you must add the player view, Player.view
to some view in your hierarchy.
For example, in a view controller:
open override func viewDidLoad() {
view.addSubview(player.view)
}
The player ViewController
PlayerViewController
is a UIKit-based implementation of our player protocol, which does what was stated above - adds the video preview view as a child element covering the full size of the controller.
let player = PlayerViewController()
After creating the view controller, it can be added to your hierarchy and it will show the camera preview.
SwiftUI
We don't offer any SwiftUI utility at the moment, but it is trivial to implement a SwiftUI player based on PlayerViewController
using UIViewControllerRepresentable
.