作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我只希望库中有一种类型的视频。使用默认库。我的应用程序目前正在使用 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/
我是一名优秀的程序员,十分优秀!