How to pick multiple videos as well as photos from gallery using Swift











up vote
2
down vote

favorite












I'm trying to pick both photos and videos from gallery.



I have done a few things like picked photos but not showing the videos. I have used BSImagepicker library and I have't found any video related thing in this library. If anyone have done such kind of work or know about any other library which picks both photos and videos please refer.



import UIKit
import Photos
import BSImageView
import BSImagePicker

class ViewController: UIViewController {
let pickerController = BSImagePickerViewController()
var SelectedAssets = [PHAsset]()
var PhotoArray = [UIImage]()
@IBOutlet var imageView: UIImageView!

@IBAction func buttonAction(_ sender: Any) {
pickImages()
}

func pickImages() {
self.bs_presentImagePickerController(pickerController, animated: true, select: { (asset: PHAsset) in
}, deselect: { (assets: PHAsset) in
}, cancel: { (assets: [PHAsset]) in
}, finish: { (assets: [PHAsset]) in
for i in 0..<assets.count {
self.SelectedAssets.append(assets[i])
}
self.convertAssetToImages()
}, completion: nil)
}

func convertAssetToImages(){
if SelectedAssets.count != 0 {
for i in 0..<SelectedAssets.count {
let manager = PHImageManager.default()
let option = PHImageRequestOptions()
var thumbnail = UIImage()
option.isSynchronous = true
manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 500, height: 500), contentMode: .aspectFit, options: option, resultHandler: { (result, info) in
thumbnail = result!
})
let data = UIImageJPEGRepresentation(thumbnail, 0.7)
let newImage = UIImage(data: data!)
self.PhotoArray.append(newImage! as UIImage)
}
hcArray = PhotoArray
self.imageView.animationImages = self.PhotoArray
self.imageView.animationDuration = 3.0
self.imageView.startAnimating()
}
}
}









share|improve this question




























    up vote
    2
    down vote

    favorite












    I'm trying to pick both photos and videos from gallery.



    I have done a few things like picked photos but not showing the videos. I have used BSImagepicker library and I have't found any video related thing in this library. If anyone have done such kind of work or know about any other library which picks both photos and videos please refer.



    import UIKit
    import Photos
    import BSImageView
    import BSImagePicker

    class ViewController: UIViewController {
    let pickerController = BSImagePickerViewController()
    var SelectedAssets = [PHAsset]()
    var PhotoArray = [UIImage]()
    @IBOutlet var imageView: UIImageView!

    @IBAction func buttonAction(_ sender: Any) {
    pickImages()
    }

    func pickImages() {
    self.bs_presentImagePickerController(pickerController, animated: true, select: { (asset: PHAsset) in
    }, deselect: { (assets: PHAsset) in
    }, cancel: { (assets: [PHAsset]) in
    }, finish: { (assets: [PHAsset]) in
    for i in 0..<assets.count {
    self.SelectedAssets.append(assets[i])
    }
    self.convertAssetToImages()
    }, completion: nil)
    }

    func convertAssetToImages(){
    if SelectedAssets.count != 0 {
    for i in 0..<SelectedAssets.count {
    let manager = PHImageManager.default()
    let option = PHImageRequestOptions()
    var thumbnail = UIImage()
    option.isSynchronous = true
    manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 500, height: 500), contentMode: .aspectFit, options: option, resultHandler: { (result, info) in
    thumbnail = result!
    })
    let data = UIImageJPEGRepresentation(thumbnail, 0.7)
    let newImage = UIImage(data: data!)
    self.PhotoArray.append(newImage! as UIImage)
    }
    hcArray = PhotoArray
    self.imageView.animationImages = self.PhotoArray
    self.imageView.animationDuration = 3.0
    self.imageView.startAnimating()
    }
    }
    }









    share|improve this question


























      up vote
      2
      down vote

      favorite









      up vote
      2
      down vote

      favorite











      I'm trying to pick both photos and videos from gallery.



      I have done a few things like picked photos but not showing the videos. I have used BSImagepicker library and I have't found any video related thing in this library. If anyone have done such kind of work or know about any other library which picks both photos and videos please refer.



      import UIKit
      import Photos
      import BSImageView
      import BSImagePicker

      class ViewController: UIViewController {
      let pickerController = BSImagePickerViewController()
      var SelectedAssets = [PHAsset]()
      var PhotoArray = [UIImage]()
      @IBOutlet var imageView: UIImageView!

      @IBAction func buttonAction(_ sender: Any) {
      pickImages()
      }

      func pickImages() {
      self.bs_presentImagePickerController(pickerController, animated: true, select: { (asset: PHAsset) in
      }, deselect: { (assets: PHAsset) in
      }, cancel: { (assets: [PHAsset]) in
      }, finish: { (assets: [PHAsset]) in
      for i in 0..<assets.count {
      self.SelectedAssets.append(assets[i])
      }
      self.convertAssetToImages()
      }, completion: nil)
      }

      func convertAssetToImages(){
      if SelectedAssets.count != 0 {
      for i in 0..<SelectedAssets.count {
      let manager = PHImageManager.default()
      let option = PHImageRequestOptions()
      var thumbnail = UIImage()
      option.isSynchronous = true
      manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 500, height: 500), contentMode: .aspectFit, options: option, resultHandler: { (result, info) in
      thumbnail = result!
      })
      let data = UIImageJPEGRepresentation(thumbnail, 0.7)
      let newImage = UIImage(data: data!)
      self.PhotoArray.append(newImage! as UIImage)
      }
      hcArray = PhotoArray
      self.imageView.animationImages = self.PhotoArray
      self.imageView.animationDuration = 3.0
      self.imageView.startAnimating()
      }
      }
      }









      share|improve this question















      I'm trying to pick both photos and videos from gallery.



      I have done a few things like picked photos but not showing the videos. I have used BSImagepicker library and I have't found any video related thing in this library. If anyone have done such kind of work or know about any other library which picks both photos and videos please refer.



      import UIKit
      import Photos
      import BSImageView
      import BSImagePicker

      class ViewController: UIViewController {
      let pickerController = BSImagePickerViewController()
      var SelectedAssets = [PHAsset]()
      var PhotoArray = [UIImage]()
      @IBOutlet var imageView: UIImageView!

      @IBAction func buttonAction(_ sender: Any) {
      pickImages()
      }

      func pickImages() {
      self.bs_presentImagePickerController(pickerController, animated: true, select: { (asset: PHAsset) in
      }, deselect: { (assets: PHAsset) in
      }, cancel: { (assets: [PHAsset]) in
      }, finish: { (assets: [PHAsset]) in
      for i in 0..<assets.count {
      self.SelectedAssets.append(assets[i])
      }
      self.convertAssetToImages()
      }, completion: nil)
      }

      func convertAssetToImages(){
      if SelectedAssets.count != 0 {
      for i in 0..<SelectedAssets.count {
      let manager = PHImageManager.default()
      let option = PHImageRequestOptions()
      var thumbnail = UIImage()
      option.isSynchronous = true
      manager.requestImage(for: SelectedAssets[i], targetSize: CGSize(width: 500, height: 500), contentMode: .aspectFit, options: option, resultHandler: { (result, info) in
      thumbnail = result!
      })
      let data = UIImageJPEGRepresentation(thumbnail, 0.7)
      let newImage = UIImage(data: data!)
      self.PhotoArray.append(newImage! as UIImage)
      }
      hcArray = PhotoArray
      self.imageView.animationImages = self.PhotoArray
      self.imageView.animationDuration = 3.0
      self.imageView.startAnimating()
      }
      }
      }






      ios swift






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 9 at 5:02









      rmaddy

      235k27306373




      235k27306373










      asked Nov 9 at 4:43









      Arslan Ahmed

      163




      163
























          2 Answers
          2






          active

          oldest

          votes

















          up vote
          0
          down vote













          Gallery is open source library in GitHub to select images as well as videos from photos in iOS.



          https://github.com/hyperoslo/Gallery



          Initialization:



          GalleryController is the main entry point, just instantiate and give it the delegate.



          let gallery = GalleryController()
          gallery.delegate = self
          present(gallery, animated: true, completion: nil)


          Delegate:



          The GalleryControllerDelegate requires you to implement some delegate methods in order to interact with the picker



          func galleryController(_ controller: GalleryController, didSelectImages images: [Image])
          func galleryController(_ controller: GalleryController, didSelectVideo video: Video)
          func galleryController(_ controller: GalleryController, requestLightbox images: [Image])
          func galleryControllerDidCancel(_ controller: GalleryController)


          enter image description here






          share|improve this answer





















          • Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
            – Arslan Ahmed
            Nov 9 at 5:56


















          up vote
          0
          down vote













          You are right, the designs of the libraries aren't great...



          Here, Fresh out of the oven:
          https://cocoapods.org/pods/CameraRoll



          I'll add a readme and improve it but it works well.



          first, add this to your plist



          <key>NSPhotoLibraryUsageDescription</key>
          <string>To Find images</string>


          Then Import



          import CameraRoll
          import Photos


          Then when you want to use it,



             let cr = CameraRoll()
          // For pitures use .Image mode
          cr.present(in: self, mode: .Video) { (assets) in
          // Returns array of PHAsset
          }
          }


          Use helper functions to convert



              let cr = CameraRoll()
          cr.present(in: self, mode: .Image) { (assets) in
          if let assets = assets, let first = assets.first {
          DispatchQueue.main.async {
          AssetManager.sharedInstance.getImageFromAsset(phAsset: first) { (image) in
          self.imageView.image = image
          }
          }
          }
          }





          share|improve this answer





















          • [!] Unable to find a specification for CameraRoll
            – Arslan Ahmed
            Nov 12 at 13:07











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














           

          draft saved


          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219986%2fhow-to-pick-multiple-videos-as-well-as-photos-from-gallery-using-swift%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote













          Gallery is open source library in GitHub to select images as well as videos from photos in iOS.



          https://github.com/hyperoslo/Gallery



          Initialization:



          GalleryController is the main entry point, just instantiate and give it the delegate.



          let gallery = GalleryController()
          gallery.delegate = self
          present(gallery, animated: true, completion: nil)


          Delegate:



          The GalleryControllerDelegate requires you to implement some delegate methods in order to interact with the picker



          func galleryController(_ controller: GalleryController, didSelectImages images: [Image])
          func galleryController(_ controller: GalleryController, didSelectVideo video: Video)
          func galleryController(_ controller: GalleryController, requestLightbox images: [Image])
          func galleryControllerDidCancel(_ controller: GalleryController)


          enter image description here






          share|improve this answer





















          • Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
            – Arslan Ahmed
            Nov 9 at 5:56















          up vote
          0
          down vote













          Gallery is open source library in GitHub to select images as well as videos from photos in iOS.



          https://github.com/hyperoslo/Gallery



          Initialization:



          GalleryController is the main entry point, just instantiate and give it the delegate.



          let gallery = GalleryController()
          gallery.delegate = self
          present(gallery, animated: true, completion: nil)


          Delegate:



          The GalleryControllerDelegate requires you to implement some delegate methods in order to interact with the picker



          func galleryController(_ controller: GalleryController, didSelectImages images: [Image])
          func galleryController(_ controller: GalleryController, didSelectVideo video: Video)
          func galleryController(_ controller: GalleryController, requestLightbox images: [Image])
          func galleryControllerDidCancel(_ controller: GalleryController)


          enter image description here






          share|improve this answer





















          • Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
            – Arslan Ahmed
            Nov 9 at 5:56













          up vote
          0
          down vote










          up vote
          0
          down vote









          Gallery is open source library in GitHub to select images as well as videos from photos in iOS.



          https://github.com/hyperoslo/Gallery



          Initialization:



          GalleryController is the main entry point, just instantiate and give it the delegate.



          let gallery = GalleryController()
          gallery.delegate = self
          present(gallery, animated: true, completion: nil)


          Delegate:



          The GalleryControllerDelegate requires you to implement some delegate methods in order to interact with the picker



          func galleryController(_ controller: GalleryController, didSelectImages images: [Image])
          func galleryController(_ controller: GalleryController, didSelectVideo video: Video)
          func galleryController(_ controller: GalleryController, requestLightbox images: [Image])
          func galleryControllerDidCancel(_ controller: GalleryController)


          enter image description here






          share|improve this answer












          Gallery is open source library in GitHub to select images as well as videos from photos in iOS.



          https://github.com/hyperoslo/Gallery



          Initialization:



          GalleryController is the main entry point, just instantiate and give it the delegate.



          let gallery = GalleryController()
          gallery.delegate = self
          present(gallery, animated: true, completion: nil)


          Delegate:



          The GalleryControllerDelegate requires you to implement some delegate methods in order to interact with the picker



          func galleryController(_ controller: GalleryController, didSelectImages images: [Image])
          func galleryController(_ controller: GalleryController, didSelectVideo video: Video)
          func galleryController(_ controller: GalleryController, requestLightbox images: [Image])
          func galleryControllerDidCancel(_ controller: GalleryController)


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 5:40









          Sateesh

          1,300615




          1,300615












          • Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
            – Arslan Ahmed
            Nov 9 at 5:56


















          • Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
            – Arslan Ahmed
            Nov 9 at 5:56
















          Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
          – Arslan Ahmed
          Nov 9 at 5:56




          Thanks for your response and i know about this library, actually i'm looking for iphone like library, i have to follow the design.
          – Arslan Ahmed
          Nov 9 at 5:56












          up vote
          0
          down vote













          You are right, the designs of the libraries aren't great...



          Here, Fresh out of the oven:
          https://cocoapods.org/pods/CameraRoll



          I'll add a readme and improve it but it works well.



          first, add this to your plist



          <key>NSPhotoLibraryUsageDescription</key>
          <string>To Find images</string>


          Then Import



          import CameraRoll
          import Photos


          Then when you want to use it,



             let cr = CameraRoll()
          // For pitures use .Image mode
          cr.present(in: self, mode: .Video) { (assets) in
          // Returns array of PHAsset
          }
          }


          Use helper functions to convert



              let cr = CameraRoll()
          cr.present(in: self, mode: .Image) { (assets) in
          if let assets = assets, let first = assets.first {
          DispatchQueue.main.async {
          AssetManager.sharedInstance.getImageFromAsset(phAsset: first) { (image) in
          self.imageView.image = image
          }
          }
          }
          }





          share|improve this answer





















          • [!] Unable to find a specification for CameraRoll
            – Arslan Ahmed
            Nov 12 at 13:07















          up vote
          0
          down vote













          You are right, the designs of the libraries aren't great...



          Here, Fresh out of the oven:
          https://cocoapods.org/pods/CameraRoll



          I'll add a readme and improve it but it works well.



          first, add this to your plist



          <key>NSPhotoLibraryUsageDescription</key>
          <string>To Find images</string>


          Then Import



          import CameraRoll
          import Photos


          Then when you want to use it,



             let cr = CameraRoll()
          // For pitures use .Image mode
          cr.present(in: self, mode: .Video) { (assets) in
          // Returns array of PHAsset
          }
          }


          Use helper functions to convert



              let cr = CameraRoll()
          cr.present(in: self, mode: .Image) { (assets) in
          if let assets = assets, let first = assets.first {
          DispatchQueue.main.async {
          AssetManager.sharedInstance.getImageFromAsset(phAsset: first) { (image) in
          self.imageView.image = image
          }
          }
          }
          }





          share|improve this answer





















          • [!] Unable to find a specification for CameraRoll
            – Arslan Ahmed
            Nov 12 at 13:07













          up vote
          0
          down vote










          up vote
          0
          down vote









          You are right, the designs of the libraries aren't great...



          Here, Fresh out of the oven:
          https://cocoapods.org/pods/CameraRoll



          I'll add a readme and improve it but it works well.



          first, add this to your plist



          <key>NSPhotoLibraryUsageDescription</key>
          <string>To Find images</string>


          Then Import



          import CameraRoll
          import Photos


          Then when you want to use it,



             let cr = CameraRoll()
          // For pitures use .Image mode
          cr.present(in: self, mode: .Video) { (assets) in
          // Returns array of PHAsset
          }
          }


          Use helper functions to convert



              let cr = CameraRoll()
          cr.present(in: self, mode: .Image) { (assets) in
          if let assets = assets, let first = assets.first {
          DispatchQueue.main.async {
          AssetManager.sharedInstance.getImageFromAsset(phAsset: first) { (image) in
          self.imageView.image = image
          }
          }
          }
          }





          share|improve this answer












          You are right, the designs of the libraries aren't great...



          Here, Fresh out of the oven:
          https://cocoapods.org/pods/CameraRoll



          I'll add a readme and improve it but it works well.



          first, add this to your plist



          <key>NSPhotoLibraryUsageDescription</key>
          <string>To Find images</string>


          Then Import



          import CameraRoll
          import Photos


          Then when you want to use it,



             let cr = CameraRoll()
          // For pitures use .Image mode
          cr.present(in: self, mode: .Video) { (assets) in
          // Returns array of PHAsset
          }
          }


          Use helper functions to convert



              let cr = CameraRoll()
          cr.present(in: self, mode: .Image) { (assets) in
          if let assets = assets, let first = assets.first {
          DispatchQueue.main.async {
          AssetManager.sharedInstance.getImageFromAsset(phAsset: first) { (image) in
          self.imageView.image = image
          }
          }
          }
          }






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 9 at 10:31









          shayegh

          1346




          1346












          • [!] Unable to find a specification for CameraRoll
            – Arslan Ahmed
            Nov 12 at 13:07


















          • [!] Unable to find a specification for CameraRoll
            – Arslan Ahmed
            Nov 12 at 13:07
















          [!] Unable to find a specification for CameraRoll
          – Arslan Ahmed
          Nov 12 at 13:07




          [!] Unable to find a specification for CameraRoll
          – Arslan Ahmed
          Nov 12 at 13:07


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53219986%2fhow-to-pick-multiple-videos-as-well-as-photos-from-gallery-using-swift%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Schultheiß

          Verwaltungsgliederung Dänemarks

          Liste der Kulturdenkmale in Wilsdruff