I am recording audio using AVAudioRecorder
,and now i want to get exact time duration of my recorded audio,how can i get that.
i have tried this:
AVURLAsset *asset = [[AVURLAsset alloc] initWithURL:avAudioRecorder.url options:nil];
CMTime time = asset.duration;
double durationInSeconds = CMTimeGetSeconds(time);
But my time
variable return NULL and durationInSeconds
return 'nan',what does that means by nan.
UPDATE
user1903074
answer have solved my problem but just for curiosity ,is thair any way to do it without AVAudioplayer
.
I know the original question was looking for an answer in Objective-C, but for those looking to do so in Swift, this works with Swift 4.0:
Assuming you have a valid recorder, then you will get a duration value, which is given as a
TimeInterval
.If you are using
AVAudioPlayer
withAVAudioRecorder
than you can get theaudioPlayer.duration
and get the time.like this.
But only if you are using
AVAudioPlayer
withAVAudioRecorder
.UPDATE
Or you can do like this.
steel you can get some delay becouse their is some microsecond value,and i dont know how to clip it .but thats all.
My solution is simply to keep track of the start date, and at the end, calculate the time passed. It worked for me because the user is starting and stopping the recorder.
In the recorder class