gpt4 book ai didi

ios - 视频作为背景

转载 作者:可可西里 更新时间:2023-11-01 01:00:41 25 4
gpt4 key购买 nike

我正在尝试添加视频作为背景,但它不起作用。

这是我使用的代码:

import UIKit
import MediaPlayer
import AVFoundation
import AVKit
import MediaPlayer

class WelcomeViewController: UIViewController {

let moviePlayerController = AVPlayerViewController()
var aPlayer = AVPlayer()
func playBackgroundMovie(){
if let url = NSBundle.mainBundle().URLForResource("WelcomeVideo", withExtension: "mp4") {
aPlayer = AVPlayer(URL: url)
}
moviePlayerController.player = aPlayer
moviePlayerController.view.frame = view.frame
moviePlayerController.videoGravity = AVLayerVideoGravityResizeAspectFill
moviePlayerController.view.sizeToFit()
moviePlayerController.videoGravity = AVLayerVideoGravityResizeAspect
moviePlayerController.showsPlaybackControls = false
moviePlayerController.view.userInteractionEnabled = false
aPlayer.play()
view.insertSubview(moviePlayerController.view, atIndex: 0)
}

override func viewDidLoad() {
super.viewDidLoad()
// Do any additional setup after loading the view, typically from a nib.

self.moviePlayerController.view.backgroundColor = UIColor.grayColor()

playBackgroundMovie()
NSNotificationCenter.defaultCenter().addObserver(self, selector: "didPlayToEndTime", name: AVPlayerItemDidPlayToEndTimeNotification, object: nil)
}

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

func didPlayToEndTime(){
aPlayer.seekToTime(CMTimeMakeWithSeconds(0, 1))
aPlayer.play()
}
}

当我运行我的应用程序时,它崩溃了:

aPlayer = AVPlayer(URL: url!)

我还在我的项目中添加了“WelcomeVideo.mp4”:

enter image description here

正如您在图像上看到的,“WelcomeVideo.mp4”就在当前 View Controller 类的旁边...我在这里做错了什么?

最佳答案

修复了我自己!忘了我必须将它添加到 Build Phases 中的Copy Bundle Resources

关于ios - 视频作为背景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34779905/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com