mirror of
https://github.com/oxen-io/session-ios.git
synced 2023-12-13 21:30:14 +01:00
c6d44e59e2
- Using same clang format file for old and new files. - Moving out all TextSecure code to allow other clients (OS X, iOS) to integrate easily TextSecure functionality. - Use TextSecure API to signup.
70 lines
1.7 KiB
Objective-C
70 lines
1.7 KiB
Objective-C
#import "SoundPlayer.h"
|
|
|
|
@interface SoundInstance ()
|
|
- (void)play;
|
|
- (void)stop;
|
|
@end
|
|
|
|
@implementation SoundPlayer
|
|
|
|
NSMutableDictionary *currentActiveAudioPlayers;
|
|
|
|
- (SoundPlayer *)init {
|
|
currentActiveAudioPlayers = [NSMutableDictionary dictionary];
|
|
return self;
|
|
}
|
|
|
|
#pragma mark Delegate Implementations
|
|
|
|
|
|
- (void)addSoundToManifest:(SoundInstance *)sound {
|
|
@synchronized(currentActiveAudioPlayers) {
|
|
[sound setCompeletionBlock:^(SoundInstance *soundInst) {
|
|
[self removeSoundFromManifest:soundInst];
|
|
if (self.delegate) {
|
|
[self.delegate didCompleteSoundInstanceOfType:soundInst.instanceType];
|
|
}
|
|
}];
|
|
[currentActiveAudioPlayers setValue:sound forKey:sound.getId];
|
|
}
|
|
}
|
|
- (void)removeSoundFromManifest:(SoundInstance *)sound {
|
|
[self removeSoundFromMainifestById:sound.getId];
|
|
}
|
|
|
|
- (void)removeSoundFromMainifestById:(NSString *)soundId {
|
|
@synchronized(currentActiveAudioPlayers) {
|
|
[currentActiveAudioPlayers removeObjectForKey:soundId];
|
|
}
|
|
}
|
|
|
|
- (void)playSound:(SoundInstance *)sound {
|
|
if (![self isSoundPlaying:sound]) {
|
|
[self addSoundToManifest:sound];
|
|
[sound play];
|
|
}
|
|
}
|
|
|
|
- (void)stopSound:(SoundInstance *)sound {
|
|
SoundInstance *playingSoundInstance = currentActiveAudioPlayers[sound.getId];
|
|
[self removeSoundFromManifest:sound];
|
|
[playingSoundInstance stop];
|
|
}
|
|
|
|
- (void)stopAllAudio {
|
|
for (SoundInstance *sound in currentActiveAudioPlayers.allValues) {
|
|
[self stopSound:sound];
|
|
}
|
|
}
|
|
|
|
- (BOOL)isSoundPlaying:(SoundInstance *)sound {
|
|
return nil != currentActiveAudioPlayers[sound.getId];
|
|
}
|
|
|
|
- (void)awake {
|
|
for (SoundInstance *sound in currentActiveAudioPlayers.allValues) {
|
|
[sound play];
|
|
}
|
|
}
|
|
|
|
@end
|