使用UIWebView播放视频时出错

时间:2016-12-14 06:59:51

标签: ios swift firebase uiwebview firebase-storage

我正在尝试使用UIWebView播放视频,但即使从服务器下载视频,它也没有显示任何视频。有谁知道我在这里做错了什么?

这是我的代码:

 override func viewDidLoad() {
    super.viewDidLoad()

    self.pdfView.delegate = self
    self.pdfView.mediaPlaybackRequiresUserAction = false

    if "" !=  video?.videoPath {
        self.loadFromUrl(path: (video?.videoPath)!)
        self.activityIND.isHidden = true
        self.activityIND.stopAnimating()
    } else {

        let documentsPath = NSSearchPathForDirectoriesInDomains(.documentDirectory, .userDomainMask, true)[0]
        let strName = video?.id
        let filePath = "\(documentsPath)/"+strName!+".wmv"
        let fileManager = FileManager.default
        self.activityIND.startAnimating()

        if fileManager.fileExists(atPath: filePath) {
            self.loadFromUrl(path: filePath)
            return;
        }


        let reference = FIRStorage.storage().reference(forURL: (self.video?.videoURL)!)
        reference.data(withMaxSize: 50 * 1024 * 1024) { (data, error) -> Void in
            if (error != nil) {

                print ("unable to download video file from Firebase Storage")

                self.activityIND.isHidden = false
                self.activityIND.startAnimating()

            } else {

                if ((try! data?.write(to: URL.init(fileURLWithPath: filePath, isDirectory: false))) != nil) {
                    self.loadFromUrl(path: filePath)
                    print ("video file is downloaded from Firebase Storage")
                    self.db.upDate(id: (self.video?.id)!, videoPath: filePath)
                    self.activityIND.isHidden = true
                }
            }
        }

    }
}



func loadFromUrl(path: String)
{

     let url =  NSURL(string:path)
        pdfView.loadRequest(NSURLRequest(url: url! as URL) as URLRequest)

        activityIND.isHidden = true
        activityIND.startAnimating()

}

1 个答案:

答案 0 :(得分:0)

结果表明不支持wmv格式,一旦我将格式更改为mp4一切正常