gpt4 book ai didi

swift - AVPlayerViewController 问题

转载 作者:行者123 更新时间:2023-11-30 14:12:54 26 4
gpt4 key购买 nike

所以我试图从这个项目源编辑一些源代码... https://github.com/ariiyu/VideoPlayerSample

所以,当我只是尝试替换视频路径并文件时,它崩溃了,我不知道为什么?

这是 ViewController 源代码之一...

import UIKit
import AVFoundation
import AVKit

class SecondViewController: AVPlayerViewController {

override func viewDidLoad() {
super.viewDidLoad()

// I try to replace the string with my movie file here and crashes
let moviePath = NSBundle.mainBundle().pathForResource("hogevideo", ofType: "mp4")!
let url = NSURL(fileURLWithPath: moviePath)


let playerItem = AVPlayerItem(URL: url)


player = AVPlayer(playerItem: playerItem)


player.play()
}

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

}

最佳答案

在 iOS 8 中文件系统结构发生了变化,这就是为什么你会崩溃,使用此函数来获取 iOS 8 中的视频路径

let urls = NSFileManager.defaultManager().URLsForDirectory(.DocumentDirectory, inDomains: .UserDomainMask)

let moviePath = urls[0].URLByAppendingPathComponent("hogevideo.mp4")

println("And append your video file name to urls: \(moviePath)")

关于swift - AVPlayerViewController 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31553832/

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