Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open particular view controller after selecting a audio file in swift

Tags:

swift

I want to open particular view controller after selecting a audio file from document directory. I am doing this -:

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "PlaySoundsViewController") as! PlaySoundsViewController
    vc.recordedAudioURL = url
    self.navigationController?.pushViewController(vc, animated: false)
}

and open document directory using this -:

@IBAction func startBtn(_ sender: UIButton) {
    let pickerController = UIDocumentPickerViewController(documentTypes: ["public.audio"], in: .import)
    pickerController.delegate = self
    pickerController.modalPresentationStyle = .fullScreen
    self.present(pickerController, animated: true, completion: nil)
}
like image 890
Nikki Avatar asked Jan 19 '26 13:01

Nikki


1 Answers

you have to present the view controller

func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
    let vc = UIStoryboard.init(name: "Main", bundle: Bundle.main).instantiateViewController(withIdentifier: "PlaySoundsViewController") as! PlaySoundsViewController
    vc.recordedAudioURL = url
    self.present(vc, animated: true, completion: nil)
}
like image 66
Poornima Mishra Avatar answered Jan 22 '26 09:01

Poornima Mishra



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!