Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix/ios-16-media-controls] Fix missing iOS 16 video controls #1157

Merged
merged 1 commit into from
Sep 21, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 20 additions & 17 deletions ownCloud/Client/Viewer/Media/MediaDisplayViewController.swift
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,23 @@ class MediaDisplayViewController : DisplayViewController {
override func viewDidLoad() {
super.viewDidLoad()

playerViewController = AVPlayerViewController()

guard let playerViewController = playerViewController else { return }

addChild(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)

playerViewController.view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
playerViewController.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
playerViewController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),
playerViewController.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
playerViewController.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
])

NotificationCenter.default.addObserver(self, selector: #selector(handleDidEnterBackgroundNotification), name: UIApplication.didEnterBackgroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleWillEnterForegroundNotification), name: UIApplication.willEnterForegroundNotification, object: nil)
NotificationCenter.default.addObserver(self, selector: #selector(handleAVPlayerItem(notification:)), name: Notification.Name.AVPlayerItemDidPlayToEndTime, object: nil)
Expand Down Expand Up @@ -131,32 +148,18 @@ class MediaDisplayViewController : DisplayViewController {
if player == nil {
player = AVPlayer(playerItem: playerItem)
player?.allowsExternalPlayback = true
playerViewController = AVPlayerViewController()
if let playerViewController = self.playerViewController {
playerViewController.updatesNowPlayingInfoCenter = false

if UIApplication.shared.applicationState == .active {
playerViewController.player = player
}

addChild(playerViewController)
self.view.addSubview(playerViewController.view)
playerViewController.didMove(toParent: self)

playerViewController.view.translatesAutoresizingMaskIntoConstraints = false

NSLayoutConstraint.activate([
playerViewController.view.topAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.topAnchor),
playerViewController.view.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor),
playerViewController.view.leadingAnchor.constraint(equalTo: self.view.leadingAnchor),
playerViewController.view.trailingAnchor.constraint(equalTo: self.view.trailingAnchor)
])
}

// Add artwork to the player overlay if corresponding meta data item is available in the asset
if !(player?.isVideoAvailable ?? false), let artworkMetadataItem = asset.commonMetadata.filter({$0.commonKey == AVMetadataKey.commonKeyArtwork}).first,
let imageData = artworkMetadataItem.dataValue,
let overlayView = playerViewController?.contentOverlayView {
if !(player?.isVideoAvailable ?? false), let artworkMetadataItem = asset.commonMetadata.filter({$0.commonKey == AVMetadataKey.commonKeyArtwork}).first,
let imageData = artworkMetadataItem.dataValue,
let overlayView = playerViewController?.contentOverlayView {

if let artworkImage = UIImage(data: imageData) {

Expand Down