Problems Fading Out Music
Problems Fading Out Music
- Subject: Problems Fading Out Music
- From: Chunk 1978 <email@hidden>
- Date: Wed, 6 Jan 2010 19:55:25 -0500
i'm attempting to fade out music by supplying a duration and a target
volume, but i'm running into complications.
for this example, the current playing volume is set at 1.0, i want to
fade the volume down to 0.5 over a duration of 4 seconds. this works
alright - it's not perfect because i'm using performSelector which
needs to also take into account the time it takes to execute the
method, but i've set afterDelay to 0.15, which should be close enough.
however, the way i've written this method, supplying 0.0 as the
target volume will do nothing, and it seems that supplying other low
numbers, such as 2.0 makes the supplied duration increase.
i would *love* to find out how to fade the volume similar to how core
animation animates, by simply supplying a target and a duration and
allowing it to work out the details with precisely and automatically,
but i'm doubtful that's possible.
please help.
-----------------------------------------
#define kAfterDelay 0.15
// self.targetVolumeLevel is 0.5
// self.fadeDuration is 4.0
- (void)backgroundMusicFadeOut
{
if (self.backgroundAudio.volume > self.targetVolumeLevel)
{
self.backgroundAudio.volume -= self.targetVolumeLevel /
(self.fadeDuration / kAfterDelay);
[self performSelector:@selector(backgroundMusicFadeOut)
withObject:nil afterDelay:kAfterDelay];
}
else
{
NSLog(@"Fade Out Complete After %f Seconds", self.fadeDuration);
}
}
-----------------------------------------
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden