All diese Code-Funktionen ist eine einzige Schaltfläche auf einem View-Controller. Die Schaltfläche sollte das Video abspielen. Im Moment gibt es keine Fehlermeldung im Code. Alles was passiert, ist, dass die Taste gedrückt wird und nichts passiert. Es gibt keine Fehlermeldung. Alles, was ich habe, ist eine View-Controller-Seite. Der Code ist unten aufgeführt.Video funktioniert nicht mit Swift-Code
import UIKit
import AVKit
import AVFoundation
class ViewController: UIViewController {
var moviePlayer: AVPlayerViewController?
override func viewDidLoad() {
super.viewDidLoad()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
}
@IBAction func playVideo(_ sender: UIButton) {
playLocalVideo()
}
func playLocalVideo(){
if moviePlayer != nil {
do {
let filePath = Bundle.main.path(forResource: "t", ofType: "mp4")
let videoURL = NSURL(fileURLWithPath: filePath!)
let player = AVPlayer(url: videoURL as URL)
let playViewController = AVPlayerViewController()
playViewController.player = player
self.present(playViewController, animated: true) {() -> Void in playViewController.player!.play()
}
} catch {
print(error)
}}}}
Haben Sie das Video überprüft, das zum Ziel hinzugefügt wurde? – Vinodh
Dein 'moviePlayer' ist null und geht niemals nach' if moviePlayer! = Nil'.So instantiiere ihn zuerst –