diff --git a/RNSound.xcodeproj/project.pbxproj b/RNSound.xcodeproj/project.pbxproj deleted file mode 100644 index a8631a47c81c659a9154ce732a1489d781caad45..0000000000000000000000000000000000000000 --- a/RNSound.xcodeproj/project.pbxproj +++ /dev/null @@ -1,260 +0,0 @@ -// !$*UTF8*$! -{ - archiveVersion = 1; - classes = { - }; - objectVersion = 46; - objects = { - -/* Begin PBXBuildFile section */ - 19825A221BD4A89800EE0337 /* RNSound.h in CopyFiles */ = {isa = PBXBuildFile; fileRef = 19825A211BD4A89800EE0337 /* RNSound.h */; }; - 19825A241BD4A89800EE0337 /* RNSound.m in Sources */ = {isa = PBXBuildFile; fileRef = 19825A231BD4A89800EE0337 /* RNSound.m */; }; -/* End PBXBuildFile section */ - -/* Begin PBXCopyFilesBuildPhase section */ - 19825A1C1BD4A89800EE0337 /* CopyFiles */ = { - isa = PBXCopyFilesBuildPhase; - buildActionMask = 2147483647; - dstPath = "include/$(PRODUCT_NAME)"; - dstSubfolderSpec = 16; - files = ( - 19825A221BD4A89800EE0337 /* RNSound.h in CopyFiles */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXCopyFilesBuildPhase section */ - -/* Begin PBXFileReference section */ - 19825A1E1BD4A89800EE0337 /* libRNSound.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = libRNSound.a; sourceTree = BUILT_PRODUCTS_DIR; }; - 19825A211BD4A89800EE0337 /* RNSound.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = RNSound.h; sourceTree = ""; }; - 19825A231BD4A89800EE0337 /* RNSound.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = RNSound.m; sourceTree = ""; }; -/* End PBXFileReference section */ - -/* Begin PBXFrameworksBuildPhase section */ - 19825A1B1BD4A89800EE0337 /* Frameworks */ = { - isa = PBXFrameworksBuildPhase; - buildActionMask = 2147483647; - files = ( - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXFrameworksBuildPhase section */ - -/* Begin PBXGroup section */ - 19825A151BD4A89800EE0337 = { - isa = PBXGroup; - children = ( - 19825A201BD4A89800EE0337 /* RNSound */, - 19825A1F1BD4A89800EE0337 /* Products */, - ); - sourceTree = ""; - }; - 19825A1F1BD4A89800EE0337 /* Products */ = { - isa = PBXGroup; - children = ( - 19825A1E1BD4A89800EE0337 /* libRNSound.a */, - ); - name = Products; - sourceTree = ""; - }; - 19825A201BD4A89800EE0337 /* RNSound */ = { - isa = PBXGroup; - children = ( - 19825A211BD4A89800EE0337 /* RNSound.h */, - 19825A231BD4A89800EE0337 /* RNSound.m */, - ); - path = RNSound; - sourceTree = ""; - }; -/* End PBXGroup section */ - -/* Begin PBXNativeTarget section */ - 19825A1D1BD4A89800EE0337 /* RNSound */ = { - isa = PBXNativeTarget; - buildConfigurationList = 19825A271BD4A89800EE0337 /* Build configuration list for PBXNativeTarget "RNSound" */; - buildPhases = ( - 19825A1A1BD4A89800EE0337 /* Sources */, - 19825A1B1BD4A89800EE0337 /* Frameworks */, - 19825A1C1BD4A89800EE0337 /* CopyFiles */, - ); - buildRules = ( - ); - dependencies = ( - ); - name = RNSound; - productName = RNSound; - productReference = 19825A1E1BD4A89800EE0337 /* libRNSound.a */; - productType = "com.apple.product-type.library.static"; - }; -/* End PBXNativeTarget section */ - -/* Begin PBXProject section */ - 19825A161BD4A89800EE0337 /* Project object */ = { - isa = PBXProject; - attributes = { - LastUpgradeCheck = 0700; - ORGANIZATIONNAME = zmxv; - TargetAttributes = { - 19825A1D1BD4A89800EE0337 = { - CreatedOnToolsVersion = 7.0.1; - }; - }; - }; - buildConfigurationList = 19825A191BD4A89800EE0337 /* Build configuration list for PBXProject "RNSound" */; - compatibilityVersion = "Xcode 3.2"; - developmentRegion = English; - hasScannedForEncodings = 0; - knownRegions = ( - en, - ); - mainGroup = 19825A151BD4A89800EE0337; - productRefGroup = 19825A1F1BD4A89800EE0337 /* Products */; - projectDirPath = ""; - projectRoot = ""; - targets = ( - 19825A1D1BD4A89800EE0337 /* RNSound */, - ); - }; -/* End PBXProject section */ - -/* Begin PBXSourcesBuildPhase section */ - 19825A1A1BD4A89800EE0337 /* Sources */ = { - isa = PBXSourcesBuildPhase; - buildActionMask = 2147483647; - files = ( - 19825A241BD4A89800EE0337 /* RNSound.m in Sources */, - ); - runOnlyForDeploymentPostprocessing = 0; - }; -/* End PBXSourcesBuildPhase section */ - -/* Begin XCBuildConfiguration section */ - 19825A251BD4A89800EE0337 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = dwarf; - ENABLE_STRICT_OBJC_MSGSEND = YES; - ENABLE_TESTABILITY = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_DYNAMIC_NO_PIC = NO; - GCC_NO_COMMON_BLOCKS = YES; - GCC_OPTIMIZATION_LEVEL = 0; - GCC_PREPROCESSOR_DEFINITIONS = ( - "DEBUG=1", - "$(inherited)", - ); - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(SRCROOT)/../react-native/React/**", - "$(SRCROOT)/node_modules/react-native/React/**", - ); - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = YES; - ONLY_ACTIVE_ARCH = YES; - SDKROOT = iphoneos; - }; - name = Debug; - }; - 19825A261BD4A89800EE0337 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - ALWAYS_SEARCH_USER_PATHS = NO; - CLANG_CXX_LANGUAGE_STANDARD = "gnu++0x"; - CLANG_CXX_LIBRARY = "libc++"; - CLANG_ENABLE_MODULES = YES; - CLANG_ENABLE_OBJC_ARC = YES; - CLANG_WARN_BOOL_CONVERSION = YES; - CLANG_WARN_CONSTANT_CONVERSION = YES; - CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; - CLANG_WARN_EMPTY_BODY = YES; - CLANG_WARN_ENUM_CONVERSION = YES; - CLANG_WARN_INT_CONVERSION = YES; - CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; - CLANG_WARN_UNREACHABLE_CODE = YES; - CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; - COPY_PHASE_STRIP = NO; - DEBUG_INFORMATION_FORMAT = "dwarf-with-dsym"; - ENABLE_NS_ASSERTIONS = NO; - ENABLE_STRICT_OBJC_MSGSEND = YES; - GCC_C_LANGUAGE_STANDARD = gnu99; - GCC_NO_COMMON_BLOCKS = YES; - GCC_WARN_64_TO_32_BIT_CONVERSION = YES; - GCC_WARN_ABOUT_RETURN_TYPE = YES_ERROR; - GCC_WARN_UNDECLARED_SELECTOR = YES; - GCC_WARN_UNINITIALIZED_AUTOS = YES_AGGRESSIVE; - GCC_WARN_UNUSED_FUNCTION = YES; - GCC_WARN_UNUSED_VARIABLE = YES; - HEADER_SEARCH_PATHS = ( - "$(SRCROOT)/../react-native/React/**", - "$(SRCROOT)/node_moduels/react-native/React/**", - ); - IPHONEOS_DEPLOYMENT_TARGET = 9.0; - MTL_ENABLE_DEBUG_INFO = NO; - SDKROOT = iphoneos; - VALIDATE_PRODUCT = YES; - }; - name = Release; - }; - 19825A281BD4A89800EE0337 /* Debug */ = { - isa = XCBuildConfiguration; - buildSettings = { - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Debug; - }; - 19825A291BD4A89800EE0337 /* Release */ = { - isa = XCBuildConfiguration; - buildSettings = { - OTHER_LDFLAGS = "-ObjC"; - PRODUCT_NAME = "$(TARGET_NAME)"; - SKIP_INSTALL = YES; - }; - name = Release; - }; -/* End XCBuildConfiguration section */ - -/* Begin XCConfigurationList section */ - 19825A191BD4A89800EE0337 /* Build configuration list for PBXProject "RNSound" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 19825A251BD4A89800EE0337 /* Debug */, - 19825A261BD4A89800EE0337 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; - 19825A271BD4A89800EE0337 /* Build configuration list for PBXNativeTarget "RNSound" */ = { - isa = XCConfigurationList; - buildConfigurations = ( - 19825A281BD4A89800EE0337 /* Debug */, - 19825A291BD4A89800EE0337 /* Release */, - ); - defaultConfigurationIsVisible = 0; - defaultConfigurationName = Release; - }; -/* End XCConfigurationList section */ - }; - rootObject = 19825A161BD4A89800EE0337 /* Project object */; -} diff --git a/RNSound.xcodeproj/project.xcworkspace/contents.xcworkspacedata b/RNSound.xcodeproj/project.xcworkspace/contents.xcworkspacedata deleted file mode 100644 index 554a9b5036a62b5f2dd6c5ce6490d1f720ab9a27..0000000000000000000000000000000000000000 --- a/RNSound.xcodeproj/project.xcworkspace/contents.xcworkspacedata +++ /dev/null @@ -1,7 +0,0 @@ - - - - - diff --git a/RNSound/RNSound.h b/RNSound/RNSound.h deleted file mode 100644 index 7f5b97b4c5a1dbbb1f89cbeb57ef1c6439a29196..0000000000000000000000000000000000000000 --- a/RNSound/RNSound.h +++ /dev/null @@ -1,17 +0,0 @@ -#if __has_include() -#import -#else -#import "RCTBridgeModule.h" -#endif - -#import - -#if __has_include() -#import -#else -#import "RCTEventEmitter.h" -#endif - -@interface RNSound : RCTEventEmitter -@property (nonatomic, weak) NSNumber *_key; -@end diff --git a/RNSound/RNSound.m b/RNSound/RNSound.m deleted file mode 100644 index df3784e47bbf9e476a25ad9b1d857a5d20f878cf..0000000000000000000000000000000000000000 --- a/RNSound/RNSound.m +++ /dev/null @@ -1,381 +0,0 @@ -#import "RNSound.h" - -#if __has_include("RCTUtils.h") -#import "RCTUtils.h" -#else -#import -#endif - -@implementation RNSound { - NSMutableDictionary *_playerPool; - NSMutableDictionary *_callbackPool; -} - -@synthesize _key = _key; - -- (void)audioSessionChangeObserver:(NSNotification *)notification { - NSDictionary *userInfo = notification.userInfo; - AVAudioSessionRouteChangeReason audioSessionRouteChangeReason = - [userInfo[@"AVAudioSessionRouteChangeReasonKey"] longValue]; - AVAudioSessionInterruptionType audioSessionInterruptionType = - [userInfo[@"AVAudioSessionInterruptionTypeKey"] longValue]; - AVAudioPlayer *player = [self playerForKey:self._key]; - if (audioSessionInterruptionType == AVAudioSessionInterruptionTypeEnded) { - if (player && player.isPlaying) { - [player play]; - [self setOnPlay:YES forPlayerKey:self._key]; - } - } - if (audioSessionRouteChangeReason == - AVAudioSessionRouteChangeReasonOldDeviceUnavailable) { - if (player) { - [player pause]; - [self setOnPlay:NO forPlayerKey:self._key]; - } - } - if (audioSessionInterruptionType == AVAudioSessionInterruptionTypeBegan) { - if (player) { - [player pause]; - [self setOnPlay:NO forPlayerKey:self._key]; - } - } -} - -- (NSMutableDictionary *)playerPool { - if (!_playerPool) { - _playerPool = [NSMutableDictionary new]; - } - return _playerPool; -} - -- (NSMutableDictionary *)callbackPool { - if (!_callbackPool) { - _callbackPool = [NSMutableDictionary new]; - } - return _callbackPool; -} - -- (AVAudioPlayer *)playerForKey:(nonnull NSNumber *)key { - return [[self playerPool] objectForKey:key]; -} - -- (NSNumber *)keyForPlayer:(nonnull AVAudioPlayer *)player { - return [[[self playerPool] allKeysForObject:player] firstObject]; -} - -- (RCTResponseSenderBlock)callbackForKey:(nonnull NSNumber *)key { - return [[self callbackPool] objectForKey:key]; -} - -- (NSString *)getDirectory:(int)directory { - return [NSSearchPathForDirectoriesInDomains(directory, NSUserDomainMask, - YES) firstObject]; -} - -- (void)audioPlayerDidFinishPlaying:(AVAudioPlayer *)player - successfully:(BOOL)flag { - @synchronized(self) { - NSNumber *key = [self keyForPlayer:player]; - if (key == nil) - return; - - [self setOnPlay:NO forPlayerKey:key]; - RCTResponseSenderBlock callback = [self callbackForKey:key]; - if (callback) { - callback( - [NSArray arrayWithObjects:[NSNumber numberWithBool:flag], nil]); - [[self callbackPool] removeObjectForKey:key]; - } - } -} - -RCT_EXPORT_MODULE(); - -- (NSArray *)supportedEvents { - return [NSArray arrayWithObjects:@"onPlayChange", nil]; -} - -- (NSDictionary *)constantsToExport { - 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) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - [session setCategory:AVAudioSessionCategoryAmbient error:nil]; - [session setActive:enabled error:nil]; -} - -RCT_EXPORT_METHOD(setActive : (BOOL)active) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - [session setActive:active error:nil]; -} - -RCT_EXPORT_METHOD(setMode : (NSString *)modeName) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - NSString *mode = nil; - - if ([modeName isEqual:@"Default"]) { - mode = AVAudioSessionModeDefault; - } else if ([modeName isEqual:@"VoiceChat"]) { - mode = AVAudioSessionModeVoiceChat; - } else if ([modeName isEqual:@"VideoChat"]) { - mode = AVAudioSessionModeVideoChat; - } else if ([modeName isEqual:@"GameChat"]) { - mode = AVAudioSessionModeGameChat; - } else if ([modeName isEqual:@"VideoRecording"]) { - mode = AVAudioSessionModeVideoRecording; - } else if ([modeName isEqual:@"Measurement"]) { - mode = AVAudioSessionModeMeasurement; - } else if ([modeName isEqual:@"MoviePlayback"]) { - mode = AVAudioSessionModeMoviePlayback; - } else if ([modeName isEqual:@"SpokenAudio"]) { - mode = AVAudioSessionModeSpokenAudio; - } - - if (mode) { - [session setMode:mode error:nil]; - } -} - -RCT_EXPORT_METHOD(setCategory - : (NSString *)categoryName mixWithOthers - : (BOOL)mixWithOthers) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - NSString *category = nil; - - if ([categoryName isEqual:@"Ambient"]) { - category = AVAudioSessionCategoryAmbient; - } else if ([categoryName isEqual:@"SoloAmbient"]) { - category = AVAudioSessionCategorySoloAmbient; - } else if ([categoryName isEqual:@"Playback"]) { - category = AVAudioSessionCategoryPlayback; - } else if ([categoryName isEqual:@"Record"]) { - category = AVAudioSessionCategoryRecord; - } else if ([categoryName isEqual:@"PlayAndRecord"]) { - category = AVAudioSessionCategoryPlayAndRecord; - } -#if TARGET_OS_IOS - else if ([categoryName isEqual:@"AudioProcessing"]) { - category = AVAudioSessionCategoryAudioProcessing; - } -#endif - else if ([categoryName isEqual:@"MultiRoute"]) { - category = AVAudioSessionCategoryMultiRoute; - } - - if (category) { - if (mixWithOthers) { - [session setCategory:category - withOptions:AVAudioSessionCategoryOptionMixWithOthers | - AVAudioSessionCategoryOptionAllowBluetooth - error:nil]; - } else { - [session setCategory:category error:nil]; - } - } -} - -RCT_EXPORT_METHOD(enableInSilenceMode : (BOOL)enabled) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - [session setCategory:AVAudioSessionCategoryPlayback error:nil]; - [session setActive:enabled error:nil]; -} - -RCT_EXPORT_METHOD(prepare - : (NSString *)fileName withKey - : (nonnull NSNumber *)key withOptions - : (NSDictionary *)options withCallback - : (RCTResponseSenderBlock)callback) { - NSError *error; - NSURL *fileNameUrl; - AVAudioPlayer *player; - NSString* fileNameEscaped = [fileName stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; - - if ([fileNameEscaped hasPrefix:@"http"]) { - fileNameUrl = [NSURL URLWithString:fileNameEscaped]; - NSData *data = [NSData dataWithContentsOfURL:fileNameUrl]; - player = [[AVAudioPlayer alloc] initWithData:data error:&error]; - } else if ([fileNameEscaped hasPrefix:@"ipod-library://"]) { - fileNameUrl = [NSURL URLWithString:fileNameEscaped]; - player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileNameUrl - error:&error]; - } else { - fileNameUrl = [NSURL URLWithString:fileNameEscaped]; - player = [[AVAudioPlayer alloc] initWithContentsOfURL:fileNameUrl - error:&error]; - } - - if (player) { - @synchronized(self) { - player.delegate = self; - player.enableRate = YES; - [player prepareToPlay]; - [[self playerPool] setObject:player forKey:key]; - callback([NSArray - arrayWithObjects:[NSNull null], - [NSDictionary - dictionaryWithObjectsAndKeys: - [NSNumber - numberWithDouble:player.duration], - @"duration", - [NSNumber numberWithUnsignedInteger: - player.numberOfChannels], - @"numberOfChannels", nil], - nil]); - } - } else { - callback([NSArray arrayWithObjects:RCTJSErrorFromNSError(error), nil]); - } -} - -RCT_EXPORT_METHOD(play - : (nonnull NSNumber *)key withCallback - : (RCTResponseSenderBlock)callback) { - [[AVAudioSession sharedInstance] setActive:YES error:nil]; - [[NSNotificationCenter defaultCenter] - addObserver:self - selector:@selector(audioSessionChangeObserver:) - name:AVAudioSessionRouteChangeNotification - object:nil]; - self._key = key; - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - [[self callbackPool] setObject:[callback copy] forKey:key]; - [player play]; - [self setOnPlay:YES forPlayerKey:key]; - } -} - -RCT_EXPORT_METHOD(pause - : (nonnull NSNumber *)key withCallback - : (RCTResponseSenderBlock)callback) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - [player pause]; - callback([NSArray array]); - } -} - -RCT_EXPORT_METHOD(stop - : (nonnull NSNumber *)key withCallback - : (RCTResponseSenderBlock)callback) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - [player stop]; - player.currentTime = 0; - callback([NSArray array]); - } -} - -RCT_EXPORT_METHOD(release : (nonnull NSNumber *)key) { - @synchronized(self) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - [player stop]; - [[self callbackPool] removeObjectForKey:key]; - [[self playerPool] removeObjectForKey:key]; - NSNotificationCenter *notificationCenter = - [NSNotificationCenter defaultCenter]; - [notificationCenter removeObserver:self]; - } - } -} - -RCT_EXPORT_METHOD(setVolume - : (nonnull NSNumber *)key withValue - : (nonnull NSNumber *)value) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - player.volume = [value floatValue]; - } -} - -RCT_EXPORT_METHOD(getSystemVolume : (RCTResponseSenderBlock)callback) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - callback(@[ @(session.outputVolume) ]); -} - -RCT_EXPORT_METHOD(setPan - : (nonnull NSNumber *)key withValue - : (nonnull NSNumber *)value) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - player.pan = [value floatValue]; - } -} - -RCT_EXPORT_METHOD(setNumberOfLoops - : (nonnull NSNumber *)key withValue - : (nonnull NSNumber *)value) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - player.numberOfLoops = [value intValue]; - } -} - -RCT_EXPORT_METHOD(setSpeed - : (nonnull NSNumber *)key withValue - : (nonnull NSNumber *)value) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - player.rate = [value floatValue]; - } -} - -RCT_EXPORT_METHOD(setCurrentTime - : (nonnull NSNumber *)key withValue - : (nonnull NSNumber *)value) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - player.currentTime = [value doubleValue]; - } -} - -RCT_EXPORT_METHOD(getCurrentTime - : (nonnull NSNumber *)key withCallback - : (RCTResponseSenderBlock)callback) { - AVAudioPlayer *player = [self playerForKey:key]; - if (player) { - callback([NSArray - arrayWithObjects:[NSNumber numberWithDouble:player.currentTime], - [NSNumber numberWithBool:player.isPlaying], nil]); - } else { - callback([NSArray arrayWithObjects:[NSNumber numberWithInteger:-1], - [NSNumber numberWithBool:NO], nil]); - } -} - -RCT_EXPORT_METHOD(setSpeakerPhone : (BOOL)on) { - AVAudioSession *session = [AVAudioSession sharedInstance]; - if (on) { - [session overrideOutputAudioPort:AVAudioSessionPortOverrideSpeaker - error:nil]; - } else { - [session overrideOutputAudioPort:AVAudioSessionPortOverrideNone - error:nil]; - } - [session setActive:true error:nil]; -} - -+ (BOOL)requiresMainQueueSetup { - return YES; -} -- (void)setOnPlay:(BOOL)isPlaying forPlayerKey:(nonnull NSNumber *)playerKey { - [self - sendEventWithName:@"onPlayChange" - body:[NSDictionary - dictionaryWithObjectsAndKeys: - [NSNumber - numberWithBool:isPlaying ? YES : NO], - @"isPlaying", playerKey, @"playerKey", nil]]; -} -@end diff --git a/android/build.gradle b/android/build.gradle deleted file mode 100644 index de375bf2bb9b436330e1b093eca6d7c9f907ffbb..0000000000000000000000000000000000000000 --- a/android/build.gradle +++ /dev/null @@ -1,24 +0,0 @@ -apply plugin: 'com.android.library' - -def DEFAULT_COMPILE_SDK_VERSION = 26 -def DEFAULT_BUILD_TOOLS_VERSION = "26.0.2" -def DEFAULT_TARGET_SDK_VERSION = 26 - -android { - compileSdkVersion rootProject.hasProperty('compileSdkVersion') ? rootProject.compileSdkVersion : DEFAULT_COMPILE_SDK_VERSION - buildToolsVersion rootProject.hasProperty('buildToolsVersion') ? rootProject.buildToolsVersion : DEFAULT_BUILD_TOOLS_VERSION - - defaultConfig { - minSdkVersion 16 - targetSdkVersion rootProject.hasProperty('targetSdkVersion') ? rootProject.targetSdkVersion : DEFAULT_TARGET_SDK_VERSION - versionCode 1 - versionName "1.0" - ndk { - abiFilters "armeabi-v7a", "x86" - } - } -} - -dependencies { - compileOnly 'com.facebook.react:react-native:+' -} \ No newline at end of file diff --git a/android/src/main/AndroidManifest.xml b/android/src/main/AndroidManifest.xml deleted file mode 100644 index d961e60496496da03fc0a9178696a6c0b9f67df7..0000000000000000000000000000000000000000 --- a/android/src/main/AndroidManifest.xml +++ /dev/null @@ -1,3 +0,0 @@ - - diff --git a/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java b/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java deleted file mode 100644 index e6f51ec326a566ef23d3e69114d7ba86f1a96842..0000000000000000000000000000000000000000 --- a/android/src/main/java/com/zmxv/RNSound/RNSoundModule.java +++ /dev/null @@ -1,497 +0,0 @@ -package com.zmxv.RNSound; - -import android.content.Context; -import android.content.res.AssetFileDescriptor; -import android.media.MediaPlayer; -import android.media.MediaPlayer.OnCompletionListener; -import android.media.MediaPlayer.OnErrorListener; -import android.net.Uri; -import android.media.AudioManager; - -import com.facebook.react.bridge.Arguments; -import com.facebook.react.bridge.Callback; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.bridge.ReactContext; -import com.facebook.react.bridge.ReactContextBaseJavaModule; -import com.facebook.react.bridge.ReactMethod; -import com.facebook.react.bridge.ReadableMap; -import com.facebook.react.bridge.WritableMap; -import com.facebook.react.modules.core.DeviceEventManagerModule; -import com.facebook.react.modules.core.ExceptionsManagerModule; - -import java.io.File; -import java.util.HashMap; -import java.util.Map; -import java.io.IOException; - -import android.util.Log; - -public class RNSoundModule extends ReactContextBaseJavaModule implements AudioManager.OnAudioFocusChangeListener { - Map playerPool = new HashMap<>(); - ReactApplicationContext context; - final static Object NULL = null; - String category; - Boolean mixWithOthers = true; - Double focusedPlayerKey; - Boolean wasPlayingBeforeFocusChange = false; - - public RNSoundModule(ReactApplicationContext context) { - super(context); - this.context = context; - this.category = null; - } - - private void setOnPlay(boolean isPlaying, final Double playerKey) { - final ReactContext reactContext = this.context; - WritableMap params = Arguments.createMap(); - params.putBoolean("isPlaying", isPlaying); - params.putDouble("playerKey", playerKey); - reactContext - .getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter.class) - .emit("onPlayChange", params); - } - - @Override - public String getName() { - return "RNSound"; - } - - @ReactMethod - public void prepare(final String fileName, final Double key, final ReadableMap options, final Callback callback) { - MediaPlayer player = createMediaPlayer(fileName); - if (options.hasKey("speed") && android.os.Build.VERSION.SDK_INT >= 23) { - player.setPlaybackParams(player.getPlaybackParams().setSpeed((float)options.getDouble("speed"))); - } - if (player == null) { - WritableMap e = Arguments.createMap(); - e.putInt("code", -1); - e.putString("message", "resource not found"); - callback.invoke(e, NULL); - return; - } - this.playerPool.put(key, player); - - final RNSoundModule module = this; - - if (module.category != null) { - Integer category = null; - switch (module.category) { - case "Playback": - category = AudioManager.STREAM_MUSIC; - break; - case "Ambient": - category = AudioManager.STREAM_NOTIFICATION; - break; - case "System": - category = AudioManager.STREAM_SYSTEM; - break; - case "Voice": - category = AudioManager.STREAM_VOICE_CALL; - break; - case "Ring": - category = AudioManager.STREAM_RING; - break; - case "Alarm": - category = AudioManager.STREAM_ALARM; - break; - default: - Log.e("RNSoundModule", String.format("Unrecognised category %s", module.category)); - break; - } - if (category != null) { - player.setAudioStreamType(category); - } - } - - player.setOnPreparedListener(new MediaPlayer.OnPreparedListener() { - boolean callbackWasCalled = false; - - @Override - public synchronized void onPrepared(MediaPlayer mp) { - if (callbackWasCalled) return; - callbackWasCalled = true; - - WritableMap props = Arguments.createMap(); - props.putDouble("duration", mp.getDuration() * .001); - try { - callback.invoke(NULL, props); - } catch(RuntimeException runtimeException) { - // The callback was already invoked - Log.e("RNSoundModule", "Exception", runtimeException); - } - } - - }); - - player.setOnErrorListener(new OnErrorListener() { - boolean callbackWasCalled = false; - - @Override - public synchronized boolean onError(MediaPlayer mp, int what, int extra) { - if (callbackWasCalled) return true; - callbackWasCalled = true; - try { - WritableMap props = Arguments.createMap(); - props.putInt("what", what); - props.putInt("extra", extra); - callback.invoke(props, NULL); - } catch(RuntimeException runtimeException) { - // The callback was already invoked - Log.e("RNSoundModule", "Exception", runtimeException); - } - return true; - } - }); - - try { - if(options.hasKey("loadSync") && options.getBoolean("loadSync")) { - player.prepare(); - } else { - player.prepareAsync(); - } - } catch (Exception ignored) { - // When loading files from a file, we useMediaPlayer.create, which actually - // prepares the audio for us already. So we catch and ignore this error - Log.e("RNSoundModule", "Exception", ignored); - } - } - - protected MediaPlayer createMediaPlayer(final String fileName) { - int res = this.context.getResources().getIdentifier(fileName, "raw", this.context.getPackageName()); - MediaPlayer mediaPlayer = new MediaPlayer(); - if (res != 0) { - try { - AssetFileDescriptor afd = context.getResources().openRawResourceFd(res); - mediaPlayer.setDataSource(afd.getFileDescriptor(), afd.getStartOffset(), afd.getLength()); - afd.close(); - } catch (IOException e) { - Log.e("RNSoundModule", "Exception", e); - return null; - } - return mediaPlayer; - } - - if (fileName.startsWith("http://") || fileName.startsWith("https://")) { - mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - Log.i("RNSoundModule", fileName); - try { - mediaPlayer.setDataSource(fileName); - } catch(IOException e) { - Log.e("RNSoundModule", "Exception", e); - return null; - } - return mediaPlayer; - } - - if (fileName.startsWith("asset:/")){ - try { - AssetFileDescriptor descriptor = this.context.getAssets().openFd(fileName.replace("asset:/", "")); - mediaPlayer.setDataSource(descriptor.getFileDescriptor(), descriptor.getStartOffset(), descriptor.getLength()); - descriptor.close(); - return mediaPlayer; - } catch(IOException e) { - Log.e("RNSoundModule", "Exception", e); - return null; - } - } - - if (fileName.startsWith("file:/")){ - try { - mediaPlayer.setDataSource(fileName); - } catch(IOException e) { - Log.e("RNSoundModule", "Exception", e); - return null; - } - return mediaPlayer; - } - - File file = new File(fileName); - if (file.exists()) { - mediaPlayer.setAudioStreamType(AudioManager.STREAM_MUSIC); - Log.i("RNSoundModule", fileName); - try { - mediaPlayer.setDataSource(fileName); - } catch(IOException e) { - Log.e("RNSoundModule", "Exception", e); - return null; - } - return mediaPlayer; - } - - return null; - } - - @ReactMethod - public void play(final Double key, final Callback callback) { - MediaPlayer player = this.playerPool.get(key); - if (player == null) { - setOnPlay(false, key); - if (callback != null) { - callback.invoke(false); - } - return; - } - if (player.isPlaying()) { - return; - } - - // Request audio focus in Android system - if (!this.mixWithOthers) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - - audioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN); - - this.focusedPlayerKey = key; - } - - player.setOnCompletionListener(new OnCompletionListener() { - boolean callbackWasCalled = false; - - @Override - public synchronized void onCompletion(MediaPlayer mp) { - if (!mp.isLooping()) { - setOnPlay(false, key); - if (callbackWasCalled) return; - callbackWasCalled = true; - try { - callback.invoke(true); - } catch (Exception e) { - //Catches the exception: java.lang.RuntimeException·Illegal callback invocation from native module - } - } - } - }); - player.setOnErrorListener(new OnErrorListener() { - boolean callbackWasCalled = false; - - @Override - public synchronized boolean onError(MediaPlayer mp, int what, int extra) { - setOnPlay(false, key); - if (callbackWasCalled) return true; - callbackWasCalled = true; - try { - callback.invoke(true); - } catch (Exception e) { - //Catches the exception: java.lang.RuntimeException·Illegal callback invocation from native module - } - return true; - } - }); - player.start(); - setOnPlay(true, key); - } - - @ReactMethod - public void pause(final Double key, final Callback callback) { - MediaPlayer player = this.playerPool.get(key); - if (player != null && player.isPlaying()) { - player.pause(); - } - - if (callback != null) { - callback.invoke(); - } - } - - @ReactMethod - public void stop(final Double key, final Callback callback) { - MediaPlayer player = this.playerPool.get(key); - if (player != null && player.isPlaying()) { - player.pause(); - player.seekTo(0); - } - - // Release audio focus in Android system - if (!this.mixWithOthers && key == this.focusedPlayerKey) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - audioManager.abandonAudioFocus(this); - } - - callback.invoke(); - } - - @ReactMethod - public void reset(final Double key) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.reset(); - } - } - - @ReactMethod - public void release(final Double key) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.reset(); - player.release(); - this.playerPool.remove(key); - - // Release audio focus in Android system - if (!this.mixWithOthers && key == this.focusedPlayerKey) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - audioManager.abandonAudioFocus(this); - } - } - } - - @Override - public void onCatalystInstanceDestroy() { - java.util.Iterator it = this.playerPool.entrySet().iterator(); - while (it.hasNext()) { - Map.Entry entry = (Map.Entry)it.next(); - MediaPlayer player = (MediaPlayer)entry.getValue(); - if (player != null) { - player.reset(); - player.release(); - } - it.remove(); - } - } - - @ReactMethod - public void setVolume(final Double key, final Float left, final Float right) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.setVolume(left, right); - } - } - - @ReactMethod - public void getSystemVolume(final Callback callback) { - try { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - - callback.invoke((float) audioManager.getStreamVolume(AudioManager.STREAM_MUSIC) / audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC)); - } catch (Exception error) { - WritableMap e = Arguments.createMap(); - e.putInt("code", -1); - e.putString("message", error.getMessage()); - callback.invoke(e); - } - } - - @ReactMethod - public void setSystemVolume(final Float value) { - AudioManager audioManager = (AudioManager) context.getSystemService(Context.AUDIO_SERVICE); - - int volume = Math.round(audioManager.getStreamMaxVolume(AudioManager.STREAM_MUSIC) * value); - audioManager.setStreamVolume(AudioManager.STREAM_MUSIC, volume, 0); - } - - @ReactMethod - public void setLooping(final Double key, final Boolean looping) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.setLooping(looping); - } - } - - @ReactMethod - public void setSpeed(final Double key, final Float speed) { - if (android.os.Build.VERSION.SDK_INT < 23) { - Log.w("RNSoundModule", "setSpeed ignored due to sdk limit"); - return; - } - - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.setPlaybackParams(player.getPlaybackParams().setSpeed(speed)); - } - } - - @ReactMethod - public void setPitch(final Double key, final Float pitch) { - if (android.os.Build.VERSION.SDK_INT < 23) { - Log.w("RNSoundModule", "setPitch ignored due to sdk limit"); - return; - } - - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.setPlaybackParams(player.getPlaybackParams().setPitch(pitch)); - } - } - - @ReactMethod - public void setCurrentTime(final Double key, final Float sec) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - player.seekTo((int)Math.round(sec * 1000)); - } - } - - @ReactMethod - public void getCurrentTime(final Double key, final Callback callback) { - MediaPlayer player = this.playerPool.get(key); - if (player == null) { - callback.invoke(-1, false); - return; - } - callback.invoke(player.getCurrentPosition() * .001, player.isPlaying()); - } - - //turn speaker on - @ReactMethod - public void setSpeakerphoneOn(final Double key, final Boolean speaker) { - MediaPlayer player = this.playerPool.get(key); - if (player != null) { - AudioManager audioManager = (AudioManager)this.context.getSystemService(this.context.AUDIO_SERVICE); - if(speaker){ - audioManager.setMode(AudioManager.MODE_IN_COMMUNICATION); - }else{ - audioManager.setMode(AudioManager.MODE_NORMAL); - } - audioManager.setSpeakerphoneOn(speaker); - } - } - - @ReactMethod - public void setCategory(final String category, final Boolean mixWithOthers) { - this.category = category; - this.mixWithOthers = mixWithOthers; - } - - @Override - public void onAudioFocusChange(int focusChange) { - if (!this.mixWithOthers) { - MediaPlayer player = this.playerPool.get(this.focusedPlayerKey); - - if (player != null) { - if (focusChange <= 0) { - this.wasPlayingBeforeFocusChange = player.isPlaying(); - - if (this.wasPlayingBeforeFocusChange) { - this.pause(this.focusedPlayerKey, null); - } - } else { - if (this.wasPlayingBeforeFocusChange) { - this.play(this.focusedPlayerKey, null); - this.wasPlayingBeforeFocusChange = false; - } - } - } - } - } - - @ReactMethod - public void enable(final Boolean enabled) { - // no op - } - - @Override - public Map getConstants() { - final Map constants = new HashMap<>(); - constants.put("IsAndroid", true); - return constants; - } - - @ReactMethod - public void addListener(String eventName) { - // Keep: Required for RN built in Event Emitter Calls. - } - - @ReactMethod - public void removeListeners(Integer count) { - // Keep: Required for RN built in Event Emitter Calls. - } -} diff --git a/android/src/main/java/com/zmxv/RNSound/RNSoundPackage.java b/android/src/main/java/com/zmxv/RNSound/RNSoundPackage.java deleted file mode 100644 index f9e878f6dc6bb42ef7b7283ff3a4808f5cb35947..0000000000000000000000000000000000000000 --- a/android/src/main/java/com/zmxv/RNSound/RNSoundPackage.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.zmxv.RNSound; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import com.facebook.react.ReactPackage; -import com.facebook.react.bridge.NativeModule; -import com.facebook.react.bridge.JavaScriptModule; -import com.facebook.react.bridge.ReactApplicationContext; -import com.facebook.react.uimanager.ViewManager; - -public class RNSoundPackage implements ReactPackage { - - @Override - public List createNativeModules (ReactApplicationContext context) { - List modules = new ArrayList<>(); - modules.add(new RNSoundModule(context)); - return modules; - } - - // Deprecated RN 0.47 - // @Override - public List> createJSModules() { - return Collections.emptyList(); - } - - @Override - public List createViewManagers(ReactApplicationContext context) { - return Collections.emptyList(); - } -}