How do I get the video to play in my Video Selection ControllerHow can I disable the UITableView selection?Passing Data between View ControllersHow to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsHow to show images from API in CollectionViewCan't implement required methods of JSQMessagesViewController Swift 3Issues with casting celltypes to dequeueHow can I programmatically make a UICollectionView fill a UITableViewCell?Swift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableView

What are some good books on Machine Learning and AI like Krugman, Wells and Graddy's "Essentials of Economics"

Im going to France and my passport expires June 19th

Why didn't Boeing produce its own regional jet?

Personal Teleportation: From Rags to Riches

How do conventional missiles fly?

How much of data wrangling is a data scientist's job?

Can I run a new neutral wire to repair a broken circuit?

Intersection Puzzle

What killed these X2 caps?

Is "remove commented out code" correct English?

Why no variance term in Bayesian logistic regression?

What mechanic is there to disable a threat instead of killing it?

Is it logically or scientifically possible to artificially send energy to the body?

How do I deal with an unproductive colleague in a small company?

Arrow those variables!

Unlock My Phone! February 2018

Is there an expression that means doing something right before you will need it rather than doing it in case you might need it?

Should I tell management that I intend to leave due to bad software development practices?

How can I deal with my CEO asking me to hire someone with a higher salary than me, a co-founder?

How can saying a song's name be a copyright violation?

If human space travel is limited by the G force vulnerability, is there a way to counter G forces?

How seriously should I take size and weight limits of hand luggage?

What reasons are there for a Capitalist to oppose a 100% inheritance tax?

How do I gain back my faith in my PhD degree?



How do I get the video to play in my Video Selection Controller


How can I disable the UITableView selection?Passing Data between View ControllersHow to detect tableView cell touched or clicked in swiftExpand and Collapse tableview cellsHow to show images from API in CollectionViewCan't implement required methods of JSQMessagesViewController Swift 3Issues with casting celltypes to dequeueHow can I programmatically make a UICollectionView fill a UITableViewCell?Swift Error - Use of undeclared type 'cell' - Collection ViewSwift vertical UICollectionView inside UITableView













0















I wrote a video selection controller so a user can select a video he wants to upload to firebase. Right now the problem I am having is that I can select the video but I cannot play it in the main view. It should work a little like the image/video selector in Instagram where if it's a video it automatically plays it. I don't need images at all, I only need videos to be uploaded.



What I see right now when select the video is a still of the first frame:



Video Selection Screen



I would be very greatful if someone could help me by telling me where I need to add what to making this video play automatically, or even with a play button in the middle of the screen.



My code right now to show the selection is as follow:



import UIKit
import Firebase
import Photos

private let reuseIdentifier = "SelectVideoCell"
private let headerIdentifier = "SelectVideoHeader"

class SelectVideoController: UICollectionViewController, UICollectionViewDelegateFlowLayout

// MARK: - Properties

var images = [UIImage]()
var assets = [PHAsset]()
var selectedImage: UIImage?
var header: SelectVideoHeader?

// MARK: - Init

override func viewDidLoad()
super.viewDidLoad()

configureUI()
fetchVideos()

//Register cell classes
collectionView.register(SelectVideoCell.self, forCellWithReuseIdentifier: reuseIdentifier)
collectionView.register(SelectVideoHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)

collectionView.backgroundColor = UIColor(red: 227/255, green: 227/255, blue: 227/255, alpha: 1)


// MARK: - UICollectionViewFlowLayout

func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
let width = view.frame.width

return CGSize(width: width, height: width)


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
let width = (view.frame.width - 3) / 4
return CGSize(width: width, height: width)


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
return 1


func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
return 1


// MARK: - UICollectionViewDataSource

override func numberOfSections(in collectionView: UICollectionView) -> Int
return 1


override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
return images.count


override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! SelectVideoHeader

self.header = header

if let selectedImage = self.selectedImage

// Index selected image
if let index = self.images.index(of: selectedImage)

// Asset associated with Selected Image
let selectedAsset = self.assets[index]

let videoManager = PHImageManager.default()
let targetSize = CGSize(width: 600, height: 600)



// Request Image
videoManager.requestImage(for: selectedAsset, targetSize: targetSize, contentMode: .default, options: nil) (image, info) in

header.videoSelectView.image = image





return header


override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! SelectVideoCell

cell.videoSelectView.image = images[indexPath.row]

return cell


override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
self.selectedImage = images[indexPath.row]
self.collectionView?.reloadData()

let indexPath = IndexPath(item: 0, section: 0)
collectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)


@objc func handleDismiss()
dismiss(animated: true, completion: nil)


@objc func handleNext()
let uploadController = UploadVideoController()
uploadController.selectedImage = header?.videoSelectView.image
let navController = UINavigationController(rootViewController: uploadController)
present(navController, animated: true, completion: nil)


func configureUI()

navigationController?.navigationBar.tintColor = .black
navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
navigationController?.navigationBar.shadowImage = (UIImage())
//navigationItem.title = "Videos"

navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleDismiss))
navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(handleNext))


func getAssetFetchOptions() -> PHFetchOptions

let options = PHFetchOptions()

// Fetch Limit
options.fetchLimit = 30

// Sort Videos by Date
let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: false)

// Set Sort Descriptor for Options
options.sortDescriptors = [sortDescriptor]

// Return Options
return options



func fetchVideos()

let allVideos = PHAsset.fetchAssets(with: .video, options: getAssetFetchOptions())

print("Function running")

// Fetch Videos on Background Thread
DispatchQueue.global(qos: .background).async

// Enumerate Objects
allVideos.enumerateObjects( (asset, count, stop) in

print("Count is (count)")

let videoManager = PHImageManager.default()
let targetSize = CGSize(width: 600, height: 600)
let options = PHImageRequestOptions()
options.isSynchronous = true

// Request Video representation for specific Asset
videoManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: (image, info) in

if let image = image

// Append image to data source
self.images.append(image)

// Append asset to data source
self.assets.append(asset)

// Set selected Image
if self.selectedImage == nil
self.selectedImage = image


// Reload collectionView with images once counr has completed
if count == allVideos.count - 1

// Reload collectionView on main thread
DispatchQueue.main.async
self.collectionView?.reloadData()



)
)



override var prefersStatusBarHidden: Bool
return true











share|improve this question




























    0















    I wrote a video selection controller so a user can select a video he wants to upload to firebase. Right now the problem I am having is that I can select the video but I cannot play it in the main view. It should work a little like the image/video selector in Instagram where if it's a video it automatically plays it. I don't need images at all, I only need videos to be uploaded.



    What I see right now when select the video is a still of the first frame:



    Video Selection Screen



    I would be very greatful if someone could help me by telling me where I need to add what to making this video play automatically, or even with a play button in the middle of the screen.



    My code right now to show the selection is as follow:



    import UIKit
    import Firebase
    import Photos

    private let reuseIdentifier = "SelectVideoCell"
    private let headerIdentifier = "SelectVideoHeader"

    class SelectVideoController: UICollectionViewController, UICollectionViewDelegateFlowLayout

    // MARK: - Properties

    var images = [UIImage]()
    var assets = [PHAsset]()
    var selectedImage: UIImage?
    var header: SelectVideoHeader?

    // MARK: - Init

    override func viewDidLoad()
    super.viewDidLoad()

    configureUI()
    fetchVideos()

    //Register cell classes
    collectionView.register(SelectVideoCell.self, forCellWithReuseIdentifier: reuseIdentifier)
    collectionView.register(SelectVideoHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)

    collectionView.backgroundColor = UIColor(red: 227/255, green: 227/255, blue: 227/255, alpha: 1)


    // MARK: - UICollectionViewFlowLayout

    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
    let width = view.frame.width

    return CGSize(width: width, height: width)


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
    let width = (view.frame.width - 3) / 4
    return CGSize(width: width, height: width)


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
    return 1


    func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
    return 1


    // MARK: - UICollectionViewDataSource

    override func numberOfSections(in collectionView: UICollectionView) -> Int
    return 1


    override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
    return images.count


    override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

    let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! SelectVideoHeader

    self.header = header

    if let selectedImage = self.selectedImage

    // Index selected image
    if let index = self.images.index(of: selectedImage)

    // Asset associated with Selected Image
    let selectedAsset = self.assets[index]

    let videoManager = PHImageManager.default()
    let targetSize = CGSize(width: 600, height: 600)



    // Request Image
    videoManager.requestImage(for: selectedAsset, targetSize: targetSize, contentMode: .default, options: nil) (image, info) in

    header.videoSelectView.image = image





    return header


    override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

    let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! SelectVideoCell

    cell.videoSelectView.image = images[indexPath.row]

    return cell


    override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
    self.selectedImage = images[indexPath.row]
    self.collectionView?.reloadData()

    let indexPath = IndexPath(item: 0, section: 0)
    collectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)


    @objc func handleDismiss()
    dismiss(animated: true, completion: nil)


    @objc func handleNext()
    let uploadController = UploadVideoController()
    uploadController.selectedImage = header?.videoSelectView.image
    let navController = UINavigationController(rootViewController: uploadController)
    present(navController, animated: true, completion: nil)


    func configureUI()

    navigationController?.navigationBar.tintColor = .black
    navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
    navigationController?.navigationBar.shadowImage = (UIImage())
    //navigationItem.title = "Videos"

    navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleDismiss))
    navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(handleNext))


    func getAssetFetchOptions() -> PHFetchOptions

    let options = PHFetchOptions()

    // Fetch Limit
    options.fetchLimit = 30

    // Sort Videos by Date
    let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: false)

    // Set Sort Descriptor for Options
    options.sortDescriptors = [sortDescriptor]

    // Return Options
    return options



    func fetchVideos()

    let allVideos = PHAsset.fetchAssets(with: .video, options: getAssetFetchOptions())

    print("Function running")

    // Fetch Videos on Background Thread
    DispatchQueue.global(qos: .background).async

    // Enumerate Objects
    allVideos.enumerateObjects( (asset, count, stop) in

    print("Count is (count)")

    let videoManager = PHImageManager.default()
    let targetSize = CGSize(width: 600, height: 600)
    let options = PHImageRequestOptions()
    options.isSynchronous = true

    // Request Video representation for specific Asset
    videoManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: (image, info) in

    if let image = image

    // Append image to data source
    self.images.append(image)

    // Append asset to data source
    self.assets.append(asset)

    // Set selected Image
    if self.selectedImage == nil
    self.selectedImage = image


    // Reload collectionView with images once counr has completed
    if count == allVideos.count - 1

    // Reload collectionView on main thread
    DispatchQueue.main.async
    self.collectionView?.reloadData()



    )
    )



    override var prefersStatusBarHidden: Bool
    return true











    share|improve this question


























      0












      0








      0








      I wrote a video selection controller so a user can select a video he wants to upload to firebase. Right now the problem I am having is that I can select the video but I cannot play it in the main view. It should work a little like the image/video selector in Instagram where if it's a video it automatically plays it. I don't need images at all, I only need videos to be uploaded.



      What I see right now when select the video is a still of the first frame:



      Video Selection Screen



      I would be very greatful if someone could help me by telling me where I need to add what to making this video play automatically, or even with a play button in the middle of the screen.



      My code right now to show the selection is as follow:



      import UIKit
      import Firebase
      import Photos

      private let reuseIdentifier = "SelectVideoCell"
      private let headerIdentifier = "SelectVideoHeader"

      class SelectVideoController: UICollectionViewController, UICollectionViewDelegateFlowLayout

      // MARK: - Properties

      var images = [UIImage]()
      var assets = [PHAsset]()
      var selectedImage: UIImage?
      var header: SelectVideoHeader?

      // MARK: - Init

      override func viewDidLoad()
      super.viewDidLoad()

      configureUI()
      fetchVideos()

      //Register cell classes
      collectionView.register(SelectVideoCell.self, forCellWithReuseIdentifier: reuseIdentifier)
      collectionView.register(SelectVideoHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)

      collectionView.backgroundColor = UIColor(red: 227/255, green: 227/255, blue: 227/255, alpha: 1)


      // MARK: - UICollectionViewFlowLayout

      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
      let width = view.frame.width

      return CGSize(width: width, height: width)


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
      let width = (view.frame.width - 3) / 4
      return CGSize(width: width, height: width)


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
      return 1


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
      return 1


      // MARK: - UICollectionViewDataSource

      override func numberOfSections(in collectionView: UICollectionView) -> Int
      return 1


      override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
      return images.count


      override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

      let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! SelectVideoHeader

      self.header = header

      if let selectedImage = self.selectedImage

      // Index selected image
      if let index = self.images.index(of: selectedImage)

      // Asset associated with Selected Image
      let selectedAsset = self.assets[index]

      let videoManager = PHImageManager.default()
      let targetSize = CGSize(width: 600, height: 600)



      // Request Image
      videoManager.requestImage(for: selectedAsset, targetSize: targetSize, contentMode: .default, options: nil) (image, info) in

      header.videoSelectView.image = image





      return header


      override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! SelectVideoCell

      cell.videoSelectView.image = images[indexPath.row]

      return cell


      override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
      self.selectedImage = images[indexPath.row]
      self.collectionView?.reloadData()

      let indexPath = IndexPath(item: 0, section: 0)
      collectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)


      @objc func handleDismiss()
      dismiss(animated: true, completion: nil)


      @objc func handleNext()
      let uploadController = UploadVideoController()
      uploadController.selectedImage = header?.videoSelectView.image
      let navController = UINavigationController(rootViewController: uploadController)
      present(navController, animated: true, completion: nil)


      func configureUI()

      navigationController?.navigationBar.tintColor = .black
      navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
      navigationController?.navigationBar.shadowImage = (UIImage())
      //navigationItem.title = "Videos"

      navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleDismiss))
      navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(handleNext))


      func getAssetFetchOptions() -> PHFetchOptions

      let options = PHFetchOptions()

      // Fetch Limit
      options.fetchLimit = 30

      // Sort Videos by Date
      let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: false)

      // Set Sort Descriptor for Options
      options.sortDescriptors = [sortDescriptor]

      // Return Options
      return options



      func fetchVideos()

      let allVideos = PHAsset.fetchAssets(with: .video, options: getAssetFetchOptions())

      print("Function running")

      // Fetch Videos on Background Thread
      DispatchQueue.global(qos: .background).async

      // Enumerate Objects
      allVideos.enumerateObjects( (asset, count, stop) in

      print("Count is (count)")

      let videoManager = PHImageManager.default()
      let targetSize = CGSize(width: 600, height: 600)
      let options = PHImageRequestOptions()
      options.isSynchronous = true

      // Request Video representation for specific Asset
      videoManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: (image, info) in

      if let image = image

      // Append image to data source
      self.images.append(image)

      // Append asset to data source
      self.assets.append(asset)

      // Set selected Image
      if self.selectedImage == nil
      self.selectedImage = image


      // Reload collectionView with images once counr has completed
      if count == allVideos.count - 1

      // Reload collectionView on main thread
      DispatchQueue.main.async
      self.collectionView?.reloadData()



      )
      )



      override var prefersStatusBarHidden: Bool
      return true











      share|improve this question
















      I wrote a video selection controller so a user can select a video he wants to upload to firebase. Right now the problem I am having is that I can select the video but I cannot play it in the main view. It should work a little like the image/video selector in Instagram where if it's a video it automatically plays it. I don't need images at all, I only need videos to be uploaded.



      What I see right now when select the video is a still of the first frame:



      Video Selection Screen



      I would be very greatful if someone could help me by telling me where I need to add what to making this video play automatically, or even with a play button in the middle of the screen.



      My code right now to show the selection is as follow:



      import UIKit
      import Firebase
      import Photos

      private let reuseIdentifier = "SelectVideoCell"
      private let headerIdentifier = "SelectVideoHeader"

      class SelectVideoController: UICollectionViewController, UICollectionViewDelegateFlowLayout

      // MARK: - Properties

      var images = [UIImage]()
      var assets = [PHAsset]()
      var selectedImage: UIImage?
      var header: SelectVideoHeader?

      // MARK: - Init

      override func viewDidLoad()
      super.viewDidLoad()

      configureUI()
      fetchVideos()

      //Register cell classes
      collectionView.register(SelectVideoCell.self, forCellWithReuseIdentifier: reuseIdentifier)
      collectionView.register(SelectVideoHeader.self, forSupplementaryViewOfKind: UICollectionView.elementKindSectionHeader, withReuseIdentifier: headerIdentifier)

      collectionView.backgroundColor = UIColor(red: 227/255, green: 227/255, blue: 227/255, alpha: 1)


      // MARK: - UICollectionViewFlowLayout

      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -> CGSize
      let width = view.frame.width

      return CGSize(width: width, height: width)


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, sizeForItemAt indexPath: IndexPath) -> CGSize
      let width = (view.frame.width - 3) / 4
      return CGSize(width: width, height: width)


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumInteritemSpacingForSectionAt section: Int) -> CGFloat
      return 1


      func collectionView(_ collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, minimumLineSpacingForSectionAt section: Int) -> CGFloat
      return 1


      // MARK: - UICollectionViewDataSource

      override func numberOfSections(in collectionView: UICollectionView) -> Int
      return 1


      override func collectionView(_ collectionView: UICollectionView, numberOfItemsInSection section: Int) -> Int
      return images.count


      override func collectionView(_ collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, at indexPath: IndexPath) -> UICollectionReusableView

      let header = collectionView.dequeueReusableSupplementaryView(ofKind: kind, withReuseIdentifier: headerIdentifier, for: indexPath) as! SelectVideoHeader

      self.header = header

      if let selectedImage = self.selectedImage

      // Index selected image
      if let index = self.images.index(of: selectedImage)

      // Asset associated with Selected Image
      let selectedAsset = self.assets[index]

      let videoManager = PHImageManager.default()
      let targetSize = CGSize(width: 600, height: 600)



      // Request Image
      videoManager.requestImage(for: selectedAsset, targetSize: targetSize, contentMode: .default, options: nil) (image, info) in

      header.videoSelectView.image = image





      return header


      override func collectionView(_ collectionView: UICollectionView, cellForItemAt indexPath: IndexPath) -> UICollectionViewCell

      let cell = collectionView.dequeueReusableCell(withReuseIdentifier: reuseIdentifier, for: indexPath) as! SelectVideoCell

      cell.videoSelectView.image = images[indexPath.row]

      return cell


      override func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath)
      self.selectedImage = images[indexPath.row]
      self.collectionView?.reloadData()

      let indexPath = IndexPath(item: 0, section: 0)
      collectionView.scrollToItem(at: indexPath, at: .bottom, animated: true)


      @objc func handleDismiss()
      dismiss(animated: true, completion: nil)


      @objc func handleNext()
      let uploadController = UploadVideoController()
      uploadController.selectedImage = header?.videoSelectView.image
      let navController = UINavigationController(rootViewController: uploadController)
      present(navController, animated: true, completion: nil)


      func configureUI()

      navigationController?.navigationBar.tintColor = .black
      navigationController?.navigationBar.setBackgroundImage(UIImage(), for: .default)
      navigationController?.navigationBar.shadowImage = (UIImage())
      //navigationItem.title = "Videos"

      navigationItem.leftBarButtonItem = UIBarButtonItem(title: "Cancel", style: .plain, target: self, action: #selector(handleDismiss))
      navigationItem.rightBarButtonItem = UIBarButtonItem(title: "Next", style: .plain, target: self, action: #selector(handleNext))


      func getAssetFetchOptions() -> PHFetchOptions

      let options = PHFetchOptions()

      // Fetch Limit
      options.fetchLimit = 30

      // Sort Videos by Date
      let sortDescriptor = NSSortDescriptor(key: "creationDate", ascending: false)

      // Set Sort Descriptor for Options
      options.sortDescriptors = [sortDescriptor]

      // Return Options
      return options



      func fetchVideos()

      let allVideos = PHAsset.fetchAssets(with: .video, options: getAssetFetchOptions())

      print("Function running")

      // Fetch Videos on Background Thread
      DispatchQueue.global(qos: .background).async

      // Enumerate Objects
      allVideos.enumerateObjects( (asset, count, stop) in

      print("Count is (count)")

      let videoManager = PHImageManager.default()
      let targetSize = CGSize(width: 600, height: 600)
      let options = PHImageRequestOptions()
      options.isSynchronous = true

      // Request Video representation for specific Asset
      videoManager.requestImage(for: asset, targetSize: targetSize, contentMode: .aspectFit, options: options, resultHandler: (image, info) in

      if let image = image

      // Append image to data source
      self.images.append(image)

      // Append asset to data source
      self.assets.append(asset)

      // Set selected Image
      if self.selectedImage == nil
      self.selectedImage = image


      // Reload collectionView with images once counr has completed
      if count == allVideos.count - 1

      // Reload collectionView on main thread
      DispatchQueue.main.async
      self.collectionView?.reloadData()



      )
      )



      override var prefersStatusBarHidden: Bool
      return true








      ios swift video avplayer






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Mar 8 at 22:15









      rmaddy

      246k27327390




      246k27327390










      asked Mar 8 at 22:14







      user9611921





























          1 Answer
          1






          active

          oldest

          votes


















          1














          You can play video by create instances of AVPlayer and AVPlayerLayer. Add following code in your selection view controller or create one new view controller and present by passing video url in that.



          Add following code to play video.



          import AVFoundation

          var avPlayerLayer : AVPlayerLayer?
          var avPlayer : AVPlayer?

          override func viewDidLoad()
          super.viewDidLoad()

          // You need to pass your url here.
          self.avPlayer = AVPlayer(url: url)

          self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer!)
          self.avPlayerLayer!.frame = self.view!.bounds

          self.view.layer.addSublayer(self.avPlayerLayer!)

          self.avPlayer!.play()



          This code will play your video immediately after your selection. You need required to pass url in avPlayer.



          I hope this will help you.






          share|improve this answer























            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',
            autoActivateHeartbeat: false,
            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%2f55071732%2fhow-do-i-get-the-video-to-play-in-my-video-selection-controller%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown
























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            You can play video by create instances of AVPlayer and AVPlayerLayer. Add following code in your selection view controller or create one new view controller and present by passing video url in that.



            Add following code to play video.



            import AVFoundation

            var avPlayerLayer : AVPlayerLayer?
            var avPlayer : AVPlayer?

            override func viewDidLoad()
            super.viewDidLoad()

            // You need to pass your url here.
            self.avPlayer = AVPlayer(url: url)

            self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer!)
            self.avPlayerLayer!.frame = self.view!.bounds

            self.view.layer.addSublayer(self.avPlayerLayer!)

            self.avPlayer!.play()



            This code will play your video immediately after your selection. You need required to pass url in avPlayer.



            I hope this will help you.






            share|improve this answer



























              1














              You can play video by create instances of AVPlayer and AVPlayerLayer. Add following code in your selection view controller or create one new view controller and present by passing video url in that.



              Add following code to play video.



              import AVFoundation

              var avPlayerLayer : AVPlayerLayer?
              var avPlayer : AVPlayer?

              override func viewDidLoad()
              super.viewDidLoad()

              // You need to pass your url here.
              self.avPlayer = AVPlayer(url: url)

              self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer!)
              self.avPlayerLayer!.frame = self.view!.bounds

              self.view.layer.addSublayer(self.avPlayerLayer!)

              self.avPlayer!.play()



              This code will play your video immediately after your selection. You need required to pass url in avPlayer.



              I hope this will help you.






              share|improve this answer

























                1












                1








                1







                You can play video by create instances of AVPlayer and AVPlayerLayer. Add following code in your selection view controller or create one new view controller and present by passing video url in that.



                Add following code to play video.



                import AVFoundation

                var avPlayerLayer : AVPlayerLayer?
                var avPlayer : AVPlayer?

                override func viewDidLoad()
                super.viewDidLoad()

                // You need to pass your url here.
                self.avPlayer = AVPlayer(url: url)

                self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer!)
                self.avPlayerLayer!.frame = self.view!.bounds

                self.view.layer.addSublayer(self.avPlayerLayer!)

                self.avPlayer!.play()



                This code will play your video immediately after your selection. You need required to pass url in avPlayer.



                I hope this will help you.






                share|improve this answer













                You can play video by create instances of AVPlayer and AVPlayerLayer. Add following code in your selection view controller or create one new view controller and present by passing video url in that.



                Add following code to play video.



                import AVFoundation

                var avPlayerLayer : AVPlayerLayer?
                var avPlayer : AVPlayer?

                override func viewDidLoad()
                super.viewDidLoad()

                // You need to pass your url here.
                self.avPlayer = AVPlayer(url: url)

                self.avPlayerLayer = AVPlayerLayer(player: self.avPlayer!)
                self.avPlayerLayer!.frame = self.view!.bounds

                self.view.layer.addSublayer(self.avPlayerLayer!)

                self.avPlayer!.play()



                This code will play your video immediately after your selection. You need required to pass url in avPlayer.



                I hope this will help you.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Mar 9 at 11:02









                Sagar ChauhanSagar Chauhan

                2,5501727




                2,5501727





























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Stack Overflow!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55071732%2fhow-do-i-get-the-video-to-play-in-my-video-selection-controller%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

                    Identity Server 4 is not redirecting to Angular app after login2019 Community Moderator ElectionIdentity Server 4 and dockerIdentityserver implicit flow unauthorized_clientIdentityServer Hybrid Flow - Access Token is null after user successful loginIdentity Server to MVC client : Page Redirect After loginLogin with Steam OpenId(oidc-client-js)Identity Server 4+.NET Core 2.0 + IdentityIdentityServer4 post-login redirect not working in Edge browserCall to IdentityServer4 generates System.NullReferenceException: Object reference not set to an instance of an objectIdentityServer4 without HTTPS not workingHow to get Authorization code from identity server without login form

                    2005 Ahvaz unrest Contents Background Causes Casualties Aftermath See also References Navigation menue"At Least 10 Are Killed by Bombs in Iran""Iran"Archived"Arab-Iranians in Iran to make April 15 'Day of Fury'"State of Mind, State of Order: Reactions to Ethnic Unrest in the Islamic Republic of Iran.10.1111/j.1754-9469.2008.00028.x"Iran hangs Arab separatists"Iran Overview from ArchivedConstitution of the Islamic Republic of Iran"Tehran puzzled by forged 'riots' letter""Iran and its minorities: Down in the second class""Iran: Handling Of Ahvaz Unrest Could End With Televised Confessions""Bombings Rock Iran Ahead of Election""Five die in Iran ethnic clashes""Iran: Need for restraint as anniversary of unrest in Khuzestan approaches"Archived"Iranian Sunni protesters killed in clashes with security forces"Archived

                    Can't initialize raids on a new ASUS Prime B360M-A motherboard2019 Community Moderator ElectionSimilar to RAID config yet more like mirroring solution?Can't get motherboard serial numberWhy does the BIOS entry point start with a WBINVD instruction?UEFI performance Asus Maximus V Extreme