Remove HKPictureInPictureController
This commit is contained in:
parent
3816d10261
commit
1c9ab5c3c9
|
@ -4,7 +4,7 @@ import Foundation
|
|||
import HaishinKit
|
||||
import UIKit
|
||||
|
||||
final class PlaybackViewController: UIViewController, HKPictureInPictureController {
|
||||
final class PlaybackViewController: UIViewController {
|
||||
private static let maxRetryCount: Int = 5
|
||||
|
||||
@IBOutlet private weak var playbackButton: UIButton!
|
||||
|
@ -16,9 +16,6 @@ final class PlaybackViewController: UIViewController, HKPictureInPictureControll
|
|||
override func viewDidLoad() {
|
||||
super.viewDidLoad()
|
||||
rtmpStream = RTMPStream(connection: rtmpConnection)
|
||||
let tapGesture = UITapGestureRecognizer(target: self, action: #selector(didTapped(_:)))
|
||||
tapGesture.numberOfTapsRequired = 2
|
||||
view.addGestureRecognizer(tapGesture)
|
||||
}
|
||||
|
||||
override func viewWillAppear(_ animated: Bool) {
|
||||
|
@ -83,17 +80,6 @@ final class PlaybackViewController: UIViewController, HKPictureInPictureControll
|
|||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func didTapped(_ sender: UITapGestureRecognizer) {
|
||||
if isPictureInPictureActive {
|
||||
stopPictureInPicture()
|
||||
playbackButton.isHidden = false
|
||||
} else {
|
||||
startPictureInPicture()
|
||||
playbackButton.isHidden = true
|
||||
}
|
||||
}
|
||||
|
||||
@objc
|
||||
private func rtmpErrorHandler(_ notification: Notification) {
|
||||
logger.error(notification)
|
||||
|
@ -103,7 +89,7 @@ final class PlaybackViewController: UIViewController, HKPictureInPictureControll
|
|||
@objc
|
||||
private func didEnterBackground(_ notification: Notification) {
|
||||
logger.info(notification)
|
||||
if !isPictureInPictureActive {
|
||||
if (pictureInPictureController?.isPictureInPictureActive == false) {
|
||||
rtmpStream.receiveVideo = false
|
||||
}
|
||||
}
|
||||
|
@ -111,7 +97,7 @@ final class PlaybackViewController: UIViewController, HKPictureInPictureControll
|
|||
@objc
|
||||
private func didBecomeActive(_ notification: Notification) {
|
||||
logger.info(notification)
|
||||
if !isPictureInPictureActive {
|
||||
if (pictureInPictureController?.isPictureInPictureActive == false) {
|
||||
rtmpStream.receiveVideo = true
|
||||
}
|
||||
}
|
||||
|
|
|
@ -329,16 +329,6 @@
|
|||
BC0D236E26331BAB001DDA0C /* NetSocket.CircularBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC0D236C26331BAB001DDA0C /* NetSocket.CircularBuffer.swift */; };
|
||||
BC0D236F26331BAB001DDA0C /* NetSocket.CircularBuffer.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC0D236C26331BAB001DDA0C /* NetSocket.CircularBuffer.swift */; };
|
||||
BC11D94625A1B01000D710BA /* Screencast.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = 2915EC521D85BDF100621092 /* Screencast.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
|
||||
BC20DF2C2503747E007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF2B2503747E007BC608 /* HKPictureInPictureControllerPosition.swift */; };
|
||||
BC20DF2D25037498007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF2B2503747E007BC608 /* HKPictureInPictureControllerPosition.swift */; };
|
||||
BC20DF2E25037498007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF2B2503747E007BC608 /* HKPictureInPictureControllerPosition.swift */; };
|
||||
BC20DF2F2503749C007BC608 /* HKPictureInPictureControllerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355D24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift */; };
|
||||
BC20DF302503749D007BC608 /* HKPictureInPictureControllerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355D24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift */; };
|
||||
BC20DF31250374A7007BC608 /* HKPictureInPictureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355624FA37F700DC5108 /* HKPictureInPictureController.swift */; };
|
||||
BC20DF32250374A8007BC608 /* HKPictureInPictureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355624FA37F700DC5108 /* HKPictureInPictureController.swift */; };
|
||||
BC20DF34250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF33250374EA007BC608 /* HKPictureInPictureController+Extension.swift */; };
|
||||
BC20DF35250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF33250374EA007BC608 /* HKPictureInPictureController+Extension.swift */; };
|
||||
BC20DF36250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */ = {isa = PBXBuildFile; fileRef = BC20DF33250374EA007BC608 /* HKPictureInPictureController+Extension.swift */; };
|
||||
BC20DF38250377A3007BC608 /* ScreenCaptureSession.swift in Sources */ = {isa = PBXBuildFile; fileRef = 299B131C1D35272D00A1E8F5 /* ScreenCaptureSession.swift */; };
|
||||
BC34DFF025EBB53F005F975A /* Logboard.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC34DFD125EBB12C005F975A /* Logboard.xcframework */; };
|
||||
BC34E00225EBB59C005F975A /* Logboard.xcframework in Frameworks */ = {isa = PBXBuildFile; fileRef = BC34DFD125EBB12C005F975A /* Logboard.xcframework */; };
|
||||
|
@ -555,8 +545,6 @@
|
|||
BCD63AE226FDF3500084842D /* Logboard.xcframework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = BC34DFD125EBB12C005F975A /* Logboard.xcframework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
|
||||
BCFB355524FA27EA00DC5108 /* PlaybackViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355324FA275600DC5108 /* PlaybackViewController.swift */; };
|
||||
BCFB355A24FA40DD00DC5108 /* PlaybackContainerViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */; };
|
||||
BCFB355C24FAB29B00DC5108 /* HKPictureInPictureController.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355624FA37F700DC5108 /* HKPictureInPictureController.swift */; };
|
||||
BCFB355E24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift in Sources */ = {isa = PBXBuildFile; fileRef = BCFB355D24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift */; };
|
||||
/* End PBXBuildFile section */
|
||||
|
||||
/* Begin PBXContainerItemProxy section */
|
||||
|
@ -844,8 +832,6 @@
|
|||
2EC97B6F27880FF400D8BE32 /* Views.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Views.swift; sourceTree = "<group>"; };
|
||||
2EC97B7027880FF400D8BE32 /* MTHKSwiftUiView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = MTHKSwiftUiView.swift; sourceTree = "<group>"; };
|
||||
BC0D236C26331BAB001DDA0C /* NetSocket.CircularBuffer.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = NetSocket.CircularBuffer.swift; sourceTree = "<group>"; };
|
||||
BC20DF2B2503747E007BC608 /* HKPictureInPictureControllerPosition.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKPictureInPictureControllerPosition.swift; sourceTree = "<group>"; };
|
||||
BC20DF33250374EA007BC608 /* HKPictureInPictureController+Extension.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "HKPictureInPictureController+Extension.swift"; sourceTree = "<group>"; };
|
||||
BC34DFD125EBB12C005F975A /* Logboard.xcframework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.xcframework; name = Logboard.xcframework; path = Carthage/Build/Logboard.xcframework; sourceTree = "<group>"; };
|
||||
BC34FA0A286CB90A00EFAF27 /* PiPHkView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PiPHkView.swift; sourceTree = "<group>"; };
|
||||
BC44A1A823D31E92002D4297 /* AudioCodec.AudioBuffer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AudioCodec.AudioBuffer.swift; sourceTree = "<group>"; wrapsLines = 1; };
|
||||
|
@ -923,9 +909,7 @@
|
|||
BCD63AB826FDF12A0084842D /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
|
||||
BCD63ABB26FDF12A0084842D /* Preview Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = "Preview Assets.xcassets"; sourceTree = "<group>"; };
|
||||
BCFB355324FA275600DC5108 /* PlaybackViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackViewController.swift; sourceTree = "<group>"; };
|
||||
BCFB355624FA37F700DC5108 /* HKPictureInPictureController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKPictureInPictureController.swift; sourceTree = "<group>"; };
|
||||
BCFB355924FA40DD00DC5108 /* PlaybackContainerViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PlaybackContainerViewController.swift; sourceTree = "<group>"; };
|
||||
BCFB355D24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = HKPictureInPictureControllerImpl.swift; sourceTree = "<group>"; };
|
||||
/* End PBXFileReference section */
|
||||
|
||||
/* Begin PBXFrameworksBuildPhase section */
|
||||
|
@ -1169,7 +1153,6 @@
|
|||
29BDE0BD1C65BC2400D6A768 /* Media */,
|
||||
BCA97B84263AC0A80027213C /* MP4 */,
|
||||
297C16881CC5382600117ADF /* Net */,
|
||||
BC20DF2A25037454007BC608 /* PiP */,
|
||||
29C0E0591C2EB00A009DD8E8 /* RTMP */,
|
||||
BCD1DCF62610751900A1C593 /* TS */,
|
||||
290907CE1C3961BC00F2E80C /* Util */,
|
||||
|
@ -1469,17 +1452,6 @@
|
|||
path = View;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
BC20DF2A25037454007BC608 /* PiP */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
BCFB355624FA37F700DC5108 /* HKPictureInPictureController.swift */,
|
||||
BC20DF33250374EA007BC608 /* HKPictureInPictureController+Extension.swift */,
|
||||
BCFB355D24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift */,
|
||||
BC20DF2B2503747E007BC608 /* HKPictureInPictureControllerPosition.swift */,
|
||||
);
|
||||
path = PiP;
|
||||
sourceTree = "<group>";
|
||||
};
|
||||
BCA97B84263AC0A80027213C /* MP4 */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
|
@ -2007,14 +1979,11 @@
|
|||
BCAD0C00263E968400ADFB80 /* MP4FileReader.swift in Sources */,
|
||||
BCA97B8A263AC1830027213C /* MP4Box.swift in Sources */,
|
||||
2915EC4D1D85BB8C00621092 /* RTMPTSocket.swift in Sources */,
|
||||
BCFB355C24FAB29B00DC5108 /* HKPictureInPictureController.swift in Sources */,
|
||||
BCC1A6C22643F41600661156 /* MP4FragmentedWriter.swift in Sources */,
|
||||
2958910A1EEB8D1800CE51E1 /* FLVReader.swift in Sources */,
|
||||
29C2631C1D0083B50098D4EF /* AVVideoIOUnit.swift in Sources */,
|
||||
29B876B41CD70B2800FC07DA /* RTMPSharedObject.swift in Sources */,
|
||||
BC20DF34250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */,
|
||||
2901A4EE1D437170002BBD23 /* MediaLink.swift in Sources */,
|
||||
BC20DF2C2503747E007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */,
|
||||
2958911E1EEB8E9600CE51E1 /* FLVSoundRate.swift in Sources */,
|
||||
29B876941CD70AFE00FC07DA /* SoundTransform.swift in Sources */,
|
||||
29DF20662312A436004057C3 /* RTMPSocketCompatible.swift in Sources */,
|
||||
|
@ -2113,7 +2082,6 @@
|
|||
29B876781CD70ACE00FC07DA /* HTTPService.swift in Sources */,
|
||||
2976A4861D4903C300B53EF2 /* DeviceUtil.swift in Sources */,
|
||||
BCC1A7072647E89300661156 /* BaseDescriptor.swift in Sources */,
|
||||
BCFB355E24FAB2D200DC5108 /* HKPictureInPictureControllerImpl.swift in Sources */,
|
||||
29B876881CD70AE800FC07DA /* TSPacket.swift in Sources */,
|
||||
BCA97BE8263C27070027213C /* MP4SampleSizeBox.swift in Sources */,
|
||||
BCA97C18263DA5060027213C /* MP4AudioSampleEntry.swift in Sources */,
|
||||
|
@ -2212,7 +2180,6 @@
|
|||
29EA87E71E79A2780043A5F8 /* CMAudioFormatDescription+Extension.swift in Sources */,
|
||||
29FD1B5122FF13190095A0BE /* VTSessionPropertyKey.swift in Sources */,
|
||||
29B876F61CD70D5900FC07DA /* HTTPRequest.swift in Sources */,
|
||||
BC20DF2F2503749C007BC608 /* HKPictureInPictureControllerImpl.swift in Sources */,
|
||||
BCC1A70C2647F23200661156 /* ESDescriptor.swift in Sources */,
|
||||
29B876F71CD70D5900FC07DA /* HTTPResponse.swift in Sources */,
|
||||
BC4C9EB023F2E736004A14F2 /* AudioStreamBasicDescription+Extension.swift in Sources */,
|
||||
|
@ -2234,7 +2201,6 @@
|
|||
2941746C22D069B300A2944F /* AudioEffect.swift in Sources */,
|
||||
BC9CFA9423BDE8B700917EEF /* NetStreamDrawable.swift in Sources */,
|
||||
BCC1A728264FA1C100661156 /* ProfileLevelIndicationIndexDescriptor.swift in Sources */,
|
||||
BC20DF31250374A7007BC608 /* HKPictureInPictureController.swift in Sources */,
|
||||
296242631D8DBA8C00C451A3 /* TSReader.swift in Sources */,
|
||||
BC94E52F264146540094C169 /* MP4ReaderConvertible.swift in Sources */,
|
||||
29B876FE1CD70D5A00FC07DA /* AVCConfigurationRecord.swift in Sources */,
|
||||
|
@ -2275,7 +2241,6 @@
|
|||
29B877081CD70D5A00FC07DA /* AVVideoIOUnit.swift in Sources */,
|
||||
294CC9B422D9BEC000F9DD5C /* DisplayLink-macOS.swift in Sources */,
|
||||
BC94E507263FEA7F0094C169 /* MP4TrackFragmentBaseMediaDecodeTimeBox.swift in Sources */,
|
||||
BC20DF2D25037498007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */,
|
||||
BCC1A7182647F3E000661156 /* DecoderSpecificInfo.swift in Sources */,
|
||||
29B877091CD70D5A00FC07DA /* VideoEffect.swift in Sources */,
|
||||
29B8770A1CD70D5A00FC07DA /* MIME.swift in Sources */,
|
||||
|
@ -2298,7 +2263,6 @@
|
|||
BCC1A6D026445AF500661156 /* MP4TrackExtendsBox.swift in Sources */,
|
||||
29EA87E01E79A0810043A5F8 /* CMSampleBuffer+Extension.swift in Sources */,
|
||||
29B8770D1CD70D5A00FC07DA /* NetSocket.swift in Sources */,
|
||||
BC20DF35250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */,
|
||||
29B8770E1CD70D5A00FC07DA /* AMF0Serializer.swift in Sources */,
|
||||
2976A4871D49045700B53EF2 /* DeviceUtil.swift in Sources */,
|
||||
29B8770F1CD70D5A00FC07DA /* AMF3Serializer.swift in Sources */,
|
||||
|
@ -2375,7 +2339,6 @@
|
|||
BC55826A240BB40E00011AC0 /* RTMPStreamInfo.swift in Sources */,
|
||||
294B2D3423785E3800CE7BDC /* CircularBuffer.swift in Sources */,
|
||||
BC94E504263FE8400094C169 /* MP4TrackFragmentHeaderBox.swift in Sources */,
|
||||
BC20DF32250374A8007BC608 /* HKPictureInPictureController.swift in Sources */,
|
||||
BCA97BE7263C0B8B0027213C /* MP4FileTypeBox.swift in Sources */,
|
||||
29EB3E1F1ED059F7001CAE8B /* RTMPChunk.swift in Sources */,
|
||||
29EB3DFA1ED057A1001CAE8B /* CMVideoFormatDescription+Extension.swift in Sources */,
|
||||
|
@ -2440,7 +2403,6 @@
|
|||
BCC1A6BB2643F41600661156 /* MP4File.Builder.swift in Sources */,
|
||||
BC94E52E264146530094C169 /* MP4ReaderConvertible.swift in Sources */,
|
||||
BCC1A72D264FAC1800661156 /* ElementaryStreamSpecificData.swift in Sources */,
|
||||
BC20DF2E25037498007BC608 /* HKPictureInPictureControllerPosition.swift in Sources */,
|
||||
BCB976E126107B5600C9A649 /* TSAdaptationField.swift in Sources */,
|
||||
BCC1A6D5264461FE00661156 /* MP4HandlerBox.swift in Sources */,
|
||||
BCC1A7112647F25A00661156 /* DecoderConfigDescriptor.swift in Sources */,
|
||||
|
@ -2461,7 +2423,6 @@
|
|||
BCA97C0C263D80F40027213C /* MP4SampleEntry.swift in Sources */,
|
||||
29EB3E381ED05A41001CAE8B /* MD5.swift in Sources */,
|
||||
295891141EEB8D7200CE51E1 /* FLVFrameType.swift in Sources */,
|
||||
BC20DF302503749D007BC608 /* HKPictureInPictureControllerImpl.swift in Sources */,
|
||||
29EB3E1B1ED0589F001CAE8B /* AMF0Serializer.swift in Sources */,
|
||||
BCC1A70D2647F23200661156 /* ESDescriptor.swift in Sources */,
|
||||
BCA97C03263C61930027213C /* MP4MediaHeaderBox.swift in Sources */,
|
||||
|
@ -2516,7 +2477,6 @@
|
|||
2958911C1EEB8E3F00CE51E1 /* FLVAudioCodec.swift in Sources */,
|
||||
BC94E500263FE6B80094C169 /* MP4MovieFragmentHeaderBox.swift in Sources */,
|
||||
29EB3DF61ED0577C001CAE8B /* CMSampleBuffer+Extension.swift in Sources */,
|
||||
BC20DF36250374EA007BC608 /* HKPictureInPictureController+Extension.swift in Sources */,
|
||||
BCC1A729264FA1C100661156 /* ProfileLevelIndicationIndexDescriptor.swift in Sources */,
|
||||
29EB3E281ED05A0C001CAE8B /* RTMPTSocket.swift in Sources */,
|
||||
);
|
||||
|
|
|
@ -29,7 +29,6 @@ let package = Package(
|
|||
"Media",
|
||||
"MP4",
|
||||
"Net",
|
||||
"PiP",
|
||||
"RTMP",
|
||||
"Util",
|
||||
"Platforms",
|
||||
|
|
|
@ -1,86 +0,0 @@
|
|||
#if !os(macOS)
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
private var HKPictureInPictureControllerImplKey: UInt8 = 0
|
||||
|
||||
/// HKPictureInPictureController protocol default implementation.
|
||||
public extension HKPictureInPictureController where Self: UIViewController {
|
||||
var isPictureInPictureActive: Bool {
|
||||
impl.isPictureInPictureActive
|
||||
}
|
||||
|
||||
var pictureInPictureSize: CGSize {
|
||||
get {
|
||||
impl.pictureInPictureSize
|
||||
}
|
||||
set {
|
||||
impl.pictureInPictureSize = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var pictureInPicturePosition: HKPictureInPictureControllerPosition {
|
||||
get {
|
||||
impl.pictureInPicturePosition
|
||||
}
|
||||
set {
|
||||
impl.pictureInPicturePosition = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var pictureInPictureMargin: CGFloat {
|
||||
get {
|
||||
impl.pictureInPictureMargin
|
||||
}
|
||||
set {
|
||||
impl.pictureInPictureMargin = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var pictureInPictureCornerRadius: CGFloat {
|
||||
get {
|
||||
impl.pictureInPictureCornerRadius
|
||||
}
|
||||
set {
|
||||
impl.pictureInPictureCornerRadius = newValue
|
||||
}
|
||||
}
|
||||
|
||||
var pictureInPictureAnimationDuration: TimeInterval {
|
||||
get {
|
||||
impl.pictureInPictureAnimationDuration
|
||||
}
|
||||
set {
|
||||
impl.pictureInPictureAnimationDuration = newValue
|
||||
}
|
||||
}
|
||||
|
||||
private var impl: HKPictureInPictureControllerImpl {
|
||||
get {
|
||||
guard let object = objc_getAssociatedObject(self, &HKPictureInPictureControllerImplKey) as? HKPictureInPictureControllerImpl else {
|
||||
let impl = HKPictureInPictureControllerImpl(self)
|
||||
objc_setAssociatedObject(self, &HKPictureInPictureControllerImplKey, impl, .OBJC_ASSOCIATION_RETAIN)
|
||||
return impl
|
||||
}
|
||||
return object
|
||||
}
|
||||
set {
|
||||
objc_setAssociatedObject(self, &HKPictureInPictureControllerImplKey, newValue, .OBJC_ASSOCIATION_RETAIN)
|
||||
}
|
||||
}
|
||||
|
||||
func startPictureInPicture() {
|
||||
guard !impl.isPictureInPictureActive else {
|
||||
return
|
||||
}
|
||||
impl.startPictureInPicture()
|
||||
}
|
||||
|
||||
func stopPictureInPicture() {
|
||||
guard impl.isPictureInPictureActive else {
|
||||
return
|
||||
}
|
||||
impl.stopPictureInPicture()
|
||||
}
|
||||
}
|
||||
#endif
|
|
@ -1,16 +0,0 @@
|
|||
#if !os(macOS)
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
public protocol HKPictureInPictureController: AnyObject {
|
||||
var isPictureInPictureActive: Bool { get }
|
||||
var pictureInPictureSize: CGSize { get set }
|
||||
var pictureInPicturePosition: HKPictureInPictureControllerPosition { get set }
|
||||
var pictureInPictureMargin: CGFloat { get set }
|
||||
var pictureInPictureCornerRadius: CGFloat { get set }
|
||||
var pictureInPictureAnimationDuration: TimeInterval { get set }
|
||||
|
||||
func startPictureInPicture()
|
||||
func stopPictureInPicture()
|
||||
}
|
||||
#endif
|
|
@ -1,122 +0,0 @@
|
|||
#if !os(macOS)
|
||||
import Foundation
|
||||
import UIKit
|
||||
|
||||
class HKPictureInPictureControllerImpl: HKPictureInPictureController {
|
||||
static let margin: CGFloat = 16
|
||||
static let position: HKPictureInPictureControllerPosition = .bottomRight
|
||||
static let cornerRadius: CGFloat = 8
|
||||
static let animationDuration: TimeInterval = 0.3
|
||||
|
||||
var isPictureInPictureActive = false
|
||||
var pictureInPictureSize: CGSize = .init(width: 160, height: 90)
|
||||
var pictureInPictureMargin: CGFloat = HKPictureInPictureControllerImpl.margin
|
||||
var pictureInPicturePosition: HKPictureInPictureControllerPosition = HKPictureInPictureControllerImpl.position
|
||||
var pictureInPictureCornerRadius: CGFloat = HKPictureInPictureControllerImpl.cornerRadius
|
||||
var pictureInPictureAnimationDuration: TimeInterval = HKPictureInPictureControllerImpl.animationDuration
|
||||
|
||||
private var window: UIWindow?
|
||||
private var origin: CGPoint = .zero
|
||||
private var parent: UIViewController?
|
||||
private let viewController: UIViewController
|
||||
private lazy var panGestureRecognizer = UIPanGestureRecognizer(target: self, action: #selector(didPanGestureRecognizer(_:)))
|
||||
|
||||
init(_ viewController: UIViewController) {
|
||||
self.viewController = viewController
|
||||
self.parent = viewController.parent
|
||||
}
|
||||
|
||||
func startPictureInPicture() {
|
||||
guard !isPictureInPictureActive else {
|
||||
return
|
||||
}
|
||||
toggleWindow()
|
||||
viewController.view.addGestureRecognizer(panGestureRecognizer)
|
||||
#if os(iOS)
|
||||
NotificationCenter.default.addObserver(self, selector: #selector(orientationDidChange), name: UIDevice.orientationDidChangeNotification, object: nil)
|
||||
#endif
|
||||
isPictureInPictureActive = true
|
||||
}
|
||||
|
||||
func stopPictureInPicture() {
|
||||
guard isPictureInPictureActive else {
|
||||
return
|
||||
}
|
||||
toggleWindow()
|
||||
viewController.view.removeGestureRecognizer(panGestureRecognizer)
|
||||
#if os(iOS)
|
||||
NotificationCenter.default.removeObserver(self, name: UIDevice.orientationDidChangeNotification, object: nil)
|
||||
#endif
|
||||
isPictureInPictureActive = false
|
||||
}
|
||||
|
||||
private func toggleWindow() {
|
||||
if window == nil {
|
||||
viewController.removeFromParent()
|
||||
viewController.view.removeFromSuperview()
|
||||
window = UIWindow(frame: .zero)
|
||||
window?.rootViewController = viewController
|
||||
window?.makeKeyAndVisible()
|
||||
if #available(iOS 11.0, tvOS 11.0, *) {
|
||||
transform(parent?.view.window?.safeAreaInsets ?? .zero)
|
||||
} else {
|
||||
transform()
|
||||
}
|
||||
viewController.view.layer.cornerRadius = pictureInPictureCornerRadius
|
||||
} else {
|
||||
window?.rootViewController = nil
|
||||
window = nil
|
||||
parent?.addChild(viewController)
|
||||
parent?.view.addSubview(viewController.view)
|
||||
viewController.view.layer.cornerRadius = 0
|
||||
UIView.animate(withDuration: pictureInPictureAnimationDuration) { [weak self] in
|
||||
guard let self = self else {
|
||||
return
|
||||
}
|
||||
self.viewController.view.frame = self.parent?.view.bounds ?? .zero
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private func transform(_ insets: UIEdgeInsets = .zero) {
|
||||
UIView.animate(withDuration: pictureInPictureAnimationDuration) { [weak self] in
|
||||
guard let self = self, let window = self.window else {
|
||||
return
|
||||
}
|
||||
if self.origin == .zero || !UIScreen.main.bounds.contains(self.origin) {
|
||||
window.frame = .init(origin: self.pictureInPicturePosition.CGPoint(self, insets: insets), size: self.pictureInPictureSize)
|
||||
} else {
|
||||
window.frame = .init(origin: self.origin, size: self.pictureInPictureSize)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
@objc
|
||||
private func orientationDidChange() {
|
||||
switch UIDevice.current.orientation {
|
||||
case .landscapeLeft, .landscapeRight, .portrait, .portraitUpsideDown:
|
||||
if #available(iOS 11.0, *) {
|
||||
transform(parent?.view.window?.safeAreaInsets ?? .zero)
|
||||
} else {
|
||||
transform()
|
||||
}
|
||||
default:
|
||||
break
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@objc
|
||||
private func didPanGestureRecognizer(_ sender: UIPanGestureRecognizer) {
|
||||
guard let window = window else {
|
||||
return
|
||||
}
|
||||
let point: CGPoint = sender.translation(in: viewController.view)
|
||||
window.center = CGPoint(x: window.center.x + point.x, y: window.center.y + point.y)
|
||||
origin = window.frame.origin
|
||||
sender.setTranslation(.zero, in: viewController.view)
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
|
@ -1,35 +0,0 @@
|
|||
#if !os(macOS)
|
||||
import UIKit
|
||||
|
||||
public enum HKPictureInPictureControllerPosition {
|
||||
case topLeft
|
||||
case topRight
|
||||
case bottomRight
|
||||
case bottomLeft
|
||||
|
||||
func CGPoint(_ controller: HKPictureInPictureController, insets: UIEdgeInsets = .zero) -> CGPoint {
|
||||
let margin = controller.pictureInPictureMargin
|
||||
switch self {
|
||||
case .topLeft:
|
||||
return .init(
|
||||
x: margin + insets.left,
|
||||
y: margin + insets.top)
|
||||
case .topRight:
|
||||
return .init(
|
||||
x: UIScreen.main.bounds.width - controller.pictureInPictureSize.width - margin - insets.right,
|
||||
y: margin + insets.top
|
||||
)
|
||||
case .bottomLeft:
|
||||
return .init(
|
||||
x: margin + insets.left,
|
||||
y: UIScreen.main.bounds.height - controller.pictureInPictureSize.height - margin - insets.bottom
|
||||
)
|
||||
case .bottomRight:
|
||||
return .init(
|
||||
x: UIScreen.main.bounds.width - controller.pictureInPictureSize.width - margin - insets.right,
|
||||
y: UIScreen.main.bounds.height - controller.pictureInPictureSize.height - margin - insets.bottom
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
Loading…
Reference in New Issue