尝试使用本机反应原创视频。方法是这样的:
AppDelegate.m中的:
UIView* launchScreenView = [[[NSBundle mainBundle] loadNibNamed:@"LoadVideoView" owner:self options:nil] objectAtIndex:0];
launchScreenView.frame = self.window.bounds;
rootView.loadingView = launchScreenView;
rootView.loadingViewFadeDelay = 5;
LoadVideoView从“文件所有者”标签链接到控制器:
LoadVideo.swift中的代码:
import UIKit
import AVKit
import AVFoundation
class LoadVideo: AVPlayerViewController {
override func viewDidLoad() {
super.viewDidLoad()
print("view did load!!!!!")
playLocalVideo()
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
func playLocalVideo() {
let filePath = Bundle.main.path(forResource: "loading 2048", ofType: "mp4")
let videoURL = NSURL(fileURLWithPath: filePath!)
let player = AVPlayer(url: videoURL as URL)
// let playerViewController = AVPlayerViewController()
self.showsPlaybackControls = false
self.player = player
self.player!.play()
}
}
问题是控制器中没有代码执行。如果我尝试添加IBOutlet,它会崩溃。 XIB / NIB显示,但是如果我从控制器登录则没有任何反应。如何显示视频? (如果我设置一个测试项目并使用storyboard的viewcontroller,它可以正常工作)
我在写这个问题时注意到,所有者在appdelegate中是自我。这似乎应该是控制器的一个实例,但我不确定该放在那里。