Swiftpack.co - ColdGrub1384/Pipable as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ColdGrub1384.
ColdGrub1384/Pipable 1.0.3
Picture in Picture for any UIView
⭐️ 2
🕓 1 week ago
iOS
.package(url: "https://github.com/ColdGrub1384/Pipable.git", from: "1.0.3")

Pipable

Pipable is an iOS library to implement Picture in Picture for any UIView. This is done just by conforming to a protocol.

The "Audio, AirPlay and Picture in Picture" background mode must be enabled and an audio session must be active for PIP to work.

Requires iOS / iPadOS 15+.

screenshot

Usage

Create a UIView that conforms to Pipable. Start an audio session and then use the pictureInPictureController object automatically provided by the Pipable protocol to start PIP.

import Pipable
import UIKit
import AVKit

class MyTextView: UITextView, Pipable {

    var pictureInPictureDelegate: PictureInPictureDelegate?
    
    var previewSize: CGSize {
        CGSize(width: 512, height: 512)
    }
    
    func willTakeSnapshot() {
    }
    
    func didTakeSnapshot() {
    }
}

let textView = MyTextView()
textView.text = "Hello World!"

// Update the snapshot (do this everytime the text is changed)

textView.updatePictureInPictureSnapshot()

// Start an audio session

do {
    try AVAudioSession.sharedInstance().setCategory(.playback)
    try AVAudioSession.sharedInstance().setActive(true, options: [])
} catch {
    print(error.localizedDescription)
}

// Start PIP

textView.pictureInPictureController?.startPictureInPicture()

GitHub

link
Stars: 2
Last commit: 2 weeks ago
jonrohan Something's broken? Yell at me @ptrpavlik. Praise and feedback (and money) is also welcome.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics