Archived
1
Fork 0

Only open the video player if the file is a video

This commit is contained in:
redstrate 2020-03-16 12:19:36 -04:00
parent 9862d3816b
commit 45bbbf8945

View file

@ -68,18 +68,17 @@ class PostViewController: UIViewController {
} }
@IBAction func playAction(_ sender: Any) { @IBAction func playAction(_ sender: Any) {
let imagePath = documentsPath.appendingPathComponent(post!.value(forKey: "name") as! String).path if((post?.value(forKey: "type") as? String) == "public.mpeg-4") {
let imagePath = documentsPath.appendingPathComponent(post!.value(forKey: "name") as! String).path
// Create an AVPlayer, passing it the HTTP Live Streaming URL.
let player = AVPlayer(url: URL(fileURLWithPath: imagePath)) let player = AVPlayer(url: URL(fileURLWithPath: imagePath))
// Create a new AVPlayerViewController and pass it a reference to the player. let controller = AVPlayerViewController()
let controller = AVPlayerViewController() controller.player = player
controller.player = player
present(controller, animated: true) {
// Modally present the player and call the player's play() method when complete. player.play()
present(controller, animated: true) { }
player.play()
} }
} }
} }