As always after a lot of searching I back here to get help
my app playing sounds from url, I track the sound playing in uislider by update slider value when start the streamer playing
progressUpdateTimer =
[NSTimer
scheduledTimerWithTimeInterval:0.1
target:self
selector:#selector(updateProgress:)
userInfo:nil
repeats:YES];
- (void)updateProgress:(NSTimer *)updatedTimer
{
[progressView setValue: progress / duration];
}
this is my action for change slider value ( forward / backward the track)
- (IBAction)sliderMoved:(UISlider *)aSlider
{
if (streamer.duration)
{
double newSeekTime = (aSlider.value) * streamer.duration;
[streamer seekToTime:newSeekTime];
}
}
What I want is when the user change the slider the value updates instantly without late of loading .. I mean change the slider value then load the sound
But what happened is by dragging the slider thumb to x position , it backs to its position and then move to x when sound loaded
How can I do that ? any help will be appreciated
Related
I'm trying to create something that if I have a UIView with background of yellow, and this view is moving on the screen, and somewhere placed another UIView with background of red. How can I know if the yellow color touch the red color? - which mean's that the first view touches the another view.
During the animation you will have to periodically check for intersection like #AMI289 has said. e.g.
- (void)animate {
// Use an NSTimer to check for intersection 10 times per second
NSTimer *timer = [NSTimer scheduledTimerWithTimeInterval:0.1 target:self selector:#selector(checkForCollision) userInfo:nil repeats:YES];
[UIView animateWithDuration:5 animations:^{
// Do the animation
} completion:^(BOOL complete) {
// Tell timer to stop calling checkForCollision
[timer invalidate];
}];
}
- (void)checkForCollision {
if (CGRectIntersectsRect([viewOne.layer.presentationLayer frame], [viewTwo.layer.presentationLayer frame])) {
// Handle collision
}
}
It is important to get the presentation layer of the views that are being animated otherwise you will not detect incremental changes to the views' positions on the screen. You also need to invalidate the timer once you are done with it otherwise your checkForCollision method will continue to run indefinitely.
Is there a way implement something like this? http://i.imgur.com/JbhAMbK.gif I have tried using TTAttributedLabel but to no success (no flashing and time doesn't change anymore).
Does anyone know of a way to make something like this happen?
Any help would be greatly appreciated
Thanks Everyone
Matt
You can use timer.
- (NSTimer*)createTimer {
// create timer on run loop
return [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:#selector(timerTicked:) userInfo:nil repeats:YES];
}
- (void)timerTicked:(NSTimer*)timer {
[yourLabel setText:#""]
…
}
- (void)actionStop:(id)sender {
// stop the timer
[myTimer invalidate];
}
You could use CALayer to make it happen. Unless you make changes to the layer's default actions, every change committed on the layer in animated.
By setting up a timer you could make a repeating function that animates a change of the number to a different value (image ??) and set a completion block to change the colour.
That's what I would do.
In order to show that a certain state is in progress, I'm "pulsing" the UILabel that corresponds to that state, fading it from white to dark grey repeatedly.
I'm accomplishing this with NSTimers as shown below:
- (void)pulseColorsOfLabel:(NSTimer *)timer {
_timer = timer;
UILabel *labelToPulse = timer.userInfo;
// Check pulseCycle to determine at what point in the color transition the label is
if (_pulseCycle == 0) {
[UIView transitionWithView:labelToPulse duration:0.75 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
labelToPulse.textColor = [UIColor darkGrayColor];
} completion:nil];
_pulseCycle = 1;
}
else if (_pulseCycle == 1) {
[UIView transitionWithView:labelToPulse duration:0.75 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{
labelToPulse.textColor = [UIColor whiteColor];
} completion:nil];
_pulseCycle = 0;
}
}
And I use an NSTimer call to make that method fire every 0.75 seconds:
[NSTimer scheduledTimerWithTimeInterval:0.75 target:self selector:#selector(pulseColorsOfLabel:) userInfo:self.stateLabel repeats:YES];
And as the application goes through the various states, it marks the just completed state label green, invalidates the timer, and then changes the next state label to be pulsing (there's multiple states the app has to go through) with another NSTimer call. Basically a method is called as a delegate when the state changes, then the state is checked with a switch statement and the appropriate colors and pulsings are set.
Problem is, sometimes in the process of all the state labels turning green, some will disappear completely (as I assume they get stuck in the faded to white state against the white background) and sometimes they stay dark, or sometimes they pulse very sporadically.
I know this is an issue with the timers, as if I get less fancy and just make it change the state label to orange when in progress instead of pulsing, it works beautifully every time.
Any ideas what I could be doing here to make sure all the timer calls work well in conjunction with one another, and don't mess up the coloring of the labels?
I noticed in your code that _timer is assigned when the timer fires, which means that if the current timer hadn't fired at least once yet, you wouldn't be able to cancel it. Try invalidating and assigning the timer when you schedule it:
[_timer invalidate];
_timer = [NSTimer scheduledTimerWithTimeInterval:0.75 target:self selector:#selector(pulseColorsOfLabel:) userInfo:self.stateLabel repeats:YES];
If that doesn't work, some of your animations may be getting interrupted. Try removing the old animation before adding a new one:
UILabel *labelToPulse = timer.userInfo;
[labelToPulse.layer removeAllAnimations];
I have an image animation with total duration of 2 seconds and in total 6 images. It's a blinking button. I want to play a sound every time that button blink, so in interval of 0.66 seconds by 3 times. I tried do this but the last sound play its a microsecond delay that i dont want..What i can do to play the sound right?
I'm doing this:
-(void)playAnswerAnimSound
{
if(audioActive)
{
if(answerAnimCounter <3)
{
//AudioServicesDisposeSystemSoundID(answerAnimSound);
AudioServicesPlaySystemSound(answerAnimSound);
[answerAnimTimer invalidate];
answerAnimTimer = [NSTimer scheduledTimerWithTimeInterval:0.6666 target:self selector:#selector(playAnswerAnimSound) userInfo:nil repeats:NO];
answerAnimCounter++;
}
else if(answerAnimCounter == 3)
{
answerAnimCounter =0;
[answerAnimTimer invalidate];
}
}
}
The sound duration is 1 second.
Regards
You cannot sync audio by just generating calls to audio services at time intervals, you need to actually render out a .wav or .m4a file with all the audio clips already spaced out in time. Then, playback the generated audio as 1 longer clip and sync the video to the audio. See the linked answer for more details about the implementation.
I have an animation of a drinking glass filling up from empty to full, using CAKeyframeAnimation. The animation works perfectly fine.
I need to update a UILabel with the percentage corresponding to the fullness of the glass, i.e. it will read "0%" when the animation begins, and "100%" when it ends.
The keyframe animation runs for 5 seconds. I don't see a good way of updating this label. I can think of two options:
starting another thread and running a polling-type loop that updates the text at the cost of processing power.
break down the animation into 100 parts and use CABasicAnimation to update the text and then proceed with the next bit of glass animation.
Is there a better way to do this?
Thanks in advance
You can use either a NSTImer or dispatch_after() blocks to update the label at some scheduled interval:
// assume an ivar "NSTimer *myTimer" and "int count", initially 0
// fires 20 times, so update is 0.05
myTimer = NSTimer scheduledTimerWithTimeInterval:0.25 target:self selector:#selector(updateLabel:) userInfo:nil repeats:YES
- (void)updateLabel:(NSTimer *)timer
{
++count;
if(count >= 20) {
[timer invalidate];
}
CGFloat percent += 0.05;
myLabel.text = [NSString stringWithFormat:...
}