From 45bbbf894554c6457dd1d322d73828f1ec50fd2c Mon Sep 17 00:00:00 2001 From: redstrate <54911369+redstrate@users.noreply.github.com> Date: Mon, 16 Mar 2020 12:19:36 -0400 Subject: [PATCH] Only open the video player if the file is a video --- Gallery/PostViewController.swift | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/Gallery/PostViewController.swift b/Gallery/PostViewController.swift index 5106532..4e18426 100644 --- a/Gallery/PostViewController.swift +++ b/Gallery/PostViewController.swift @@ -68,18 +68,17 @@ class PostViewController: UIViewController { } @IBAction func playAction(_ sender: Any) { - 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)) - - // Create a new AVPlayerViewController and pass it a reference to the player. - let controller = AVPlayerViewController() - controller.player = player - - // Modally present the player and call the player's play() method when complete. - present(controller, animated: true) { - player.play() + if((post?.value(forKey: "type") as? String) == "public.mpeg-4") { + let imagePath = documentsPath.appendingPathComponent(post!.value(forKey: "name") as! String).path + + let player = AVPlayer(url: URL(fileURLWithPath: imagePath)) + + let controller = AVPlayerViewController() + controller.player = player + + present(controller, animated: true) { + player.play() + } } } }