How To Play A Video In Swift

[Solved] How To Play A Video In Swift | Swift - Code Explorer | yomemimo.com
Question : how to play a video in swift

Answered by : successful-sandpiper-de476cjazsqs

import UIKit
import AVKit
class ViewController: UIViewController { override func viewDidLoad() { super.viewDidLoad() //TODO : Make Sure Add and copy "SampleVideo.mp4" file in project before play } @IBAction func playLocalVideo(_ sender: Any) { guard let path = Bundle.main.path(forResource: "SampleVideo", ofType: "mp4") else { return } let videoURL = NSURL(fileURLWithPath: path) // Create an AVPlayer, passing it the local video url path let player = AVPlayer(url: videoURL as URL) let controller = AVPlayerViewController() controller.player = player present(controller, animated: true) { player.play() } }
}

Source : https://stackoverflow.com/questions/25348877/how-to-play-a-local-video-with-swift | Last Update : Sun, 21 Nov 21

Answers related to how to play a video in swift

Code Explorer Popular Question For Swift