mirror of https://github.com/oxen-io/session-ios
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
69 lines
1.7 KiB
Matlab
69 lines
1.7 KiB
Matlab
11 years ago
|
#import "SoundPlayer.h"
|
||
|
#import "SoundBoard.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];
|
||
|
}];
|
||
|
[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 objectForKey:[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 objectForKey:[sound getId]];
|
||
|
}
|
||
|
|
||
|
-(void) awake {
|
||
|
for( SoundInstance* sound in [currentActiveAudioPlayers allValues]){
|
||
|
[sound play];
|
||
|
}
|
||
|
}
|
||
|
|
||
|
@end
|