Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playing Local Videos #158

Closed
fnrbh opened this issue Nov 21, 2017 · 2 comments
Closed

Playing Local Videos #158

fnrbh opened this issue Nov 21, 2017 · 2 comments

Comments

@fnrbh
Copy link

fnrbh commented Nov 21, 2017

Hello,
Thanks for such a library, i am using it in my apps.
In one of my apps i encountered a problem. I am getting a video from the phone's gallery, appending it on my lightbox array and trying to play it, but i am unsuccessful. If i add a remote video, it is playing the video. My own video url is something like this "assets-library://asset/asset.mov?id=C006BE3C-2327-4A91-A139-7B594A99458D&ext=mov".

thanks in advance.

Here is my code:

var controller:LightboxController! = nil
var lbImages = [LightboxImage]()

override func viewDidLoad() {
        super.viewDidLoad()
        LightboxConfig.handleVideo = { from, videoURL in
            
            // Custom video handling
            
            print("playing local :")
            print(videoURL)
            let videoController = AVPlayerViewController()
            videoController.player = AVPlayer(url: videoURL)
            
            from.present(videoController, animated: true) {
                videoController.player?.play()
            }
}

func imagePickerController(_ picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : Any]) {
        if let chosenImage = info[UIImagePickerControllerOriginalImage] as? UIImage {
            picker.dismiss(animated: false, completion: { () -> Void in
                
                print("width is " + String(describing: chosenImage.size.width) + " height " +  String(describing: chosenImage.size.height))
                self.lbImages.append(LightboxImage(image: chosenImage))
                self.mediaCollectionView.reloadData()
                
            })
            
        } else if let videoURL = info["UIImagePickerControllerReferenceURL"] as? NSURL {
            picker.dismiss(animated: false, completion: { () -> Void in
                
                print(videoURL)
                self.lbImages.append(LightboxImage(
                    image: UIImage(named:"news")!,
                    text: "",
                    videoURL: videoURL as URL
                    //videoURL: NSURL(string: "https://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4") as URL?
                ))
                self.mediaCollectionView.reloadData()
                
            })
        
        
        } else{
            print("Something went wrong")
            self.dismiss(animated: true, completion: nil)
        }
        
        
    }

func collectionView(_ collectionView: UICollectionView, didSelectItemAt indexPath: IndexPath) {
        controller = LightboxController(images: lbImages)
        // Set delegates.
        //controller.pageDelegate = self
        //controller.dismissalDelegate = self
        
        // Use dynamic background.
        controller.dynamicBackground = true
        // Present your controller.
        
        controller.headerView.deleteButton.addTarget(self, action: #selector(self.deleteImage), for: .touchUpInside)
        
        present(controller, animated: true, completion: nil)
    }

@onmyway133
Copy link
Contributor

@fnrbh Hi, we just use simple AVPlayerViewController as default https://github.com/hyperoslo/Lightbox/blob/master/Source/LightboxConfig.swift#L12 Can you create a simple project and try to play that video with AVFoundation?

@fnrbh
Copy link
Author

fnrbh commented Dec 13, 2017

Hi, the way i was getting the video url from imagepicker was wrong. When i corrected it, Ligthbox worked as expected...Thanks...

@fnrbh fnrbh closed this as completed Dec 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants