mirror of
https://github.com/purplecabbage/phonegap-plugins.git
synced 2026-01-14 08:57:53 -05:00
27 lines
1.1 KiB
Objective-C
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
|