Xcode:通过按钮连接的Swift多个视频

时间:2018-03-22 04:04:40

标签: swift xcode

我在为不同的按钮使用不同的视频时遇到困难。然而,我的第一个按钮有效,但是当我点击第二个按钮时,它会将我带到AppDelegate.swift页面。我附上了我的代码。有什么建议吗?

import UIKit
import AVFoundation
import AVKit

class Chicken_visual_ViewController: UIViewController {

var playerController = AVPlayerViewController()
var playerView = AVPlayer()

override func viewDidLoad() {
    super.viewDidLoad()


}




override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}




@IBAction func button1(_ sender: AnyObject) {
    var fileURL = NSURL(fileURLWithPath:"/Users/owner/Desktop/video.mp4")
    playerView = AVPlayer(url: fileURL as URL)
    playerController.player = playerView


    self.present(self.playerController, animated: true, completion: {
        self.playerController.player?.play()
    })
}

@IBAction func button2(_ sender: AnyObject) {
    var fileURL2 = NSURL(fileURLWithPath:"/Users/owner/Desktop//video_3. 
 mp4")
    playerView = AVPlayer(url: fileURL2 as URL)
    playerController.player = playerView


    self.present(self.playerController, animated: true, completion: {
        self.playerController.player?.play()
    })

}

}

0 个答案:

没有答案