我在项目中添加了DemoVideo.mp4并将其添加到复制资源文件中。但是,当我运行应用程序时,它不播放我的视频。 这是我的方法。
SELECT TABLE_NAME, COLUMN_NAME
FROM information_schema.COLUMNS
WHERE TABLE_SCHEMA=DATABASE()
AND DATA_TYPE IN ('char', 'varchar', 'text')
我在private func setUpAndPlayVideo() {
guard let videoPath = Bundle.main.path(forResource: "DemoVideo.mp4", ofType: nil) else {
return
}
let videoURL = NSURL(string: videoPath)
let player = AVPlayer(url: videoURL! as URL)
playerViewController = AVPlayerViewController()
playerViewController.player = player
playerViewController.view.frame = self.videoPlayerView.bounds
self.videoPlayerView.addSubview(playerViewController.view)
playerViewController.showsPlaybackControls = false
playerViewController.player?.play()
}
方法中调用此方法,但它显示了这个。
答案 0 :(得分:2)
let path : String = Bundle.main.path(forResource: "charlie", ofType: "mp4")!
let movieurl : URL = URL(fileURLWithPath: path)
let movie : AVPlayerViewController = AVPlayerViewController()
movie.view.frame = self.view.bounds
let player : AVPlayer = AVPlayer(url: movieurl)
movie.player = player
self.view.addSubview(movie.view)
player.play()