Record audio to Local and fetch and Play iOS swift 3
When the audio has to be recorded and saved to the document directory then save the filename to the database.
If you save the path then it will vary every time.you cannot able to play.
Code:
let currentFileName = "recording-\(format.string(from: Date())).m4a"
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let URL = documentsDirectory.appendingPathComponent(currentFileName)
let FileName = currentFileName
Code:
let documentsDirectory = FileManager.default.urls(for: .documentDirectory, in: .userDomainMask)[0]
let urls = documentsDirectory.appendingPathComponent(soundFileURL)
let asset = AVURLAsset(url: urls, options: nil)
Code:
let audioDuration = asset.duration
let audioDurationSeconds = CMTimeGetSeconds(audioDuration)
Comments
Post a Comment