gpt4 book ai didi

ios - 使用 Avplayer/kit 问题播放本地视频

转载 作者:行者123 更新时间:2023-11-28 06:24:32 25 4
gpt4 key购买 nike

每当我运行该项目时,它都会调出视频播放器,但视频不播放  (the code and error) .我该如何解决?如果图片中的代码不够清楚,这里是代码:

import UIKit
import AVKit
import AVFoundation


class ViewController: UIViewController {

let avPlayerViewController = AVPlayerViewController()
var avPlayer:AVPlayer?

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

let urlPathString = Bundle.main.path(forResource: "small", ofType: "mp4")

if urlPathString != nil {

let movieUrl = NSURL(fileURLWithPath: "/Users/kevingerman/Desktop/Pioneer News Season 2 Episode 1.mp4")

self.avPlayer = AVPlayer(url: movieUrl as URL)
self.avPlayerViewController.player = self.avPlayer

}
}



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


@IBAction func playButtonTapped(_ sender: AnyObject) {
//Trigger the video to play
self.present(self.avPlayerViewController, animated: true) { () -> Void in self.avPlayerViewController.player?.play() }


}

最佳答案

评论中提出的解决方案和@Guan 回答的都是正确的。

你的urlPathString在这里实际上是nil,

让它工作——

1- Either add the Target Membership, as suggested in the comment and the answer above or

执行以下操作

1.1- Delete the small.mp4 from bundle, make sure you move it to trash

2.1 - Go to trash and drag and drop your mp4 file into the project again, you will get a window like this -Window on drag and drop

在将其添加回来时确保您 -

Check the projectTarget checkbox like the screenshot below -

Checked box for app target

确保文件名为small.mp4

关于ios - 使用 Avplayer/kit 问题播放本地视频,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42377834/

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