简体   繁体   English

AVPlayerViewController问题

[英]AVPlayerViewController issues

so I am trying to edit some source code from this project source... https://github.com/ariiyu/VideoPlayerSample 所以我正在尝试从该项目源代码中编辑一些源代码... https://github.com/ariiyu/VideoPlayerSample

So, when I simply just try to replace the video path and file it crashes and I am not sure why?? 因此,当我只是尝试替换视频路径并归档时,它崩溃了,我不确定为什么吗?

Here is one of the ViewController source code... 这是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.
    }

}

In iOS 8 file system structure changed thats why you are getting crash use this function to get path of video in iOS 8 在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)")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM