-
What's new in AVKit
Learn about enhancements to Picture in Picture and full screen improvements on macOS. Explore the new content source API, and learn how AVPictureInPictureController supports AVSampleBufferDisplayLayer, as well as recommended steps for an app to provide a seamless full screen experience on macOS or in a Mac Catalyst app.
Recursos
Videos relacionados
WWDC21
WWDC19
-
Buscar este video…
-
-
1:16 - New canStartPictureInPictureAutomaticallyFromInline property
// New property on AVPlayerViewController / AVPictureInPictureController. var canStartPictureInPictureAutomaticallyFromInline: Bool { get set } -
1:40 - Setting up AVPictureInPictureController with an AVPlayerLayer
func setupPictureInPicture() { // Ensure PiP is supported by current device. if AVPictureInPictureController.isPictureInPictureSupported() { // Create a new controller, passing the reference to the AVPlayerLayer. pictureInPictureController = AVPictureInPictureController(playerLayer: playerLayer) pictureInPictureController.delegate = self // Observe AVPictureInPictureController.isPictureInPicturePossible to update the PiP // button’s enabled state. } else { // PiP isn't supported by the current device. Disable the PiP button. pictureInPictureButton.isEnabled = false } } -
2:11 - Starting and stopping picture in picture
@IBAction func togglePictureInPictureMode(_ sender: UIButton) { if pictureInPictureController.isPictureInPictureActive { pictureInPictureController.stopPictureInPicture() } else { pictureInPictureController.startPictureInPicture() } } -
2:56 - AVPictureInPictureSampleBufferPlaybackDelegate
public protocol AVPictureInPictureSampleBufferPlaybackDelegate: NSObjectProtocol{ // Delegate is responsible for: // // - Supplying playback state information for PiP UI. // - Responding to user input from PiP UI. } -
3:17 - Toggle playback of the video and seek back / ahead 15 seconds
func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, setPlaying playing: Bool) func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, skipByInterval skipInterval: CMTime, completion completionHandler: @escaping () -› Void) -
3:31 - Provide elapsed time information
func pictureInPictureControllerTimeRangeForPlayback(_ pictureInPictureController: AVPictureInPictureController) -> CMTimeRange -
3:51 - Choose appropriate media variant for render size
func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, didTransitionToRenderSize newRenderSize: CMVideoDimensions) -
4:06 - Update playback state
func pictureInPictureControllerIsPlaybackPaused(pictureInPictureController: AVPictureInPictureController) -> Bool -
6:05 - iOS / MacCatalyst - Persist full screen playback
func playerViewController(_ playerViewController: AVPlayerViewController, willBeginFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator) { coordinator.animate(alongsideTransition: nil) { context in // Keep a strong reference to the playerViewController while in full screen. self.detachedPlayerViewController = playerViewController } } -
6:38 - iOS / MacCatalyst - Release the playerViewController
func playerViewController(_ playerViewController: AVPlayerViewController, willEndFullScreenPresentationWithAnimationCoordinator coordinator: UIViewControllerTransitionCoordinator){ coordinator.animate(alongsideTransition: nil) { context in // Stop keeping the playerViewController alive when transition completes, self.detachedPlayerViewController = nil } } -
6:46 - Persist full screen playback on macOS
func playerViewWillEnterFullScreen(_ playerView: AVPlayerView) { // Start keeping the player view alive while it is not in the view hierarchy. self.detachedPlayerView = playerView } func playerViewWillExitFullScreen(_ playerView: AVPlayerView) { // Stop keeping the player view alive. self.detachedPlayerView = nil } -
6:55 - Restoring UI when exiting full screen
// Restoring UI when exiting full screen // iOS / MacCatalyst func playerViewControllerRestoreUserInterfaceForFullScreenExit(_ playerViewController: AVPlayerViewController) async -> Bool { // Custom UI restoration logic return true } // macOS func playerViewRestoreUserInterfaceForFullScreenExit(_ playerView: AVPlayerView) async -> Bool { // custom UI restore logic here return true }
-