Encode sound at set intervals

I am new to this, so please carry me. I need to know how to encode a sound (or any object for that matter) in a certain period of time. Something simple, touch a button and a small sound file will play every x seconds until you touch another button or touch the same button again.

+3
source share
1 answer

NSTimer is what you are looking for to complete an action at regular intervals.

Creating a simple timer to perform some actions every 5 seconds will look something like this:

//This will start a repeating timer that will fire every 5 seconds
-(IBAction)startTimer {
    self.timer = [NSTimer scheduledTimerWithTimeInterval:5.0
                                                 target:self
                                               selector:@selector(someAction:)
                                               userInfo:nil
                                                repeats:YES];
}

//The method the timer will call when fired
-(void)someAction:(NSTimer *)aTimer {
    //Do stuff here
}


-(IBAction)stopTimer {
    [self.timer invalidate];
}

, iOS . , Apple , .

+5

Source: https://habr.com/ru/post/1785662/


All Articles