在swift 3中转换NSData中的媒体选择器项

时间:2017-04-23 19:27:58

标签: ios swift

func getAudioData(url: URL, count:Int,completion: @escaping () -> Void){
    var fileName = String(format:"%@",url as CVarArg)
    let exportPath: NSString = NSTemporaryDirectory().appendingFormat(url.lastPathComponent) as NSString
    let exportURL = URL(fileURLWithPath: exportPath as String)


   // let exportPath = NSTemporaryDir
    let songAsset = AVURLAsset(url: url)

    let exporter = AVAssetExportSession(asset: songAsset, presetName: AVAssetExportPresetAppleM4A)
    exporter?.outputURL = exportURL
    exporter?.outputFileType = "com.apple.m4a-audio"
    exporter?.exportAsynchronously(completionHandler: {

        //DispatchQueue.global().async {
            if exporter?.status == .completed {
                var data = NSData(contentsOf: exportURL)
                print("complte")
            }
        if exporter?.status == .exporting {
            print("exporting")

        }
        if exporter?.status == .cancelled {
            print("cancelled")

        }
        if exporter?.status == .failed {

            print("failed %@", exporter?.error?.localizedDescription)

        }
        if exporter?.status == .waiting {
            print("waiting")

        }
              })
        /*let fileNameString = String(format:"%@",url as CVarArg )
        fileName = (fileNameString as NSString).lastPathComponent
        self.selectedImages.append( ["media":data!,"parameter":"image\(count)" as AnyObject,"filename":fileName! as AnyObject])
        debugPrint("selected image count === %@",self.selectedImages.count)
        completion()*/

}

错误:

0 个答案:

没有答案