8 #import <AVFoundation/AVFoundation.h> |
8 #import <AVFoundation/AVFoundation.h> |
9 |
9 |
10 #define SKVolumeChangesPerSecond 15 |
10 #define SKVolumeChangesPerSecond 15 |
11 |
11 |
12 @interface MXAudioPlayerFadeOperation () |
12 @interface MXAudioPlayerFadeOperation () |
13 @property (nonatomic, retain, readwrite) AVAudioPlayer *audioPlayer; |
13 @property (nonatomic, strong, readwrite) AVAudioPlayer *audioPlayer; |
14 - (void)beginFadeOperation; |
14 - (void)beginFadeOperation; |
15 - (void)finishFadeOperation; |
15 - (void)finishFadeOperation; |
16 @end |
16 @end |
17 |
17 |
18 @implementation MXAudioPlayerFadeOperation |
18 @implementation MXAudioPlayerFadeOperation |
29 #pragma mark - |
29 #pragma mark - |
30 #pragma mark Accessors |
30 #pragma mark Accessors |
31 - (AVAudioPlayer *)audioPlayer { |
31 - (AVAudioPlayer *)audioPlayer { |
32 AVAudioPlayer *result; |
32 AVAudioPlayer *result; |
33 @synchronized(self) { |
33 @synchronized(self) { |
34 result = [_audioPlayer retain]; |
34 result = _audioPlayer; |
35 } |
35 } |
36 return [result autorelease]; |
36 return result; |
37 } |
37 } |
38 |
38 |
39 - (void)setAudioPlayer:(AVAudioPlayer *)anAudioPlayer { |
39 - (void)setAudioPlayer:(AVAudioPlayer *)anAudioPlayer { |
40 @synchronized(self) { |
40 @synchronized(self) { |
41 if (_audioPlayer != anAudioPlayer) { |
41 if (_audioPlayer != anAudioPlayer) { |
42 [_audioPlayer release]; |
42 _audioPlayer = anAudioPlayer; |
43 _audioPlayer = [anAudioPlayer retain]; |
|
44 } |
43 } |
45 } |
44 } |
46 } |
45 } |
47 |
46 |
48 #pragma mark - |
47 #pragma mark - |
49 #pragma mark NSOperation |
48 #pragma mark NSOperation |
50 -(id) initFadeWithAudioPlayer:(AVAudioPlayer*)player toVolume:(float)volume overDuration:(NSTimeInterval)duration withDelay:(NSTimeInterval)timeDelay { |
49 - (id)initFadeWithAudioPlayer:(AVAudioPlayer*)player toVolume:(float)volume overDuration:(NSTimeInterval)duration withDelay:(NSTimeInterval)timeDelay { |
51 if ((self = [super init])) { |
50 if ((self = [super init])) { |
52 self.audioPlayer = player; |
51 self.audioPlayer = player; |
53 [player prepareToPlay]; |
52 [player prepareToPlay]; |
54 _fadeDuration = duration; |
53 _fadeDuration = duration; |
55 _finishVolume = volume; |
54 _finishVolume = volume; |