如果您使用AVAudioPlayer
with AVAudioRecorder
,则可以获得audioPlayer.duration
并获得时间。
像这样。
NSError *playerError;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:yoururl error:&playerError];
NSlog(@"%@",audioPlayer.duration);
但仅当您使用AVAudioPlayer
with 时AVAudioRecorder
。
更新
或者你可以这样做。
//put this where you start recording
myTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(updateTime) userInfo:nil repeats:YES];
// a method for update
- (void)updateTime {
if([recorder isRecording])
{
float minutes = floor(recorder.currentTime/60);
float seconds = recorder.currentTime - (minutes * 60);
NSString *time = [[NSString alloc]
initWithFormat:@"%0.0f.%0.0f",
minutes, seconds];
}
}
钢你可以得到一些延迟,因为它们是一些微秒值,我不知道如何剪辑它。但仅此而已。