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()
}
}
}
ios swift
add a comment |
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()
}
}
}
ios swift
add a comment |
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()
}
}
}
ios swift
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
ios swift
edited Nov 9 at 5:02
rmaddy
235k27306373
235k27306373
asked Nov 9 at 4:43
Arslan Ahmed
163
163
add a comment |
add a comment |
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)
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
add a comment |
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
}
}
}
}
[!] Unable to find a specification forCameraRoll
– Arslan Ahmed
Nov 12 at 13:07
add a comment |
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)
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
add a comment |
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)
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
add a comment |
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)
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)
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
add a comment |
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
add a comment |
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
}
}
}
}
[!] Unable to find a specification forCameraRoll
– Arslan Ahmed
Nov 12 at 13:07
add a comment |
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
}
}
}
}
[!] Unable to find a specification forCameraRoll
– Arslan Ahmed
Nov 12 at 13:07
add a comment |
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
}
}
}
}
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
}
}
}
}
answered Nov 9 at 10:31
shayegh
1346
1346
[!] Unable to find a specification forCameraRoll
– Arslan Ahmed
Nov 12 at 13:07
add a comment |
[!] Unable to find a specification forCameraRoll
– 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
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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