views:

101

answers:

1

basically whenever i play a sound the animation slowing down or pauses, what to do ???

sound size 20kb mp3.

animation size 5kb png.

code:

- (void) startAnimation { 

 [UIView beginAnimations:nil context:nil];
 [UIView setAnimationDuration:0.8];
 CGPoint destination = CGPointMake(152,20);
 pink.center = destination;
 [UIView commitAnimations];
 [soundPink play];    
}


- (void) initSoundResources {

 soundPink = [[APlayer alloc] initWithFile:@"pink" type:@"mp3"];
 soundPink = 0.4;
 }
+2  A: 

Edit:

I've just noticed that in initSoundResources, you are alloc'ing and init'ing an APlayer object, but then assigning a float to the pointer straight afterwards. I'm pretty sure this isn't what you're intending.


Try this:

- (void) startAnimation { 
     [UIView beginAnimations:nil context:nil];
     [UIView setAnimationDuration:0.8];
     [UIView setAnimationDelegate:self];
     [UIView setAnimationDidStopSelector:@selector(playSound)];
     CGPoint destination = CGPointMake(152,20);
     pink.center = destination;
     [UIView commitAnimations];   
}


- (void) initSoundResources {
     soundPink = [[APlayer alloc] initWithFile:@"pink" type:@"mp3"];
     soundPink = 0.4;
}


- (void) playSound {
    //assuming initSoundResources is called at some point before this...
    [soundPink play];
}

The idea here is that UIView animations are asynchronous. If the animation is set to be 0.8 seconds long, that doesn't mean the code will take 0.8 seconds to run.

What I mean is that the code straight after the UIView animations code gets called effectively instantly after the animation code. In this case the sound is going to play (probably) before the animation even starts.

I can't imagine why it would pause or freeze, but using this method should work.

In my code, I have taken the assumption that the initSoundResources method is called at some point before trying to play the sound.

If the soundPink pointer is not initialised to nil or a valid sound instance, then sending it the play message may cause a crash.

Jasarien
first thanks!do i need to change something in my initSoundResources method ?i'm just synthesize the soundPink, do i need to do something more?how to this [UIViewsetAnimationDidStopSelector:@selector(playSound)];if i need to timer the sound ?[NSTimer scheduledTimerWithTimeInterval:1.8 target:self selector:@selector(playSound) userInfo:nil repeats:false];
nil
The code I gave you should just work, in regards to the UIViewAnimation delegate and didStopSelector.In regards to your initSoundResources, you need to not assign a float to the soundPink pointer. Surely the compiler should be warning you about that, did you not see it?
Jasarien
i didn't see no warning, what do you mean by assign a float?
nil
soundPink = [[APlayer alloc] initWithFile:@"pink" type:@"mp3"]; soundPink = 0.4; In that code, you are creating a new instance of an APlayer object, and assigning it to soundPink, which I assume is a pointer to an APlayer instance. Then, straight after, you're assigning 0.4, a floating point number, to the soundPink pointer. Regardless of what you defined soundPink as, assigning two different types of value to the variable should produce some kind of warning.
Jasarien