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,20 +68,19 @@ class PostViewController: UIViewController {
} }
@IBAction func playAction(_ sender: Any) { @IBAction func playAction(_ sender: Any) {
if((post?.value(forKey: "type") as? String) == "public.mpeg-4") {
let imagePath = documentsPath.appendingPathComponent(post!.value(forKey: "name") as! String).path 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
// Modally present the player and call the player's play() method when complete.
present(controller, animated: true) { present(controller, animated: true) {
player.play() player.play()
} }
} }
}
} }
extension PostViewController { extension PostViewController {