このカスタムクラスを使用してビデオを記録しています - https://github.com/piemonte/PBJVision。私はiOSアプリにビデオを録画しようとしていますが、コードをパーズサーバーにアップロードするのに正しいコードを取得できないようです。いくつかのこと:映像が記録された後の資産にアクセスするには:それはあなたがNSURL(videoPath fileWithPath)を使用することができますPBJVisionクラスでビデオを解析して再生するために保存する
。私はその後、解析から自分のデータを表示するのUITableViewを使用しています
func vision(vision: PBJVision, capturedVideo videoDict: [NSObject : AnyObject]?, error: NSError?) { if error != nil { print("Encountered error with video") isVideo = false } else { let currentVideo = videoDict let videoPath = currentVideo![PBJVisionVideoPathKey] as! String print("The video path is: \(videoPath)") self.player = Player() self.player.delegate = self self.player.view.frame = CGRect(x: cameraView.frame.origin.x, y: cameraView.frame.origin.y, width: cameraView.frame.width, height: cameraView.frame.height) self.player.playbackLoops = true videoUrl = NSURL(fileURLWithPath: videoPath) self.player.setUrl(videoUrl) self.cameraView.addSubview(self.player.view) self.player.playFromBeginning() nextButton.hidden = false isVideo = true let contents: NSData? do { contents = try NSData(contentsOfFile: videoPath, options: NSDataReadingOptions.DataReadingMappedAlways) } catch _ { contents = nil } print(contents) let videoObject = PFObject(className: "EventChatroomMessages") videoObject.setValue(user, forKey: "user") videoObject.setValue("uG7v2KWBQm", forKey: "eventId") videoObject.setValue(NSDate(), forKey: "timestamp") let videoFile: PFFile? do { videoFile = try PFFile(name: randomAlphaNumericString(26) + ".mp4", data: contents!, contentType: "video/mp4") print("VideoFile: \(videoFile)") } catch _ { print("error") } print(videoFile) videoObject.setValue(videoFile, forKey: "image") videoObject.saveInBackgroundWithBlock { (success: Bool, error: NSError?) -> Void in if success == true { ProgressHUD.showSuccess("Video Saved.", interaction: false) dispatch_async(dispatch_get_main_queue()) { ProgressHUD.dismiss() } } else { ProgressHUD.showError("Error Saving Video.", interaction: false) dispatch_async(dispatch_get_main_queue()) { ProgressHUD.dismiss() } } } }
}
:
let video = message.objectForKey("image") as! PFFile
let urlFromParse = video.url!
print(urlFromParse)
let url = NSURL(fileURLWithPath: video.url!)
print(url)
let playerNew = AVPlayer(URL: url!)
let playerLayer = AVPlayerLayer(player: playerNew)
playerLayer.frame = CGRectMake(0.0, nameLabel.frame.origin.y + nameLabel.frame.size.height + 0.0, self.view.frame.width, 150)
cell.layer.addSublayer(playerLayer)
playerLayer.backgroundColor = UIColor.whiteColor().CGColor
playerNew.play()
Iはその値をコピーurlFromParse(http://parlayapp.herokuapp.com/parse/files/smTrXDGZhlYQGh4BZcVvmZ2rYB9kA5EhPkGbj2R2/58c0648ae4ca9900f2d835feb77f165e_file.mp4)から返され、ブラウザに貼り付けられ、動画がブラウザで再生されます。ファイルが正しく保存されていると見なすのは正しいですか?
私のアプリを起動すると、ビデオは再生されません。私が間違っていることに関する何か提案はありますか?
あなたのコードの一部が正常であることを確認するために、アプリで再生するローカルファイルを取得できますか? – DogCoffee
テーブルの中のディスプレイメディアをテストするためにリンクを使用しました。私は次のリンクを使用しました: let videoUrl = NSURL(文字列: "https://v.cdn.vine.co/r/videos/AA3C120C521177175800441692160_38f2cbd1ffb.1.5.13763579289575020226.mp4")! –
ビデオの実際の再生は、(テストで見られるように)うまくいきます。ブラウザで貼り付けると、パースから取得したリンクが機能します...トリッキーなものです。あなたが解析したPSは数ヶ月後に消え去っていますか? – DogCoffee