I am new to Object C, and I have two questions but I can not find the answers on stackoverflow.
My iOS app is simple, one button on the screen, and if user tap it, it will:
play a sound
get the time interval between 2 taps in millisecond.
Thanks to Owl, now the code to get the interval look like this:
(Long coding since I don't understand what is "UNIX time stamp" and I don't know where/how to use the second code.)
double dt1;
double dt2;
-(IBAction)Beated:(id)sender{
If (FB == 1) {
FB = 2;
NSDate *date = [NSDate date];
NSTimeInterval ti = [date timeIntervalSince1970];
dt1 = ti;
} else {
FB = 1
NSDate *date = [NSDate date];
NSTimeInterval ti = [date timeIntervalSince1970];
dt2 = ti;
double progress;
progress = dt2 - dt1;
int timeInMs = trunc(progress * 1000);
NSLog(@"Interval %d", timeInMs);
}
}
And after start the app, there is a lag when the sound was played for the first time, but it works good after the first tap. How to stop that lag?
My code to play the sound:
in .h
#import <AVFoundation/AVFoundation.h>
and
AVAudioPlayer *audioPlayer;
in .m
-(IBAction)Beated:(id)sender {
NSURL *url = [NSURL fileURLWithPath:[NSString stringWithFormat:@"%@/ssn.wav", [[NSBundle mainBundle] resourcePath]]];
NSError*error;
audioPlayer = [[AVAudioPlayer alloc] initWithContentsOfURL:url error:$error];
audioPlayer.numberOfLoops = 0;
[audioPlayer play];
}
Thanks