Wednesday, March 22, 2017

Play A Movie That Is In Your Project

On your Storyboard, add a "AVKit Player View Controller". Connect it with a Segue from a UIButton you put on the View Controller.

Like this:
 
import UIKit
import AVKit
import AVFoundation

class ViewController: UIViewController {
    
    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
        
        let destination = segue.destination as! AVPlayerViewController
        let url = Bundle.main.url(forResource: "myMovieName", withExtension: "m4v")
        
        if let movieURL = url {
            destination.player = AVPlayer(url: movieURL)
        }
    }
}
 

(Xcode 8.2, Swift 3)

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.

SwiftUI Search & Filter with Combine - Part 3 (iOS, Xcode 13, SwiftUI, 2...

In part 3 of the Searchable video series, I show you how to use Combine in #SwiftUI for the search and filter logic connected to the searcha...