私はオブジェクトCを初めて使用し、2つの質問がありますが、stackoverflowで答えを見つけることができません。
私のiOSアプリはシンプルで、画面上のボタンが1つあり、ユーザーがそれをタップすると、次のようになります。
音を出す
2タップ間の時間間隔をミリ秒で取得します。
Owlのおかげで、間隔を取得するコードは次のようになります。
(「UNIXタイムスタンプ」とは何かがわからず、2番目のコードをどこでどのように使用するかわからないため、長いコーディングです。)
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);
}
}
また、アプリを起動してから初めて音を鳴らしたときは遅れがありますが、最初のタップ以降は問題なく動作します。その遅れを止める方法は?
サウンドを再生するための私のコード:
.hで
#import <AVFoundation/AVFoundation.h>
と
AVAudioPlayer *audioPlayer;
.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];
}
ありがとう