'How to play video using the fileURL
I am able to fetch the output file URL like below using custom video recorder.
file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov
I need to play that video using AVPlayerViewController. I am using the below code for playing video in my viewcontroller. But it is not working. Could anyone guide me to do this task?
func pathVideo()
{
if let path = Bundle.main.path(forResource: "file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov", ofType: "mov", inDirectory: "file:///var/mobile/Containers/Data/Application/5EB769B8-193F-4C9F-982A-48892333A8F0/Documents/2018-Oct-31%2012:16:54output.mov")
{
let video = AVPlayer(url: URL(fileURLWithPath: path))
let playerViewController = AVPlayerViewController()
playerViewController.player = video
present(playerViewController, animated: true, completion:
{
video.play()
})
}
}
Solution 1:[1]
Try declaring let playerViewController = AVPlayerViewController() at class scope not in method's scope. My guess is, it gets deallocated.
And again Kamarshad's point is right. You should retrieve the URL from fileManager not from application Bundle
Solution 2:[2]
I’m not all that tech smart and I’m not even sure why I received this, sorry I’m on my cell phone n I know I’ve been hacked by a Mac OS device that somehow keeps signing in every single time I sign in on a gmail acct. I get the message stating that a Mac device has signed in at the precise moment I’m signing in on my phone into a specific gmail acct. When I signed out of a bunch of accounts I received a message saying “let this Mac device sign into your Google accounts” idk what’s going on or what this is
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Roohul |
| Solution 2 | Brina |
