gpt4 book ai didi

swift - 如何在 photoLibrary UIimgaePickerController swift 中过滤扩展

转载 作者:行者123 更新时间:2023-11-28 09:22:52 24 4
gpt4 key购买 nike

我只希望库中有一种类型的视频。使用默认库。我的应用程序目前正在使用 UIImagePickerController (.photoLibrary) 从应用程序文档目录中获取图像和视频。我只想显示一种视频类型 .mp4

import AVFoundation
import MobileCoreServices
import Photos
import UIKit

class CameraLibraryTestViewController: UIViewController {
@IBOutlet weak var imgView: UIImageView!

let picker = UIImagePickerController()


override func viewDidLoad() {
super.viewDidLoad()


}

@IBAction func bAction(_ sender: Any) {
picker.mediaTypes = ["public.image", "public.mp4"] // filter extesion mp4 didn't work,
picker.sourceType = .photoLibrary
picker.allowsEditing = false
picker.delegate = self

present(picker, animated: true)
}
}



extension CameraLibraryTestViewController: UINavigationControllerDelegate, UIImagePickerControllerDelegate {
public func imagePickerControllerDidCancel(_ picker: UIImagePickerController) {
dismiss(animated: true, completion: nil)
}

func navigationController(_ navigationController: UINavigationController, willShow viewController: UIViewController, animated: Bool) {
viewController.navigationItem.title = "Jeri Library"
picker.setEditing(false, animated: true)
print("test or check: \(viewController.debugDescription)")
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String: Any]) {
let assetPath = info[UIImagePickerControllerReferenceURL] as! NSURL

if (assetPath.absoluteString?.hasSuffix("MOV"))! {
print("MOV")
dismiss(animated: true) {
self.navigationController?.pushViewController(EmojiReadViewController(), animated: true)
}
}
else if (assetPath.absoluteString?.hasSuffix("MP4"))! {
print("MP4")
dismiss(animated: true) {
self.navigationController?.pushViewController(EmojiReadViewController(), animated: true)
}
}
else if (assetPath.absoluteString?.hasSuffix("M4V"))! {
print("M4V")
dismiss(animated: true) {
self.navigationController?.pushViewController(EmojiReadViewController(), animated: true)
}
}
else {
print("Unknown")
dismiss(animated: true, completion: nil)
}
}
}

我尝试使用 mediaType [kUTTypeMPEG4 as String] 但它仍然不起作用,它在 didFinishPickingMediaWithInfo 中它仅用于从库中选择后的过滤器。

如果我使用 kUTTypeMovie 它会获取本地存储中的所有视频

最佳答案

这将只显示视频

picker.mediaTypes = [ "public.movie"]

关于swift - 如何在 photoLibrary UIimgaePickerController swift 中过滤扩展,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53038759/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com