Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 17 additions & 18 deletions RNSound/RNSound.m
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ -(void) audioPlayerDidFinishPlaying:(AVAudioPlayer*)player
[self setOnPlay:NO forPlayerKey:key];
RCTResponseSenderBlock callback = [self callbackForKey:key];
if (callback) {
callback(@[@(flag)]);
callback([NSArray arrayWithObjects:[NSNumber numberWithBool:flag], nil]);
[[self callbackPool] removeObjectForKey:key];
}
}
Expand All @@ -88,17 +88,17 @@ -(void) audioPlayerDidFinishPlaying:(AVAudioPlayer*)player
RCT_EXPORT_MODULE();

-(NSArray<NSString *> *)supportedEvents
{
return @[@"onPlayChange"];
}
{
return [NSArray arrayWithObjects: @"onPlayChange", nil];
}

-(NSDictionary *)constantsToExport {
return @{@"IsAndroid": [NSNumber numberWithBool:NO],
@"MainBundlePath": [[NSBundle mainBundle] bundlePath],
@"NSDocumentDirectory": [self getDirectory:NSDocumentDirectory],
@"NSLibraryDirectory": [self getDirectory:NSLibraryDirectory],
@"NSCachesDirectory": [self getDirectory:NSCachesDirectory],
};
return [NSDictionary dictionaryWithObjectsAndKeys:
[NSNumber numberWithBool:NO], @"IsAndroid",
[[NSBundle mainBundle] bundlePath], @"MainBundlePath",
[self getDirectory:NSDocumentDirectory], @"NSDocumentDirectory",
[self getDirectory:NSLibraryDirectory], @"NSLibraryDirectory",
[self getDirectory:NSCachesDirectory], @"NSCachesDirectory", nil];
}

RCT_EXPORT_METHOD(enable:(BOOL)enabled) {
Expand Down Expand Up @@ -208,10 +208,9 @@ -(NSDictionary *)constantsToExport {
player.enableRate = YES;
[player prepareToPlay];
[[self playerPool] setObject:player forKey:key];
callback(@[[NSNull null], @{@"duration": @(player.duration),
@"numberOfChannels": @(player.numberOfChannels)}]);
callback([NSArray arrayWithObjects:[NSNull null], [NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithDouble:player.duration], @"duration", [NSNumber numberWithUnsignedInteger:player.numberOfChannels], @"numberOfChannels", nil], nil]);
} else {
callback(@[RCTJSErrorFromNSError(error)]);
callback([NSArray arrayWithObjects:RCTJSErrorFromNSError(error), nil]);
}
}

Expand All @@ -231,7 +230,7 @@ -(NSDictionary *)constantsToExport {
AVAudioPlayer* player = [self playerForKey:key];
if (player) {
[player pause];
callback(@[]);
callback([NSArray array]);
}
}

Expand All @@ -240,7 +239,7 @@ -(NSDictionary *)constantsToExport {
if (player) {
[player stop];
player.currentTime = 0;
callback(@[]);
callback([NSArray array]);
}
}

Expand Down Expand Up @@ -295,9 +294,9 @@ -(NSDictionary *)constantsToExport {
withCallback:(RCTResponseSenderBlock)callback) {
AVAudioPlayer* player = [self playerForKey:key];
if (player) {
callback(@[@(player.currentTime), @(player.isPlaying)]);
callback([NSArray arrayWithObjects:[NSNumber numberWithDouble:player.currentTime], [NSNumber numberWithBool: player.isPlaying], nil]);
} else {
callback(@[@(-1), @(false)]);
callback([NSArray arrayWithObjects:[NSNumber numberWithInteger:-1], [NSNumber numberWithBool:NO], nil]);
}
}

Expand All @@ -306,6 +305,6 @@ + (BOOL)requiresMainQueueSetup
return YES;
}
- (void)setOnPlay:(BOOL)isPlaying forPlayerKey:(nonnull NSNumber*)playerKey {
[self sendEventWithName:@"onPlayChange" body:@{@"isPlaying": isPlaying ? @YES : @NO, @"playerKey": playerKey}];
[self sendEventWithName:@"onPlayChange" body:[NSDictionary dictionaryWithObjectsAndKeys: [NSNumber numberWithBool: isPlaying ? YES : NO], @"isPlaying", playerKey, @"playerKey", nil]];
}
@end
6 changes: 3 additions & 3 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apply plugin: 'com.android.library'

android {
compileSdkVersion 23
buildToolsVersion "23.0.1"
compileSdkVersion 26
buildToolsVersion "26.0.3"

defaultConfig {
minSdkVersion 16
targetSdkVersion 23
targetSdkVersion 26
versionCode 1
versionName "1.0"
ndk {
Expand Down