I am trying to player an mp4 video from the local file system on an ios app. The video is about an hour long and can be played on quicktime. I am able to play an mp4 if it is from the web (NSURL(string: "http:domain.com/vid.mp4")). I am playing the video like below:
let steamingURL:NSURL = NSURL(string: video.filePath)! //valid path
let player = AVPlayer(URL: steamingURL)
player.allowsExternalPlayback = false
PlayWorkoutViewController.playerController = AVPlayerViewController()
PlayWorkoutViewController.playerController.player = player
self.addChildViewController(PlayWorkoutViewController.playerController)
self.view.addSubview(PlayWorkoutViewController.playerController.view)
PlayWorkoutViewController.playerController.view.frame = videoContainerView.frame
PlayWorkoutViewController.playerController.showsPlaybackControls = false
player.play()
Do I need to change some of the settings to play the longer video? Thanks.
An object that provides the interface to control the player's transport behavior.
New in iOS 14SwiftUI's VideoPlayer view lets us playback movies from any URL, local or remote. It comes from the AVKit framework, so you should make sure and add import AVKit before trying it out. Reminder: You need to add import AVKit to your Swift file to use this.
Check the steamingURL is nil or not first
If you want to use NSURL(string: "xxx") initialiser please check the string starts with file://, otherwise use NSURL(fileURLWithPath: "xxxx") instead.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With