Posted at

Swift: 動画再生

More than 1 year has passed since last update.


Frameworks追加


ソース追加


qiita.rb

import UIKit

import AVFoundation
import AVKit

class ViewController: UIViewController {

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.
let path = Bundle.main.path(forResource: "movie.mp4", ofType: nil)

let player = AVPlayer(url: URL(fileURLWithPath:path!))
let playerController = AVPlayerViewController()

playerController.player = player
self.addChildViewController(playerController)
self.view.addSubview(playerController.view)
playerController.view.frame = self.view.frame
player.play()
}

}