Created
February 15, 2022 01:09
-
-
Save FireRayo/508952f39b5539bba08c8eb5e18ebfbc to your computer and use it in GitHub Desktop.
video player picker - AVPlayer, PHPickerViewController, pick and play images, videos, livephotos - SWIFT, SWIFTUI
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Complete project: | |
// https://drive.google.com/file/d/1gDRF8xoUmfKXyhDEvWvQx0OXBQuSzFiK/view?usp=sharing | |
// | |
// PhotoPicker.swift | |
// PHPickerViewController_Player_Picker_SwiftUI | |
// | |
import SwiftUI | |
import PhotosUI | |
// SwiftUI view for PHPickerViewController | |
struct PhotoPicker: UIViewControllerRepresentable { | |
typealias UIViewControllerType = PHPickerViewController | |
@ObservedObject var service: PhotoPickerService | |
func makeUIViewController(context: Context) -> PHPickerViewController { | |
var config = PHPickerConfiguration() | |
config.filter = .any(of: service.filters) | |
config.selectionLimit = service.selectionLimit | |
config.preferredAssetRepresentationMode = .current | |
let controller = PHPickerViewController(configuration: config) | |
controller.delegate = context.coordinator | |
return controller | |
} | |
func updateUIViewController(_ uiViewController: PHPickerViewController, context: Context) { | |
} | |
func makeCoordinator() -> Coordinator { | |
Coordinator(with: self) | |
} | |
class Coordinator: PHPickerViewControllerDelegate { | |
var photoPicker: PhotoPicker | |
init(with photoPicker: PhotoPicker) { | |
self.photoPicker = photoPicker | |
} | |
func picker(_ picker: PHPickerViewController, didFinishPicking results: [PHPickerResult]) { | |
photoPicker.service.isPresented = false | |
guard !results.isEmpty else { | |
return | |
} | |
photoPicker.service.results = results | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment