andreipitis / ASPVideoPlayer

A simple video player that allow animations to be performed on the view during playback.
MIT License
89 stars 43 forks source link

HELP WANTED - Use ASPVideoPlayer with video .mov saved in documents directory #28

Closed CPiersigilli closed 6 years ago

CPiersigilli commented 6 years ago

After several attempts, I think I understand that your ASPVideoPlayer does not work with .movvideo files, for example with this path:/var/mobile/Containers/Data/Application/DD33257B-561C-4E8A-AC16-1794AB2846A6/Documents/myVideo.mov. How can I use it? Thank you

andreipitis commented 6 years ago

Hi @CPiersigilli ,

ASPVideoPlayer uses an AVPlayer in its implementation, so any format that an AVPlayer can play is supported, including .mov. I have used the .mov file from this link to test that it works. If the .mov file at that link works for you, then your issue might be with the encoding of your video file.

CPiersigilli commented 6 years ago

I created the file with the iphone video camera: "file: ///private/var/mobile/Containers/Data/Application/204BA506-5798-444A-B578-513536933E35/Documents/myVideo.mov" assigned to the variable firstVideoURL and then videoPlayer.videoURLs = [firstVideoURL]

Unfortunately I get the error: "Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value"

Instead using the following code I can see the saved video.

// Create an AVPlayer from the video saved in the filemanager
 let player = AVPlayer (url: firstVideoURL)
// Create a new AVPlayerViewController and pass it to reference to the player.
let controller = AVPlayerViewController ()
controller.player = player
// Modally present the player and call the player's play () method when complete.
present (controller, animated: true) {
     player.play ()}

Do you have any idea why it does not work? Thank you

CPiersigilli commented 6 years ago

For your information, I added ASPVideoPlayer by copying the ASPVideoPlayer folder to my project, because I do not like using CocoaPods. Can this be the problem?

andreipitis commented 6 years ago

Not using CocoaPods shouldn't be a problem.

I tried to reproduce your issue by loading a video from the media library (taken by the camera) but I wasn't able to get the same behaviour.

Is the Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value happening within the code of the framework? If so could you tell me the file and the line?

Does this also fail if you try to set the AVAsset directly using the videoAssets property of the ASPVideoPlayer, instead of using the URL?

It's pretty hard to debug this without actually seeing the code. It would be great if you could make a sample project with code to reproduce the issue and provide me with a link/zip file.

CPiersigilli commented 6 years ago

I have modified AVCam of Apple.

See: // MARK: Save Movies nella directory permanente from CameraViewController.swift, where capture and saved video from iPhone camera.

See Thread 1: Fatal error: Unexpectedly found nil while unwrapping an Optional value in VideoPlayVC.

I'm using an iPhone 6.

Zip Code from: click here

andreipitis commented 6 years ago

@CPiersigilli thanks for sharing the code. The issue you are having is not caused by ASPVideoPlayer but by the fact that your videoPlayer outlet (PlayVideoVC - line 14) is not connected with the view in the storyboard.

Once you properly connect the outlet, everything works fine.

CPiersigilli commented 6 years ago

Great, thanks! ASPVideoPlayer works fine now.

One more thing... I'd like the toolbar and navigation bar to be shown when the video isn't playing or if it was stopped and hidden when it's playing. How can I make it work that way?

You can download, by clicking the link below, the VideoPlayVC code where I tried to add this feature but it doesn't work as expected

Zipped file: click here

Thanks in advance for your help.

andreipitis commented 6 years ago

Unfortunately ASPVideoPlayer does not have any callback methods for different events yet, so it's probably going to be very tricky to do what you want. I will try to add this new functionality soon.

In the meantime you can use ASPVideoPlayerView. It work similar to ASPVideoPlayer and it provides a number of callback methods for events like when a video stopped, when it resumed, etc. The drawback is that it has no UI Controls.

CPiersigilli commented 6 years ago

Thank you for your support. I will wait for the change to your ASPVideoPlayer to implement what I would like to do. Please enter the ability to move your ASPVideoPlayerControls vertically so as not to hide it when it is shown, for example the toolbar.