我使用UI ImagePickerController从我的库中选择一个视频.我需要提取我的视频文件的NSData.我使用以下操作从我的库中选择一个视频,但我的数据似乎是零,但我的AVPlayer播放结果NSURL中的视频,所
func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) { let fileURL = info[UIImagePickerControllerReferenceURL] as! NSURL! let data = NSData(contentsOfURL: fileURL) print(data) player = AVPlayer(URL: fileURL) let playerLayer = AVPlayerLayer(player: player) playerLayer.frame = CGRectMake(0, 0, 300, 300) self.view.layer.addSublayer(playerLayer) player.play() self.dismissViewControllerAnimated(true, completion: nil) }尝试将UIImagePickerControllerReferenceURL更改为
UIImagePickerControllerMediaURL
而不是让data = NSData(contentsOfURL:fileURL)
let video3 = try NSData(contentsOfURL: videoDataURL, options: .DataReadingMappedIfSafe)