【问题标题】:AVPlayerViewController issuesAVPlayerViewController 问题
【发布时间】:2015-07-22 04:23:37
【问题描述】:

所以我正在尝试从这个项目源中编辑一些源代码...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.
    }

}

【问题讨论】:

  • 确保您的文件存在。
  • 我实际上只是想通了...我没有将文件设置为以项目为目标。不过谢谢

标签: swift xcode6 avplayerview


【解决方案1】:

在 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)")

【讨论】:

    猜你喜欢
    • 2017-12-04
    • 2019-01-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-04-24
    • 2017-03-18
    • 2015-10-20
    • 2020-01-28
    相关资源
    最近更新 更多