An alternative to SwiftUI's VideoPlayer that includes an overlay button that will transition the player to be presented full screen.

Related tags

Video AZVideoPlayer
Overview

AZVideoPlayer

The VideoPlayer provided by SwiftUI out of the box is great but it's missing one very important feature: full screen presentation mode. AZVideoPlayer behaves pretty much exactly like VideoPlayer, but adds the button that's provided by AVPlayerViewController to go full screen.

Basic Usage

import SwiftUI
import AVKit
import AZVideoPlayer

struct ContentView: View {
    var player: AVPlayer?
    
    init(url: URL) {
        self.player = AVPlayer(url: url)
    }
    
    var body: some View {
        AZVideoPlayer(player: player)
            .aspectRatio(16/9, contentMode: .fit)
            // Adding .shadow(radius: 0) is necessary if
            // your player will be in a List on iOS 16.
            .shadow(radius: 0)
    }
}

Advanced Usage

I had a couple more reasons for making this package:

  1. Make it easy to reset the video player when the view disappears.
  2. Have the video continue playing when ending full screen presentation (it defaults to pausing when full screen mode ends).

Here's an example of how AZVideoPlayer can be used to do that:

import SwiftUI
import AVKit
import AZVideoPlayer

struct ContentView: View {
    var player: AVPlayer?
    @State var willBeginFullScreenPresentation: Bool = false
    
    init(url: URL) {
        self.player = AVPlayer(url: url)
    }
    
    var body: some View {
        AZVideoPlayer(player: player,
                      willBeginFullScreenPresentationWithAnimationCoordinator: willBeginFullScreen,
                      willEndFullScreenPresentationWithAnimationCoordinator: willEndFullScreen)
        .aspectRatio(16/9, contentMode: .fit)
        // Adding .shadow(radius: 0) is necessary if
        // your player will be in a List on iOS 16.
        .shadow(radius: 0)
        .onDisappear {
            // onDisappear is called when full screen presentation begins, but the view is
            // not actually disappearing in this case so we don't want to reset the player
            guard !willBeginFullScreenPresentation else {
                willBeginFullScreenPresentation = false
                return
            }
            player?.pause()
            player?.seek(to: .zero)
        }
    }
    
    func willBeginFullScreen(_ playerViewController: AVPlayerViewController,
                             _ coordinator: UIViewControllerTransitionCoordinator) {
        willBeginFullScreenPresentation = true
    }
    
    func willEndFullScreen(_ playerViewController: AVPlayerViewController,
                           _ coordinator: UIViewControllerTransitionCoordinator) {
        // This is a static helper method provided by AZVideoPlayer to keep
        // the video playing if it was playing when full screen presentation ended
        AZVideoPlayer.continuePlayingIfPlaying(player, coordinator)
    }
}
You might also like...
YouTube player for SwiftUI
YouTube player for SwiftUI

SwiftUI YouTube Player for iOS and MacOS Fully functional, SwiftUI-ready YouTube player for iOS 14+ and MacOS 11+. Actions and state are both delivere

Open Source iOS 360 Degree Panorama Video Player.
Open Source iOS 360 Degree Panorama Video Player.

๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ The Metal with Swift 5.0 version is comming ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ ๐ŸŽบ 360 VR Player A Open Source, Ad-free, Na

VLC media player

VLC media player VLC is a libre and open source media player and multimedia engine, focused on playing everything, and running everywhere. VLC can pla

๐Ÿ“ฝ A video player for SwiftUI, support for caching, preload and custom control view.
๐Ÿ“ฝ A video player for SwiftUI, support for caching, preload and custom control view.

Features QuickStart Advances Installation Requirements License Demo Clone or download the project. In the terminal, run swift package resolve. Open Vi

FWVideoPlayer is video Player for iOS in Swift.

FWVideoPlayer Desc FWVideoPlayer is video Player for iOS in Swift. It can play video and audio. You can use it easy. Example To run the example projec

SuperVideoPlayer is video player in Objc.

SuperVideoPlayer Example To run the example project, clone the repo, and run pod install from the Example directory first. Requirements Installation S

iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

iOS video player for trailer. You can customize layout for the control panel. Support PiP and DRM.

IINA is the modern video player for macOS.
IINA is the modern video player for macOS.

IINA IINA is the modern video player for macOS. Website ยท Releases ยท Telegram Group Features Based on mpv, which provides the best decoding capacity o

Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey
Yattee: video player for Invidious and Piped built for iOS 15, tvOS 15 and macOS Monterey

Video player with support for Invidious and Piped instances built for iOS 15, tvOS 15 and macOS Monterey.

Comments
  • Doesn't work with SPIndicator

    Doesn't work with SPIndicator

    I'm trying to create a list of videos, but in this case I'm using a ScrollView instead of a List

    The AZVideoPlayer works as expected but together with SPIndicator (a lib from another developer that shows toasts) gets pushed towards the notch.

    I was able to find out that the problem probably lies in the AVPlayerViewController, I tried to implement a simpler version of the video player with the AVPlayerViewController and got the same result, no issues when using the native VideoPlayer

    https://user-images.githubusercontent.com/1993871/202064081-de4fd802-98e1-4d4b-b459-348af696a40c.mov

    It's a bit hard to get a idea with the screen grab but the toast should cover the "Feed" word completely

    I added the SPIndicator on the topmost view to see if it would helped but it doesn't

    opened by PedroCavaleiro 1
Owner
Adam Zarn
I'm a mobile developer working at Callibrity.
Adam Zarn
MMPlayerView - Custom AVPlayerLayer on view and transition player with good effect like youtube and facebook

MMPlayerView Demo-Swift List / Shrink / Transition / Landscape MMPlayerLayer ex. use when change player view frequently like tableView / collectionVie

Millman Yang 724 Nov 24, 2022
Musical Player - A Simple Musical Player For iOS

Musical_Player The app is a musical player. It was written as an task for a mobi

null 1 Nov 26, 2022
BMPlayer - A video player for iOS, based on AVPlayer, support the horizontal, vertical screen

A video player for iOS, based on AVPlayer, support the horizontal, vertical screen. support adjust volume, brightness and seek by slide, support subtitles.

Eliyar Eziz 1.8k Jan 4, 2023
Repository with base samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Includes steps for encoding and packaging your own test content.

Video Everything Repository with minimal samples for playing HLS/DASH with CMAF video, across as many platforms as possible. Content and License All t

Alex Dodge 3 Jul 4, 2021
๐Ÿ“ฑiOS app to extract full-resolution video frames as images.

Frame Grabber is a focused, easy-to-use iOS app to extract full-resolution video frames as images. Perfect to capture and share your favorite video mo

Arthur Hammer 315 Dec 17, 2022
MobilePlayer - A powerful and completely customizable media player for iOS

MobilePlayer A powerful and completely customizable media player for iOS. Table of Contents Features Installation Usage Customization Skinning Showing

Sahin Boydas 3k Jan 2, 2023
โ–ถ๏ธ video player in Swift, simple way to play and stream media on iOS/tvOS

Player Player is a simple iOS video player library written in Swift. Looking for an obj-c video player? Check out PBJVideoPlayer (obj-c). Looking for

patrick piemonte 2k Jan 2, 2023
Player View is a delegated view using AVPlayer of Swift

PlayerView [![CI Status](http://img.shields.io/travis/David Alejandro/PlayerView.svg?style=flat)](https://travis-ci.org/David Alejandro/PlayerView) An

null 131 Oct 25, 2022
Swifty360Player - iOS 360-degree video player streaming from an AVPlayer.

Swifty360Player iOS 360-degree video player streaming from an AVPlayer. Demo Requirements Swifty360Player Version Minimum iOS Target Swift Version 0.2

Abdullah Selek 148 Dec 18, 2022
VGPlayer - ๐Ÿ“บ A simple iOS video player by Vein.

Swift developed based on AVPlayer iOS player,support horizontal gestures Fast forward, pause, vertical gestures Support brightness and volume adjustment, support full screen, adaptive screen rotation direction.

Wen Rong 399 Dec 23, 2022