视频播放 (AVPlayer ViewController, AVkit) 不工作(不出现)
video playing (AVPlayer ViewController, AVkit) is not working (Does not appear)
我搜索了几个小时,没有找到解决方案...
视频播放代码无效(local 视频没有出现...)
我还尝试使用 URL 代码打开视频,但它们都不起作用。
希望你能找到解决办法,谢谢!
代码如下:
import UIKit
import AVKit
import AVFoundation
class ViewController2: UIViewController {
func forbutton(name : String, type : String) {
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
playVideo(name: name, type: type)
}
}
private func playVideo(name : String, type : String) {
guard let path = Bundle.main.path(forResource: "\(name)", ofType:"\(type)") else {
debugPrint("video not found")
return
}
let player = AVPlayer(url: URL(fileURLWithPath: path))
let playerController = AVPlayerViewController()
playerController.player = player
present(playerController, animated: true) {
player.play()
}
}
@IBAction func fatB(_ sender: Any) {
forbutton(name: "fatB", type: "mp4")
}
@IBAction func coderB(_ sender: Any) {
forbutton(name: "birdC", type: "mp4")
}
@IBAction func clashB(_ sender: Any) {
forbutton(name: "clash", type: "mp4")
}
目前您正在另一个中插入一个函数,它应该是
func forbutton(name : String, type : String) {
playVideo(name: name, type: type)
}
如果您想在出现视图时播放它
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
forbutton(name: "fatB", type: "mp4")
}
我搜索了几个小时,没有找到解决方案... 视频播放代码无效(local 视频没有出现...) 我还尝试使用 URL 代码打开视频,但它们都不起作用。 希望你能找到解决办法,谢谢!
代码如下:
import UIKit
import AVKit
import AVFoundation
class ViewController2: UIViewController {
func forbutton(name : String, type : String) {
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
playVideo(name: name, type: type)
}
}
private func playVideo(name : String, type : String) {
guard let path = Bundle.main.path(forResource: "\(name)", ofType:"\(type)") else {
debugPrint("video not found")
return
}
let player = AVPlayer(url: URL(fileURLWithPath: path))
let playerController = AVPlayerViewController()
playerController.player = player
present(playerController, animated: true) {
player.play()
}
}
@IBAction func fatB(_ sender: Any) {
forbutton(name: "fatB", type: "mp4")
}
@IBAction func coderB(_ sender: Any) {
forbutton(name: "birdC", type: "mp4")
}
@IBAction func clashB(_ sender: Any) {
forbutton(name: "clash", type: "mp4")
}
目前您正在另一个中插入一个函数,它应该是
func forbutton(name : String, type : String) {
playVideo(name: name, type: type)
}
如果您想在出现视图时播放它
func viewDidAppear(_ animated: Bool) {
super.viewDidAppear(animated)
forbutton(name: "fatB", type: "mp4")
}