Files
phonegap-plugins/iPhone/SoundPlug/SoundPlug.m
2011-06-20 00:14:00 +02:00

27 lines
1.1 KiB
Objective-C

#import "SoundPlug.h"
@implementation SoundPlug
- (void) play:(NSMutableArray*)arguments withDict:(NSMutableDictionary*)options
{
NSBundle * mainBundle = [NSBundle mainBundle];
NSMutableArray *directoryParts = [NSMutableArray arrayWithArray:[(NSString*)[arguments objectAtIndex:0] componentsSeparatedByString:@"/"]];
NSString *filename = [directoryParts lastObject];
[directoryParts removeLastObject];
NSMutableArray *filenameParts = [NSMutableArray arrayWithArray:[filename componentsSeparatedByString:@"."]];
NSString *directoryStr = [directoryParts componentsJoinedByString:@"/"];
NSString *filePath = [mainBundle pathForResource:(NSString*)[filenameParts objectAtIndex:0]
ofType:(NSString*)[filenameParts objectAtIndex:1]
inDirectory:directoryStr];
SystemSoundID soundID;
NSURL *fileURL = [NSURL fileURLWithPath:filePath];
AudioServicesCreateSystemSoundID((CFURLRef)fileURL, &soundID);
AudioServicesPlaySystemSound(soundID);
}
@end