Skip to content

Commit e8c1eb8

Browse files
Ok, hear me out, no more private API usage
1 parent f918935 commit e8c1eb8

File tree

4 files changed

+73
-99
lines changed

4 files changed

+73
-99
lines changed

PlayerUI/PiP Support/PIP.h

Lines changed: 0 additions & 39 deletions
This file was deleted.

PlayerUI/PlayerUI.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,3 @@ FOUNDATION_EXPORT double PlayerUIVersionNumber;
1515
FOUNDATION_EXPORT const unsigned char PlayerUIVersionString[];
1616

1717
// In this header, you should import all the public headers of your framework using statements like #import <PlayerUI/PublicHeader.h>
18-
19-
#import <PlayerUI/PIP.h>

PlayerUI/Views/PUIPlayerView.swift

Lines changed: 73 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import Cocoa
1010
import AVFoundation
1111
import os.log
12+
import AVKit
1213

1314
public final class PUIPlayerView: NSView {
1415

@@ -340,7 +341,7 @@ public final class PUIPlayerView: NSView {
340341
}
341342

342343
fileprivate func updatePlayingState() {
343-
pipController?.setPlaying(isPlaying)
344+
// pipController?.setPlaying(isPlaying)
344345

345346
if isPlaying {
346347
playButton.image = .PUIPause
@@ -645,7 +646,8 @@ public final class PUIPlayerView: NSView {
645646
let b = PUIButton(frame: .zero)
646647

647648
b.isToggle = true
648-
b.image = .PUIPictureInPicture
649+
b.image = AVPictureInPictureController.pictureInPictureButtonStartImage
650+
b.alternateImage = AVPictureInPictureController.pictureInPictureButtonStopImage
649651
b.target = self
650652
b.action = #selector(togglePip)
651653
b.toolTip = "Toggle picture in picture"
@@ -1018,7 +1020,7 @@ public final class PUIPlayerView: NSView {
10181020

10191021
@IBAction public func togglePip(_ sender: NSView?) {
10201022
if isInPictureInPictureMode {
1021-
exitPictureInPictureMode()
1023+
pipController?.stopPictureInPicture()
10221024
} else {
10231025
enterPictureInPictureMode()
10241026
}
@@ -1266,7 +1268,7 @@ public final class PUIPlayerView: NSView {
12661268
}
12671269
}
12681270

1269-
fileprivate var pipController: PIPViewController?
1271+
fileprivate var pipController: AVPictureInPictureController?
12701272

12711273
fileprivate func enterPictureInPictureMode() {
12721274
delegate?.playerViewWillEnterPictureInPictureMode(self)
@@ -1275,21 +1277,14 @@ public final class PUIPlayerView: NSView {
12751277
self?.externalStatusController.snapshot = image
12761278
}
12771279

1278-
pipController = PIPViewController()
1280+
pipController = AVPictureInPictureController(playerLayer: playerLayer)
12791281
pipController?.delegate = self
1280-
pipController?.setPlaying(isPlaying)
1281-
pipController?.aspectRatio = currentPresentationSize ?? NSSize(width: 640, height: 360)
1282-
pipController?.view.layer?.backgroundColor = NSColor.black.cgColor
1282+
// pipController?.setPlaying(isPlaying)
1283+
// pipController?.aspectRatio = currentPresentationSize ?? NSSize(width: 640, height: 360)
1284+
// pipController?.view.layer?.backgroundColor = NSColor.black.cgColor
12831285

1284-
pipController?.presentAsPicture(inPicture: pictureContainer)
1285-
1286-
isInPictureInPictureMode = true
1287-
}
1288-
1289-
fileprivate func exitPictureInPictureMode() {
1290-
if pictureContainer.presentingViewController == pipController {
1291-
pipController?.dismiss(pictureContainer)
1292-
}
1286+
// pipController?.presentAsPicture(inPicture: pictureContainer)
1287+
pipController?.startPictureInPicture()
12931288
}
12941289

12951290
// MARK: - Visibility management
@@ -1643,51 +1638,83 @@ extension PUIPlayerView: PUIExternalPlaybackConsumer {
16431638

16441639
// MARK: - PiP delegate
16451640

1646-
extension PUIPlayerView: PIPViewControllerDelegate, PUIPictureContainerViewControllerDelegate {
1641+
extension PUIPlayerView: PUIPictureContainerViewControllerDelegate, AVPictureInPictureControllerDelegate {
1642+
1643+
// public func pipActionStop(_ pip: PIPViewController) {
1644+
// pause(pip)
1645+
//
1646+
// }
1647+
//
1648+
// public func pipActionReturn(_ pip: PIPViewController) {
1649+
// delegate?.playerViewWillExitPictureInPictureModelegate?.playerViewWillExitPictureInPictureMode(self, reason: .exitButton)de(self, reason: .returnButton)
1650+
//
1651+
// if !NSApp.isActive {
1652+
// NSApp.activate(ignoringOtherApps: true)
1653+
// }
1654+
//
1655+
// if let window = lastKnownWindow {
1656+
// window.makeKeyAndOrderFront(pip)
1657+
//
1658+
// if window.isMiniaturized {
1659+
// window.deminiaturize(nil)
1660+
// }
1661+
// }
1662+
// }
1663+
1664+
// public func pipActionPause(_ pip: PIPViewController) {
1665+
// pause(pip)
1666+
// }
1667+
//
1668+
// public func pipActionPlay(_ pip: PIPViewController) {
1669+
// play(pip)
1670+
// }
1671+
1672+
public func pictureInPictureController(_ pictureInPictureController: AVPictureInPictureController, failedToStartPictureInPictureWithError error: Error) {
1673+
isInPictureInPictureMode = false
1674+
pipController = nil
1675+
}
16471676

1648-
public func pipActionStop(_ pip: PIPViewController) {
1649-
pause(pip)
1650-
delegate?.playerViewWillExitPictureInPictureMode(self, reason: .exitButton)
1677+
public func pictureInPictureControllerDidStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
1678+
print("Player Rate: \(player?.rate)")
1679+
isInPictureInPictureMode = false
1680+
pipController = nil
16511681
}
16521682

1653-
public func pipActionReturn(_ pip: PIPViewController) {
1683+
public func pictureInPictureControllerDidStartPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
1684+
isInPictureInPictureMode = true
1685+
}
1686+
1687+
// public func pipDidClose(_ pip: PIPViewController) {
1688+
// pictureContainer.view.frame = bounds
1689+
//
1690+
// addSubview(pictureContainer.view, positioned: .below, relativeTo: scrimContainerView)
1691+
//
1692+
// isInPictureInPictureMode = false
1693+
// pipController = nil
1694+
// }
1695+
1696+
public func pictureInPictureControllerWillStopPictureInPicture(_ pictureInPictureController: AVPictureInPictureController) {
16541697
delegate?.playerViewWillExitPictureInPictureMode(self, reason: .returnButton)
1698+
print("Player Rate: \(player?.rate)")
16551699

16561700
if !NSApp.isActive {
16571701
NSApp.activate(ignoringOtherApps: true)
16581702
}
16591703

16601704
if let window = lastKnownWindow {
1661-
window.makeKeyAndOrderFront(pip)
1705+
window.makeKeyAndOrderFront(pictureInPictureController)
16621706

16631707
if window.isMiniaturized {
16641708
window.deminiaturize(nil)
16651709
}
16661710
}
16671711
}
16681712

1669-
public func pipActionPause(_ pip: PIPViewController) {
1670-
pause(pip)
1671-
}
1672-
1673-
public func pipActionPlay(_ pip: PIPViewController) {
1674-
play(pip)
1675-
}
1676-
1677-
public func pipDidClose(_ pip: PIPViewController) {
1678-
pictureContainer.view.frame = bounds
1679-
1680-
addSubview(pictureContainer.view, positioned: .below, relativeTo: scrimContainerView)
1681-
1682-
isInPictureInPictureMode = false
1683-
pipController = nil
1684-
}
1685-
1686-
public func pipWillClose(_ pip: PIPViewController) {
1687-
pip.replacementRect = frame
1688-
pip.replacementView = self
1689-
pip.replacementWindow = lastKnownWindow
1690-
}
1713+
// public func pipWillClose(_ pip: PIPViewController) {
1714+
// pip.replacementRect = frame
1715+
// pip.replacementView = self
1716+
// pip.replacementWindow = lastKnownWindow
1717+
// }
16911718

16921719
func pictureContainerViewSuperviewDidChange(to superview: NSView?) {
16931720
guard let superview = superview else { return }
@@ -1696,7 +1723,7 @@ extension PUIPlayerView: PIPViewControllerDelegate, PUIPictureContainerViewContr
16961723

16971724
if superview == self, pipController != nil {
16981725
if pictureContainer.presentingViewController == pipController {
1699-
pipController?.dismiss(pictureContainer)
1726+
pipController?.stopPictureInPicture()
17001727
}
17011728

17021729
pipController = nil

WWDC.xcodeproj/project.pbxproj

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,6 @@
152152
DDF721CA1ECA12A40054C503 /* Images.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721A91ECA12A40054C503 /* Images.swift */; };
153153
DDF721CB1ECA12A40054C503 /* Speeds.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721AA1ECA12A40054C503 /* Speeds.swift */; };
154154
DDF721CC1ECA12A40054C503 /* PUIExternalPlaybackProviderRegistration.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721AC1ECA12A40054C503 /* PUIExternalPlaybackProviderRegistration.swift */; };
155-
DDF721CD1ECA12A40054C503 /* PIP.h in Headers */ = {isa = PBXBuildFile; fileRef = DDF721AE1ECA12A40054C503 /* PIP.h */; settings = {ATTRIBUTES = (Public, ); }; };
156155
DDF721CE1ECA12A40054C503 /* PUIExternalPlaybackConsumer.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721B01ECA12A40054C503 /* PUIExternalPlaybackConsumer.swift */; };
157156
DDF721CF1ECA12A40054C503 /* PUIExternalPlaybackProvider.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721B11ECA12A40054C503 /* PUIExternalPlaybackProvider.swift */; };
158157
DDF721D01ECA12A40054C503 /* PUIPlayerViewDelegates.swift in Sources */ = {isa = PBXBuildFile; fileRef = DDF721B21ECA12A40054C503 /* PUIPlayerViewDelegates.swift */; };
@@ -420,7 +419,6 @@
420419
DDF721A91ECA12A40054C503 /* Images.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Images.swift; sourceTree = "<group>"; };
421420
DDF721AA1ECA12A40054C503 /* Speeds.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Speeds.swift; sourceTree = "<group>"; };
422421
DDF721AC1ECA12A40054C503 /* PUIExternalPlaybackProviderRegistration.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PUIExternalPlaybackProviderRegistration.swift; sourceTree = "<group>"; };
423-
DDF721AE1ECA12A40054C503 /* PIP.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = PIP.h; sourceTree = "<group>"; };
424422
DDF721B01ECA12A40054C503 /* PUIExternalPlaybackConsumer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PUIExternalPlaybackConsumer.swift; sourceTree = "<group>"; };
425423
DDF721B11ECA12A40054C503 /* PUIExternalPlaybackProvider.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PUIExternalPlaybackProvider.swift; sourceTree = "<group>"; };
426424
DDF721B21ECA12A40054C503 /* PUIPlayerViewDelegates.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = PUIPlayerViewDelegates.swift; sourceTree = "<group>"; };
@@ -974,7 +972,6 @@
974972
DDF721A41ECA12A40054C503 /* Controllers */,
975973
DDF721A71ECA12A40054C503 /* Definitions */,
976974
DDF721AB1ECA12A40054C503 /* Models */,
977-
DDF721AD1ECA12A40054C503 /* PiP Support */,
978975
DDF721AF1ECA12A40054C503 /* Protocols */,
979976
DDF721B51ECA12A40054C503 /* Resources */,
980977
DDF721B81ECA12A40054C503 /* Util */,
@@ -1013,14 +1010,6 @@
10131010
path = Models;
10141011
sourceTree = "<group>";
10151012
};
1016-
DDF721AD1ECA12A40054C503 /* PiP Support */ = {
1017-
isa = PBXGroup;
1018-
children = (
1019-
DDF721AE1ECA12A40054C503 /* PIP.h */,
1020-
);
1021-
path = "PiP Support";
1022-
sourceTree = "<group>";
1023-
};
10241013
DDF721AF1ECA12A40054C503 /* Protocols */ = {
10251014
isa = PBXGroup;
10261015
children = (
@@ -1174,7 +1163,6 @@
11741163
isa = PBXHeadersBuildPhase;
11751164
buildActionMask = 2147483647;
11761165
files = (
1177-
DDF721CD1ECA12A40054C503 /* PIP.h in Headers */,
11781166
DDF7219A1ECA12780054C503 /* PlayerUI.h in Headers */,
11791167
);
11801168
runOnlyForDeploymentPostprocessing = 0;

0 commit comments

Comments
 (0)