Swift access to a file that is stored in another folder - ios

I am creating a app, where you can record videos or images. You can record videos or images on your own or you can pick it from the UIImagePicker. The videos/images are listed in a collection view.
When you tab on a row in the collection view it shows the image or the video.
One thing I don't understand is, if I record a video to safe it, it shows up in the collection view, but when I choose the video that I recorded before, I only see a grey background and not the actually video.
If I choose a video from the gallery it shows up and play.
This is how I display the video
player = AVPlayer(url: arrayOfVideoUrls[i]!)
print(arrayOfVideoUrls[i]!)
playerLayer = AVPlayerLayer(player: player)
playerLayer?.frame = view.frame
view.layer.addSublayer(playerLayer!)
player?.play()
My guess is, that I can't open the video, because it is saved in another folder.
This is the folder of my self recorded Video:
file:///private/var/mobile/Containers/Data/Application/E0EBF7F9-713C-451B-B764-D2056ECC6E48/tmp/7834C1AF-1417-4389-B455-92DA52DFF93F.mov
This is the folder of the video from the gallery:
file:///private/var/mobile/Containers/Data/PluginKitPlugin/1A977F99-6C5C-40F7-933D-E325D8E967E4/tmp/trim.31B4A909-E8FA-4CBE-B64F-30646A6366B3.MOV

You need to give the path whenever you save your recorded video and after saving you need to check that path whether its containing file or not.
And Please make sure, you give different name to your recording whenever you record a new video.And to play that video append the name of video with the path.

Related

AVAssetWriter: preview recorded .mp4 before calling `finishWriting`?

I am using AVAssetWriter to record a video (with audio) form iOS camera. Everything works great.
I now want to allow the user to preview the video before saving, meaning, before calling finishWriting on the AVAssetWriter instance.
My original thought was to copy the current file the writer is writing to during recoding to a preview url, and then use another AVAssetWriter to finalize that file and then play it.
However, I am not sure how to properly initialize a second AVAssetWriter for preview purposes, so I can call finishWriting on it at the preview url...
Anyone knows how I could implement preview functionality to allow a user to preview the currently recorded mp4 before calling finishWriting?
Anyone knows how I could implement preview functionality to allow a user to preview the currently recorded mp4 before calling finishWriting?
You must call finishWriting in order to have a viewable mp4 file.
So call finishWriting, let the user preview the resulting file and then decide whether to delete it or keep it.

ios - Is it possible to record an App screen and view or delete the recorded file?

The function you want to implement now is to record everything you see in your app when you run a screen recording I would like to add the ability to view or delete recorded files at any time.
I have found a way to record the screen using the Replay kit, AV kit, When the recording is finished, it is saved as a movie in the photo album.
Instead of doing this, I want to add viedo file to the document path folder in the App after the screen recording, to show the file list recorded by date in the table view, and to view or delete the recorded video when clicking the file.
Is this possible?

AVPlayer sometimes doesn't load a video

I have a one button and AVPlayer. After button click I record a video using DBAttachmentPickerController and I want to load it to the AVPlayer.
In function below I try to load it:
func refresh(attachmentInfo: AttachmentInfo) {
self.videoLayer.player = nil
if let url = attachmentInfo.url {
self.player = AVPlayer(url: url) // line A
self.videoLayer.player = self.player // line B
}
}
In 6/10 cases it works fine, but sometimes the video doesn't load to AVPlayer.
When I set breakpoints in line A and B it works always.
Any ideas?
I also hit this exact issue as yours. In my case the AVPlayer and AVPlayerLayer were inside tableview cells which made the problem worse. However, I was using an API which returned the actual video URL, and an Image URL which consisted of the video's first frame's image. In the tableview cell logic, I first attempt to load the video into AVPlayer and then check if the AVPlayer has any .video assets, if it didn't then I simply load the Image from the other URL into the UIView (using a UIImageView of course) with a "Play" button image in the center of the Image. When the user taps the play button the selector function should try to load the AVPlayer again with the video URL. If the video loads and AVPlayer has assets then play() else simply return (and possibly alert the user that the video can't be loaded).
If you do not have the image of the first frame of the video, you can simply use a placeholder image and a button.
The way to check if the player has a video or not-
if player.currentItem?.asset.tracks(withMediaType: .video).count == 0{
print("Oops! no video here")
//load an image, and add a button here
}else{
//do whatever needs to be done if video is available
}
Unfortunately, there isn't much else that can be done here unless you have some solid networking code where in you can download the video in a utility thread and store it in cache, but then again you have to be cognizant about the user's data usage, spawning too many download threads etc.
For image caching in the UITableView cell, I used SDWebImage library from Github so that I can be (somewhat) assured that my image (for the video) atleast would be cached in case of bad/slow network, or network interruptions.

Displaying image from video file on UITableview

I have a video file from local server like this.
http://127.0.0.1:8000/media/through_your_eyes/file0.mov
Before I play that video, I need to show image from video inside tableview. Is there an api to show image from video and when I click, it will play automatically?
My current method is I download video file and I extract image from video file. After that, I show inside my tableview. But I guess it is not quite good.

Creating video from scratch in iOS

I've got an app where the user shoots some video, enters a title for it, and picks a music track. I've got the music dubbing working with AVMutableComposition, but the titling is a bad hack -- just a view overlaid on the MPMoviePlayerViewController. And while the user can upload the dubbed video to YouTube, the title of course isn't included.
Are there iOS APIs that will let me access or create raw video frames, so I can either overlay the title on the video, or splice in new frames with the title before the start of the video proper?
For anyone coming along later: see, e.g., How do I export UIImage array as a movie?

Resources