Pick Video And Pics from photo gallary please
Pick Video And Pics from photo gallary please
I'm desperately trying to add video picking option to my app. The app can take a picture and select pictures but it cannot select video file. I want the users to be able to select video from the photo library just as easily as they can select a photo. But most people I have asked seem to think it is not possible. But of course, it is not. I have used many app with this feature. Or this is not something I can do with Xcode?
}
let actionsheet = UIAlertController(title: nil, message: nil, preferredStyle: .alert)
actionsheet.addAction(UIAlertAction(title: "Gallery", style: .default, handler: { (alert: UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.photoLibrary){
let mypickerController = UIImagePickerController()
mypickerController.delegate = self
mypickerController.sourceType = .photoLibrary
self.present(mypickerController, animated: true, completion: nil)
}
}))
actionsheet.addAction(UIAlertAction(title: "Camera", style: .default, handler: { (alert: UIAlertAction) in
if UIImagePickerController.isSourceTypeAvailable(.camera){
let myPickerController = UIImagePickerController()
myPickerController.delegate = self
myPickerController.sourceType = .camera
self.present(myPickerController, animated: true, completion: nil)
}
}))
actionsheet.addAction(UIAlertAction(title: "Cancel", style: .cancel, handler: nil))
self.present(actionsheet, animated: true, completion: nil)
}
@IBAction func onSaveButton(_ sender: Any) {
print("screenshot pressed")
//let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
//appDelegate?.myInterstitial = appDelegate?.createAndLoadInterstitial()
if firstImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: firstImage)
}
if secondImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: secondImage)
}
if thirdImage.image == nil{
GlobalFunction.sharedManager.setWhiteBackground(selectView: thirdImage)
}
let image = GlobalFunction.sharedManager.takeScreenshot(theView: backView)//takeScreenshot(theView: backView)
UIImageWriteToSavedPhotosAlbum(image, self, #selector(image(image:didFinishSavingWithError:contextInfo:)), nil)
}
@IBAction func onCancelButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC") as! ViewController
self.present(vc, animated: true, completion: nil)
}
@IBAction func onAddButton(_ sender: Any) {
let vc = self.storyboard?.instantiateViewController(withIdentifier: "mainVC") as! ViewController
self.present(vc, animated: true, completion: nil)
}
@objc func image(image: UIImage, didFinishSavingWithError error: NSErrorPointer, contextInfo: UnsafeRawPointer) {
DispatchQueue.main.async{
self.showAlertView(message: "Your story has been saved to your Camera Roll", completionHandler: { (a) in
let appDelegate: AppDelegate? = UIApplication.shared.delegate as? AppDelegate
appDelegate?.myInterstitial = appDelegate?.createAndLoadInterstitial()
})
//UIAlertView(title: "Success", message: "Your story has been saved to your Camera Roll", delegate: nil, cancelButtonTitle: "Close").show()
}
}
func takeScreenshot(theView: UIView) -> UIImage {
UIGraphicsBeginImageContextWithOptions(theView.bounds.size, true, 0.0)
theView.drawHierarchy(in: theView.bounds, afterScreenUpdates: true)
let image = UIGraphicsGetImageFromCurrentImageContext()
UIGraphicsEndImageContext()
return image!
}
func circleCropDidCancel() {
dismiss(animated: false, completion: nil)
}
func circleCropDidCropImage(_ image: UIImage) {
dismiss(animated: false, completion: nil)
if selected == 1{
firstImage.image = image
}else if selected == 2{
secondImage.image = image
}else if selected == 3{
thirdImage.image = image
}
}
}
1 Answer
1
UIImagePickerController has a mediaTypes
property. It determines what kind of media the picker can pick. You are not setting mypickerController.mediaTypes
to include videos.
mediaTypes
mypickerController.mediaTypes
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
One choice is to look at the documentation for UIImagePickerController or google. Another choice is to do nothing and scream URGENT. The first is better.
– matt
4 hours ago