react-native-audio-api 0.10.0-nightly-e16d7ff-20251030 → 0.11.0-alpha.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/RNAudioAPI.podspec +11 -16
- package/android/build.gradle +3 -33
- package/android/src/main/cpp/audioapi/CMakeLists.txt +0 -6
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.cpp +0 -5
- package/android/src/main/cpp/audioapi/android/AudioAPIModule.h +0 -1
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.cpp +142 -28
- package/android/src/main/cpp/audioapi/android/core/AndroidAudioRecorder.h +40 -13
- package/android/src/main/cpp/audioapi/android/core/AudioPlayer.cpp +2 -4
- package/android/src/main/cpp/audioapi/android/core/NativeAudioRecorder.hpp +9 -9
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidFileWriterBackend.h +37 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.cpp +187 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AndroidRecorderCallback.h +57 -0
- package/android/src/main/cpp/audioapi/android/core/utils/AudioDecoder.cpp +0 -6
- package/android/src/main/cpp/audioapi/android/core/utils/FileUtils.h +34 -0
- package/android/src/main/cpp/audioapi/android/core/utils/FileUtilts.cpp +133 -0
- package/android/src/main/cpp/audioapi/android/core/utils/MiniaudioImplementation.cpp +3 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.cpp +154 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegAudioFileOptions.h +41 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.cpp +429 -0
- package/android/src/main/cpp/audioapi/android/core/utils/ffmpegBackend/FFmpegFileWriter.h +113 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.cpp +47 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h +28 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp +269 -0
- package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h +47 -0
- package/android/src/main/cpp/audioapi/android/system/NativeFileInfo.hpp +31 -0
- package/android/src/main/java/com/swmansion/audioapi/AudioAPIModule.kt +3 -29
- package/android/src/main/java/com/swmansion/audioapi/system/AudioFocusListener.kt +9 -21
- package/android/src/main/java/com/swmansion/audioapi/system/LockScreenManager.kt +6 -27
- package/android/src/main/java/com/swmansion/audioapi/system/MediaNotificationManager.kt +0 -11
- package/android/src/main/java/com/swmansion/audioapi/system/NativeFileInfo.kt +18 -0
- package/android/src/main/jniLibs/arm64-v8a/libavcodec.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libavformat.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libavutil.so +0 -0
- package/android/src/main/jniLibs/arm64-v8a/libswresample.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavcodec.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavformat.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libavutil.so +0 -0
- package/android/src/main/jniLibs/armeabi-v7a/libswresample.so +0 -0
- package/android/src/main/jniLibs/x86/libavcodec.so +0 -0
- package/android/src/main/jniLibs/x86/libavformat.so +0 -0
- package/android/src/main/jniLibs/x86/libavutil.so +0 -0
- package/android/src/main/jniLibs/x86/libswresample.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavcodec.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavformat.so +0 -0
- package/android/src/main/jniLibs/x86_64/libavutil.so +0 -0
- package/android/src/main/jniLibs/x86_64/libswresample.so +0 -0
- package/common/cpp/audioapi/AudioAPIModuleInstaller.h +2 -30
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.cpp +0 -18
- package/common/cpp/audioapi/HostObjects/BaseAudioContextHostObject.h +0 -1
- package/common/cpp/audioapi/HostObjects/effects/BiquadFilterNodeHostObject.cpp +1 -1
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.cpp +97 -18
- package/common/cpp/audioapi/HostObjects/inputs/AudioRecorderHostObject.h +18 -6
- package/common/cpp/audioapi/core/AudioNode.h +2 -3
- package/common/cpp/audioapi/core/AudioParam.cpp +2 -2
- package/common/cpp/audioapi/core/BaseAudioContext.cpp +0 -10
- package/common/cpp/audioapi/core/BaseAudioContext.h +0 -2
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.cpp +32 -69
- package/common/cpp/audioapi/core/effects/BiquadFilterNode.h +1 -37
- package/common/cpp/audioapi/core/inputs/AudioRecorder.cpp +36 -82
- package/common/cpp/audioapi/core/inputs/AudioRecorder.h +52 -31
- package/common/cpp/audioapi/core/sources/StreamerNode.cpp +58 -59
- package/common/cpp/audioapi/core/sources/StreamerNode.h +8 -37
- package/common/cpp/audioapi/core/utils/AudioNodeManager.cpp +0 -5
- package/common/cpp/audioapi/core/utils/Constants.h +1 -2
- package/common/cpp/audioapi/core/utils/worklets/SafeIncludes.h +10 -0
- package/common/cpp/audioapi/dsp/AudioUtils.cpp +1 -1
- package/common/cpp/audioapi/dsp/FFT.cpp +26 -0
- package/common/cpp/audioapi/dsp/FFT.h +2 -26
- package/common/cpp/audioapi/external/arm64-v8a/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libogg.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libopus.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libssl.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/arm64-v8a/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libogg.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libopus.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libssl.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/armeabi-v7a/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/avcodec.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_desc.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_id.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavcodec/codec_par.h +1 -1
- package/common/cpp/audioapi/external/ffmpeg_include/libavformat/avformat.h +2 -2
- package/common/cpp/audioapi/external/ffmpeg_include/libavutil/avutil.h +2 -2
- package/common/cpp/audioapi/external/iphoneos/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libogg.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libopus.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libssl.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/iphoneos/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libogg.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libopus.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libssl.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/iphonesimulator/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/Info.plist +44 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavcodec.xcframework/ios-arm64_x86_64-simulator/libavcodec.framework/libavcodec +0 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/Info.plist +44 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavformat.xcframework/ios-arm64_x86_64-simulator/libavformat.framework/libavformat +0 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/Info.plist +44 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libavutil.xcframework/ios-arm64_x86_64-simulator/libavutil.framework/libavutil +0 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/Info.plist +44 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/Info.plist +1 -0
- package/common/cpp/audioapi/external/libswresample.xcframework/ios-arm64_x86_64-simulator/libswresample.framework/libswresample +0 -0
- package/common/cpp/audioapi/external/x86/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/x86/libogg.a +0 -0
- package/common/cpp/audioapi/external/x86/libopus.a +0 -0
- package/common/cpp/audioapi/external/x86/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/x86/libssl.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/x86/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libcrypto.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libogg.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libopus.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libopusfile.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libssl.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbis.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbisenc.a +0 -0
- package/common/cpp/audioapi/external/x86_64/libvorbisfile.a +0 -0
- package/common/cpp/audioapi/libs/ffmpeg/FFmpegDecoding.cpp +3 -2
- package/common/cpp/audioapi/libs/ffmpeg/INSTRUCTIONS.md +32 -0
- package/common/cpp/audioapi/libs/ffmpeg/create_xcframework.sh +111 -0
- package/common/cpp/audioapi/libs/ffmpeg/ffmpeg_setup.sh +391 -0
- package/common/cpp/audioapi/utils/AudioBus.cpp +0 -28
- package/common/cpp/audioapi/utils/AudioBus.h +0 -3
- package/common/cpp/audioapi/utils/ThreadPool.hpp +1 -59
- package/common/cpp/test/CMakeLists.txt +14 -19
- package/ios/audioapi/ios/AudioAPIModule.h +1 -2
- package/ios/audioapi/ios/AudioAPIModule.mm +0 -2
- package/ios/audioapi/ios/core/IOSAudioFileOptions.h +36 -0
- package/ios/audioapi/ios/core/IOSAudioFileOptions.mm +140 -0
- package/ios/audioapi/ios/core/IOSAudioFileWriter.h +51 -0
- package/ios/audioapi/ios/core/IOSAudioFileWriter.mm +223 -0
- package/ios/audioapi/ios/core/IOSAudioRecorder.h +28 -10
- package/ios/audioapi/ios/core/IOSAudioRecorder.mm +117 -30
- package/ios/audioapi/ios/core/IOSRecorderCallback.h +57 -0
- package/ios/audioapi/ios/core/IOSRecorderCallback.mm +189 -0
- package/ios/audioapi/ios/core/NativeAudioRecorder.h +4 -9
- package/ios/audioapi/ios/core/NativeAudioRecorder.m +29 -71
- package/ios/audioapi/ios/core/utils/AudioDecoder.mm +1 -0
- package/ios/audioapi/ios/system/AudioEngine.mm +3 -3
- package/ios/audioapi/ios/system/AudioSessionManager.mm +0 -9
- package/ios/audioapi/ios/system/LockScreenManager.h +1 -0
- package/ios/audioapi/ios/system/LockScreenManager.mm +19 -6
- package/lib/commonjs/api.js +76 -141
- package/lib/commonjs/api.js.map +1 -1
- package/lib/commonjs/api.web.js +0 -8
- package/lib/commonjs/api.web.js.map +1 -1
- package/lib/commonjs/core/AudioContext.js +1 -1
- package/lib/commonjs/core/AudioContext.js.map +1 -1
- package/lib/commonjs/core/AudioRecorder.js +171 -13
- package/lib/commonjs/core/AudioRecorder.js.map +1 -1
- package/lib/commonjs/core/BaseAudioContext.js +25 -28
- package/lib/commonjs/core/BaseAudioContext.js.map +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js +1 -1
- package/lib/commonjs/core/OfflineAudioContext.js.map +1 -1
- package/lib/commonjs/types.js +46 -0
- package/lib/commonjs/types.js.map +1 -1
- package/lib/commonjs/utils/bitEnums.js +33 -0
- package/lib/commonjs/utils/bitEnums.js.map +1 -0
- package/lib/commonjs/utils/index.js +21 -19
- package/lib/commonjs/utils/index.js.map +1 -1
- package/lib/commonjs/web-core/AudioContext.js +0 -12
- package/lib/commonjs/web-core/AudioContext.js.map +1 -1
- package/lib/commonjs/web-core/OfflineAudioContext.js +0 -12
- package/lib/commonjs/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/module/api.js +15 -16
- package/lib/module/api.js.map +1 -1
- package/lib/module/api.web.js +0 -1
- package/lib/module/api.web.js.map +1 -1
- package/lib/module/core/AudioContext.js +2 -2
- package/lib/module/core/AudioContext.js.map +1 -1
- package/lib/module/core/AudioRecorder.js +171 -13
- package/lib/module/core/AudioRecorder.js.map +1 -1
- package/lib/module/core/BaseAudioContext.js +26 -29
- package/lib/module/core/BaseAudioContext.js.map +1 -1
- package/lib/module/core/OfflineAudioContext.js +2 -2
- package/lib/module/core/OfflineAudioContext.js.map +1 -1
- package/lib/module/types.js +45 -1
- package/lib/module/types.js.map +1 -1
- package/lib/module/utils/bitEnums.js +27 -0
- package/lib/module/utils/bitEnums.js.map +1 -0
- package/lib/module/utils/index.js +2 -15
- package/lib/module/utils/index.js.map +1 -1
- package/lib/module/web-core/AudioContext.js +0 -12
- package/lib/module/web-core/AudioContext.js.map +1 -1
- package/lib/module/web-core/OfflineAudioContext.js +0 -12
- package/lib/module/web-core/OfflineAudioContext.js.map +1 -1
- package/lib/typescript/api.d.ts +17 -19
- package/lib/typescript/api.d.ts.map +1 -1
- package/lib/typescript/api.web.d.ts +0 -1
- package/lib/typescript/api.web.d.ts.map +1 -1
- package/lib/typescript/core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/core/AudioRecorder.d.ts +62 -7
- package/lib/typescript/core/AudioRecorder.d.ts.map +1 -1
- package/lib/typescript/core/BaseAudioContext.d.ts +1 -3
- package/lib/typescript/core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/events/types.d.ts +16 -0
- package/lib/typescript/events/types.d.ts.map +1 -1
- package/lib/typescript/interfaces.d.ts +42 -9
- package/lib/typescript/interfaces.d.ts.map +1 -1
- package/lib/typescript/types.d.ts +79 -8
- package/lib/typescript/types.d.ts.map +1 -1
- package/lib/typescript/utils/bitEnums.d.ts +4 -0
- package/lib/typescript/utils/bitEnums.d.ts.map +1 -0
- package/lib/typescript/utils/index.d.ts +2 -5
- package/lib/typescript/utils/index.d.ts.map +1 -1
- package/lib/typescript/web-core/AudioContext.d.ts +0 -3
- package/lib/typescript/web-core/AudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/BaseAudioContext.d.ts +0 -2
- package/lib/typescript/web-core/BaseAudioContext.d.ts.map +1 -1
- package/lib/typescript/web-core/OfflineAudioContext.d.ts +0 -3
- package/lib/typescript/web-core/OfflineAudioContext.d.ts.map +1 -1
- package/package.json +4 -7
- package/src/api.ts +18 -45
- package/src/api.web.ts +0 -1
- package/src/core/AudioContext.ts +2 -3
- package/src/core/AudioRecorder.ts +211 -24
- package/src/core/BaseAudioContext.ts +60 -67
- package/src/core/OfflineAudioContext.ts +2 -2
- package/src/events/types.ts +18 -0
- package/src/interfaces.ts +52 -16
- package/src/types.ts +90 -9
- package/src/utils/bitEnums.ts +51 -0
- package/src/utils/index.ts +2 -22
- package/src/web-core/AudioContext.tsx +0 -25
- package/src/web-core/BaseAudioContext.tsx +0 -2
- package/src/web-core/OfflineAudioContext.tsx +0 -25
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.cpp +0 -47
- package/common/cpp/audioapi/HostObjects/effects/ConvolverNodeHostObject.h +0 -20
- package/common/cpp/audioapi/core/effects/ConvolverNode.cpp +0 -210
- package/common/cpp/audioapi/core/effects/ConvolverNode.h +0 -55
- package/common/cpp/audioapi/dsp/Convolver.cpp +0 -213
- package/common/cpp/audioapi/dsp/Convolver.h +0 -45
- package/common/cpp/audioapi/libs/ffmpeg/relinking.md +0 -24
- package/common/cpp/audioapi/utils/AlignedAllocator.hpp +0 -50
- package/common/cpp/test/src/biquad/BiquadFilterChromium.cpp +0 -389
- package/common/cpp/test/src/biquad/BiquadFilterChromium.h +0 -64
- package/common/cpp/test/src/biquad/BiquadFilterTest.cpp +0 -284
- package/common/cpp/test/src/biquad/BiquadFilterTest.h +0 -40
- package/lib/commonjs/core/ConvolverNode.js +0 -37
- package/lib/commonjs/core/ConvolverNode.js.map +0 -1
- package/lib/commonjs/web-core/ConvolverNode.js +0 -40
- package/lib/commonjs/web-core/ConvolverNode.js.map +0 -1
- package/lib/commonjs/web-core/ConvolverNodeOptions.js +0 -6
- package/lib/commonjs/web-core/ConvolverNodeOptions.js.map +0 -1
- package/lib/module/core/ConvolverNode.js +0 -31
- package/lib/module/core/ConvolverNode.js.map +0 -1
- package/lib/module/web-core/ConvolverNode.js +0 -34
- package/lib/module/web-core/ConvolverNode.js.map +0 -1
- package/lib/module/web-core/ConvolverNodeOptions.js +0 -4
- package/lib/module/web-core/ConvolverNodeOptions.js.map +0 -1
- package/lib/typescript/core/ConvolverNode.d.ts +0 -12
- package/lib/typescript/core/ConvolverNode.d.ts.map +0 -1
- package/lib/typescript/web-core/ConvolverNode.d.ts +0 -11
- package/lib/typescript/web-core/ConvolverNode.d.ts.map +0 -1
- package/lib/typescript/web-core/ConvolverNodeOptions.d.ts +0 -6
- package/lib/typescript/web-core/ConvolverNodeOptions.d.ts.map +0 -1
- package/scripts/download-prebuilt-binaries.sh +0 -52
- package/scripts/rnaa_utils.rb +0 -8
- package/scripts/validate-worklets-version.js +0 -28
- package/src/core/ConvolverNode.ts +0 -35
- package/src/web-core/ConvolverNode.tsx +0 -43
- package/src/web-core/ConvolverNodeOptions.tsx +0 -6
package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.cpp
ADDED
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
#include <android/log.h>
|
|
2
|
+
#include <audioapi/android/core/utils/AndroidFileWriterBackend.h>
|
|
3
|
+
#include <audioapi/android/core/utils/miniaudioBackend/MiniAudioFileOptions.h>
|
|
4
|
+
#include <audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h>
|
|
5
|
+
#include <audioapi/libs/miniaudio/miniaudio.h>
|
|
6
|
+
|
|
7
|
+
constexpr double BYTES_TO_MB = 1024.0 * 1024.0;
|
|
8
|
+
|
|
9
|
+
namespace audioapi {
|
|
10
|
+
|
|
11
|
+
MiniAudioFileWriter::MiniAudioFileWriter(
|
|
12
|
+
float sampleRate,
|
|
13
|
+
size_t channelCount,
|
|
14
|
+
size_t bitRate,
|
|
15
|
+
size_t androidFlags)
|
|
16
|
+
: AndroidFileWriterBackend(
|
|
17
|
+
sampleRate,
|
|
18
|
+
channelCount,
|
|
19
|
+
bitRate,
|
|
20
|
+
androidFlags) {
|
|
21
|
+
fileOptions_ = std::make_shared<MiniAudioFileOptions>(
|
|
22
|
+
sampleRate, channelCount, bitRate, androidFlags);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
MiniAudioFileWriter::~MiniAudioFileWriter() {
|
|
26
|
+
isFileOpen_.store(false);
|
|
27
|
+
fileOptions_.reset();
|
|
28
|
+
|
|
29
|
+
if (encoder_ != nullptr) {
|
|
30
|
+
ma_encoder_uninit(encoder_.get());
|
|
31
|
+
encoder_.reset();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (converter_ != nullptr) {
|
|
35
|
+
ma_data_converter_uninit(converter_.get(), NULL);
|
|
36
|
+
converter_.reset();
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (processingBuffer_ != nullptr) {
|
|
40
|
+
ma_free(processingBuffer_, NULL);
|
|
41
|
+
processingBuffer_ = nullptr;
|
|
42
|
+
processingBufferLength_ = 0;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
std::string MiniAudioFileWriter::openFile(
|
|
47
|
+
int32_t streamSampleRate,
|
|
48
|
+
int32_t streamChannelCount,
|
|
49
|
+
int32_t streamMaxBufferSize) {
|
|
50
|
+
streamSampleRate_ = streamSampleRate;
|
|
51
|
+
streamChannelCount_ = streamChannelCount;
|
|
52
|
+
streamMaxBufferSize_ = streamMaxBufferSize;
|
|
53
|
+
bool success = false;
|
|
54
|
+
|
|
55
|
+
isConverterRequired_.store(
|
|
56
|
+
(streamSampleRate_ != fileOptions_->getSampleRate()) ||
|
|
57
|
+
(streamChannelCount_ != fileOptions_->getChannelCount()) ||
|
|
58
|
+
(fileOptions_->getDataFormat() != ma_format_f32));
|
|
59
|
+
|
|
60
|
+
success = initializeConverterIfNeeded();
|
|
61
|
+
|
|
62
|
+
if (!success) {
|
|
63
|
+
return "";
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
success = initializeEncoder();
|
|
67
|
+
|
|
68
|
+
if (!success) {
|
|
69
|
+
return "";
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
isFileOpen_.store(true);
|
|
73
|
+
|
|
74
|
+
return filePath_;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
std::tuple<double, double> MiniAudioFileWriter::closeFile() {
|
|
78
|
+
if (!isFileOpen()) {
|
|
79
|
+
return {0.0, 0.0};
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
isFileOpen_.store(false);
|
|
83
|
+
|
|
84
|
+
if (encoder_ != nullptr) {
|
|
85
|
+
ma_encoder_uninit(encoder_.get());
|
|
86
|
+
encoder_.reset();
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
if (converter_ != nullptr) {
|
|
90
|
+
ma_data_converter_uninit(converter_.get(), NULL);
|
|
91
|
+
converter_.reset();
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
if (processingBuffer_ != nullptr) {
|
|
95
|
+
ma_free(processingBuffer_, NULL);
|
|
96
|
+
processingBuffer_ = nullptr;
|
|
97
|
+
processingBufferLength_ = 0;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
// Retrieve duration and file size
|
|
101
|
+
std::string filePath = filePath_;
|
|
102
|
+
double durationInSeconds = 0.0;
|
|
103
|
+
double fileSizeInMB = 0.0;
|
|
104
|
+
|
|
105
|
+
ma_decoder decoder;
|
|
106
|
+
|
|
107
|
+
if (ma_decoder_init_file(filePath_.c_str(), NULL, &decoder) == MA_SUCCESS) {
|
|
108
|
+
ma_uint64 frameCount = 0;
|
|
109
|
+
|
|
110
|
+
if (ma_decoder_get_length_in_pcm_frames(&decoder, &frameCount) ==
|
|
111
|
+
MA_SUCCESS) {
|
|
112
|
+
durationInSeconds =
|
|
113
|
+
static_cast<double>(frameCount) / decoder.outputSampleRate;
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
ma_decoder_uninit(&decoder);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
FILE *file = fopen(filePath_.c_str(), "rb");
|
|
120
|
+
|
|
121
|
+
if (file != nullptr) {
|
|
122
|
+
fseek(file, 0, SEEK_END);
|
|
123
|
+
long fileSizeInBytes = ftell(file);
|
|
124
|
+
fclose(file);
|
|
125
|
+
fileSizeInMB = static_cast<double>(fileSizeInBytes) / BYTES_TO_MB;
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
filePath_ = "";
|
|
129
|
+
return {fileSizeInMB, durationInSeconds};
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
bool MiniAudioFileWriter::writeAudioData(void *data, int numFrames) {
|
|
133
|
+
ma_uint64 framesWritten = 0;
|
|
134
|
+
ma_result result;
|
|
135
|
+
|
|
136
|
+
if (!isFileOpen()) {
|
|
137
|
+
return false;
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
if (!isConverterRequired()) {
|
|
141
|
+
result = ma_encoder_write_pcm_frames(
|
|
142
|
+
encoder_.get(), data, numFrames, &framesWritten);
|
|
143
|
+
|
|
144
|
+
__android_log_print(
|
|
145
|
+
ANDROID_LOG_DEBUG,
|
|
146
|
+
"MiniAudioFileWriter",
|
|
147
|
+
"Writing %llu frames without conversion to file: %s",
|
|
148
|
+
framesWritten,
|
|
149
|
+
filePath_.c_str());
|
|
150
|
+
|
|
151
|
+
if (result != MA_SUCCESS) {
|
|
152
|
+
__android_log_print(
|
|
153
|
+
ANDROID_LOG_ERROR,
|
|
154
|
+
"MiniAudioFileWriter",
|
|
155
|
+
"Failed to write audio data to file: %s",
|
|
156
|
+
filePath_.c_str());
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
framesWritten_.fetch_add(numFrames);
|
|
160
|
+
return result == MA_SUCCESS;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
ma_uint64 convertedFrameCount = convertBuffer(data, numFrames);
|
|
164
|
+
|
|
165
|
+
result = ma_encoder_write_pcm_frames(
|
|
166
|
+
encoder_.get(), processingBuffer_, convertedFrameCount, &framesWritten);
|
|
167
|
+
|
|
168
|
+
if (result != MA_SUCCESS) {
|
|
169
|
+
__android_log_print(
|
|
170
|
+
ANDROID_LOG_ERROR,
|
|
171
|
+
"MiniAudioFileWriter",
|
|
172
|
+
"Failed to write converted audio data to file: %s",
|
|
173
|
+
filePath_.c_str());
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
framesWritten_.fetch_add(numFrames);
|
|
177
|
+
return result == MA_SUCCESS;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
ma_uint64 MiniAudioFileWriter::convertBuffer(void *data, int numFrames) {
|
|
181
|
+
ma_uint64 inputFrameCount = numFrames;
|
|
182
|
+
ma_uint64 outputFrameCount = 0;
|
|
183
|
+
|
|
184
|
+
ma_data_converter_get_expected_output_frame_count(
|
|
185
|
+
converter_.get(), inputFrameCount, &outputFrameCount);
|
|
186
|
+
|
|
187
|
+
ma_data_converter_process_pcm_frames(
|
|
188
|
+
converter_.get(),
|
|
189
|
+
data,
|
|
190
|
+
&inputFrameCount,
|
|
191
|
+
processingBuffer_,
|
|
192
|
+
&outputFrameCount);
|
|
193
|
+
|
|
194
|
+
return outputFrameCount;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
bool MiniAudioFileWriter::initializeConverterIfNeeded() {
|
|
198
|
+
if (!isConverterRequired_) {
|
|
199
|
+
return true;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
ma_result result;
|
|
203
|
+
|
|
204
|
+
ma_data_converter_config converterConfig = ma_data_converter_config_init(
|
|
205
|
+
ma_format_f32,
|
|
206
|
+
fileOptions_->getDataFormat(),
|
|
207
|
+
streamChannelCount_,
|
|
208
|
+
fileOptions_->getChannelCount(),
|
|
209
|
+
streamSampleRate_,
|
|
210
|
+
fileOptions_->getSampleRate());
|
|
211
|
+
|
|
212
|
+
converter_ = std::make_unique<ma_data_converter>();
|
|
213
|
+
result = ma_data_converter_init(&converterConfig, NULL, converter_.get());
|
|
214
|
+
|
|
215
|
+
if (result != MA_SUCCESS) {
|
|
216
|
+
__android_log_print(
|
|
217
|
+
ANDROID_LOG_ERROR,
|
|
218
|
+
"MiniAudioFileWriter",
|
|
219
|
+
"Failed to initialize miniaudio data converter for file: %s",
|
|
220
|
+
filePath_.c_str());
|
|
221
|
+
return false;
|
|
222
|
+
}
|
|
223
|
+
|
|
224
|
+
ma_data_converter_get_expected_output_frame_count(
|
|
225
|
+
converter_.get(), streamMaxBufferSize_, &processingBufferLength_);
|
|
226
|
+
|
|
227
|
+
processingBuffer_ = ma_malloc(
|
|
228
|
+
processingBufferLength_ * fileOptions_->getChannelCount() *
|
|
229
|
+
ma_get_bytes_per_sample(fileOptions_->getDataFormat()),
|
|
230
|
+
NULL);
|
|
231
|
+
|
|
232
|
+
return true;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
bool MiniAudioFileWriter::initializeEncoder() {
|
|
236
|
+
filePath_ = fileOptions_->getFilePath("audio");
|
|
237
|
+
|
|
238
|
+
ma_result result;
|
|
239
|
+
|
|
240
|
+
ma_encoder_config config = ma_encoder_config_init(
|
|
241
|
+
fileOptions_->getFormat(),
|
|
242
|
+
fileOptions_->getDataFormat(),
|
|
243
|
+
fileOptions_->getChannelCount(),
|
|
244
|
+
fileOptions_->getSampleRate());
|
|
245
|
+
|
|
246
|
+
encoder_ = std::make_unique<ma_encoder>();
|
|
247
|
+
result = ma_encoder_init_file(filePath_.c_str(), &config, encoder_.get());
|
|
248
|
+
|
|
249
|
+
if (result != MA_SUCCESS) {
|
|
250
|
+
__android_log_print(
|
|
251
|
+
ANDROID_LOG_ERROR,
|
|
252
|
+
"MiniAudioFileWriter",
|
|
253
|
+
"Failed to initialize miniaudio encoder for file: %s",
|
|
254
|
+
filePath_.c_str());
|
|
255
|
+
return false;
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
return true;
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
bool MiniAudioFileWriter::isFileOpen() {
|
|
262
|
+
return isFileOpen_.load();
|
|
263
|
+
}
|
|
264
|
+
|
|
265
|
+
bool MiniAudioFileWriter::isConverterRequired() {
|
|
266
|
+
return isConverterRequired_.load();
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
} // namespace audioapi
|
package/android/src/main/cpp/audioapi/android/core/utils/miniaudioBackend/MiniAudioFileWriter.h
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <audioapi/android/core/utils/AndroidFileWriterBackend.h>
|
|
4
|
+
#include <audioapi/libs/miniaudio/miniaudio.h>
|
|
5
|
+
|
|
6
|
+
#include <string>
|
|
7
|
+
#include <memory>
|
|
8
|
+
#include <tuple>
|
|
9
|
+
|
|
10
|
+
namespace audioapi {
|
|
11
|
+
|
|
12
|
+
class MiniAudioFileOptions;
|
|
13
|
+
|
|
14
|
+
class MiniAudioFileWriter : public AndroidFileWriterBackend {
|
|
15
|
+
public:
|
|
16
|
+
MiniAudioFileWriter(
|
|
17
|
+
float sampleRate,
|
|
18
|
+
size_t channelCount,
|
|
19
|
+
size_t bitRate,
|
|
20
|
+
size_t androidFlags);
|
|
21
|
+
~MiniAudioFileWriter() override;
|
|
22
|
+
|
|
23
|
+
std::string openFile(int32_t streamSampleRate, int32_t streamChannelCount, int32_t streamMaxBufferSize) override;
|
|
24
|
+
std::tuple<double, double> closeFile() override;
|
|
25
|
+
|
|
26
|
+
bool writeAudioData(void *data, int numFrames) override;
|
|
27
|
+
|
|
28
|
+
private:
|
|
29
|
+
std::shared_ptr<MiniAudioFileOptions> fileOptions_;
|
|
30
|
+
|
|
31
|
+
std::atomic<bool> isFileOpen_{false};
|
|
32
|
+
std::atomic<bool> isConverterRequired_{false};
|
|
33
|
+
|
|
34
|
+
std::unique_ptr<ma_encoder> encoder_{nullptr};
|
|
35
|
+
std::unique_ptr<ma_data_converter> converter_{nullptr};
|
|
36
|
+
void *processingBuffer_{nullptr};
|
|
37
|
+
ma_uint64 processingBufferLength_{0};
|
|
38
|
+
|
|
39
|
+
bool initializeConverterIfNeeded();
|
|
40
|
+
bool initializeEncoder();
|
|
41
|
+
ma_uint64 convertBuffer(void *data, int numFrames);
|
|
42
|
+
|
|
43
|
+
bool isFileOpen();
|
|
44
|
+
bool isConverterRequired();
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
} // namespace audioapi
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
#pragma once
|
|
2
|
+
|
|
3
|
+
#include <fbjni/fbjni.h>
|
|
4
|
+
#include <react/jni/CxxModuleWrapper.h>
|
|
5
|
+
#include <react/jni/JMessageQueueThread.h>
|
|
6
|
+
#include <memory>
|
|
7
|
+
#include <utility>
|
|
8
|
+
#include <unordered_map>
|
|
9
|
+
|
|
10
|
+
namespace audioapi {
|
|
11
|
+
|
|
12
|
+
using namespace facebook;
|
|
13
|
+
using namespace react;
|
|
14
|
+
|
|
15
|
+
class NativeFileInfo : public jni::JavaClass<NativeFileInfo> {
|
|
16
|
+
public:
|
|
17
|
+
static auto constexpr kJavaDescriptor =
|
|
18
|
+
"Lcom/swmansion/audioapi/system/NativeFileInfo;";
|
|
19
|
+
|
|
20
|
+
static std::string getFilesDir() {
|
|
21
|
+
static const auto method = javaClassStatic()->getStaticMethod<jni::JString()>("getFilesDir");
|
|
22
|
+
return method(javaClassStatic())->toStdString();
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static std::string getCacheDir() {
|
|
26
|
+
static const auto method = javaClassStatic()->getStaticMethod<jni::JString()>("getCacheDir");
|
|
27
|
+
return method(javaClassStatic())->toStdString();
|
|
28
|
+
}
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
}
|
|
@@ -1,8 +1,6 @@
|
|
|
1
1
|
package com.swmansion.audioapi
|
|
2
2
|
|
|
3
3
|
import com.facebook.jni.HybridData
|
|
4
|
-
import com.facebook.react.bridge.LifecycleEventListener
|
|
5
|
-
import com.facebook.react.bridge.NativeModule
|
|
6
4
|
import com.facebook.react.bridge.Promise
|
|
7
5
|
import com.facebook.react.bridge.ReactApplicationContext
|
|
8
6
|
import com.facebook.react.bridge.ReadableArray
|
|
@@ -11,6 +9,7 @@ import com.facebook.react.common.annotations.FrameworkAPI
|
|
|
11
9
|
import com.facebook.react.module.annotations.ReactModule
|
|
12
10
|
import com.facebook.react.turbomodule.core.CallInvokerHolderImpl
|
|
13
11
|
import com.swmansion.audioapi.system.MediaSessionManager
|
|
12
|
+
import com.swmansion.audioapi.system.NativeFileInfo
|
|
14
13
|
import com.swmansion.audioapi.system.PermissionRequestListener
|
|
15
14
|
import java.lang.ref.WeakReference
|
|
16
15
|
|
|
@@ -18,8 +17,7 @@ import java.lang.ref.WeakReference
|
|
|
18
17
|
@ReactModule(name = AudioAPIModule.NAME)
|
|
19
18
|
class AudioAPIModule(
|
|
20
19
|
reactContext: ReactApplicationContext,
|
|
21
|
-
) : NativeAudioAPIModuleSpec(reactContext)
|
|
22
|
-
LifecycleEventListener {
|
|
20
|
+
) : NativeAudioAPIModuleSpec(reactContext) {
|
|
23
21
|
companion object {
|
|
24
22
|
const val NAME = NativeAudioAPIModuleSpec.NAME
|
|
25
23
|
}
|
|
@@ -27,7 +25,6 @@ class AudioAPIModule(
|
|
|
27
25
|
val reactContext: WeakReference<ReactApplicationContext> = WeakReference(reactContext)
|
|
28
26
|
|
|
29
27
|
private val mHybridData: HybridData
|
|
30
|
-
private var reanimatedModule: NativeModule? = null
|
|
31
28
|
|
|
32
29
|
external fun initHybrid(
|
|
33
30
|
workletsModule: Any?,
|
|
@@ -42,8 +39,6 @@ class AudioAPIModule(
|
|
|
42
39
|
eventBody: Map<String, Any>,
|
|
43
40
|
)
|
|
44
41
|
|
|
45
|
-
private external fun closeAllContexts()
|
|
46
|
-
|
|
47
42
|
init {
|
|
48
43
|
try {
|
|
49
44
|
System.loadLibrary("react-native-audio-api")
|
|
@@ -65,33 +60,12 @@ class AudioAPIModule(
|
|
|
65
60
|
|
|
66
61
|
override fun install(): Boolean {
|
|
67
62
|
MediaSessionManager.initialize(WeakReference(this), reactContext)
|
|
63
|
+
NativeFileInfo.initialize(reactContext)
|
|
68
64
|
injectJSIBindings()
|
|
69
65
|
|
|
70
66
|
return true
|
|
71
67
|
}
|
|
72
68
|
|
|
73
|
-
override fun onHostResume() {
|
|
74
|
-
// do nothing
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
override fun onHostPause() {
|
|
78
|
-
// do nothing
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
override fun onHostDestroy() {
|
|
82
|
-
closeAllContexts()
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
override fun initialize() {
|
|
86
|
-
reactContext.get()?.addLifecycleEventListener(this)
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
override fun invalidate() {
|
|
90
|
-
closeAllContexts()
|
|
91
|
-
reactContext.get()?.removeLifecycleEventListener(this)
|
|
92
|
-
// think about cleaning up resources, singletons etc.
|
|
93
|
-
}
|
|
94
|
-
|
|
95
69
|
override fun getDevicePreferredSampleRate(): Double = MediaSessionManager.getDevicePreferredSampleRate()
|
|
96
70
|
|
|
97
71
|
override fun setAudioSessionActivity(
|
|
@@ -13,14 +13,12 @@ class AudioFocusListener(
|
|
|
13
13
|
private val audioAPIModule: WeakReference<AudioAPIModule>,
|
|
14
14
|
private val lockScreenManager: WeakReference<LockScreenManager>,
|
|
15
15
|
) : AudioManager.OnAudioFocusChangeListener {
|
|
16
|
-
private var playOnAudioFocus: Boolean = false
|
|
17
16
|
private var focusRequest: AudioFocusRequest? = null
|
|
18
17
|
|
|
19
18
|
override fun onAudioFocusChange(focusChange: Int) {
|
|
20
19
|
Log.d("AudioFocusListener", "onAudioFocusChange: $focusChange")
|
|
21
20
|
when (focusChange) {
|
|
22
21
|
AudioManager.AUDIOFOCUS_LOSS -> {
|
|
23
|
-
playOnAudioFocus = false
|
|
24
22
|
val body =
|
|
25
23
|
HashMap<String, Any>().apply {
|
|
26
24
|
put("type", "began")
|
|
@@ -28,33 +26,23 @@ class AudioFocusListener(
|
|
|
28
26
|
}
|
|
29
27
|
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
|
|
30
28
|
}
|
|
29
|
+
|
|
31
30
|
AudioManager.AUDIOFOCUS_LOSS_TRANSIENT -> {
|
|
32
|
-
playOnAudioFocus = lockScreenManager.get()?.isPlaying == true
|
|
33
31
|
val body =
|
|
34
32
|
HashMap<String, Any>().apply {
|
|
35
33
|
put("type", "began")
|
|
36
|
-
put("shouldResume",
|
|
34
|
+
put("shouldResume", false)
|
|
37
35
|
}
|
|
38
36
|
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
|
|
39
37
|
}
|
|
40
|
-
AudioManager.AUDIOFOCUS_GAIN -> {
|
|
41
|
-
if (playOnAudioFocus) {
|
|
42
|
-
val body =
|
|
43
|
-
HashMap<String, Any>().apply {
|
|
44
|
-
put("type", "ended")
|
|
45
|
-
put("shouldResume", true)
|
|
46
|
-
}
|
|
47
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
|
|
48
|
-
} else {
|
|
49
|
-
val body =
|
|
50
|
-
HashMap<String, Any>().apply {
|
|
51
|
-
put("type", "ended")
|
|
52
|
-
put("shouldResume", false)
|
|
53
|
-
}
|
|
54
|
-
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
|
|
55
|
-
}
|
|
56
38
|
|
|
57
|
-
|
|
39
|
+
AudioManager.AUDIOFOCUS_GAIN -> {
|
|
40
|
+
val body =
|
|
41
|
+
HashMap<String, Any>().apply {
|
|
42
|
+
put("type", "ended")
|
|
43
|
+
put("shouldResume", true)
|
|
44
|
+
}
|
|
45
|
+
audioAPIModule.get()?.invokeHandlerWithEventNameAndEventBody("interruption", body)
|
|
58
46
|
}
|
|
59
47
|
}
|
|
60
48
|
}
|
|
@@ -42,11 +42,13 @@ class LockScreenManager(
|
|
|
42
42
|
private var playbackState: Int = PlaybackStateCompat.STATE_PAUSED
|
|
43
43
|
|
|
44
44
|
init {
|
|
45
|
-
pb.setActions(controls)
|
|
46
|
-
|
|
47
|
-
nb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
45
|
+
this.pb.setActions(controls)
|
|
46
|
+
|
|
47
|
+
this.nb.setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
|
|
48
|
+
this.nb.setPriority(NotificationCompat.PRIORITY_HIGH)
|
|
48
49
|
|
|
49
50
|
updateNotificationMediaStyle()
|
|
51
|
+
|
|
50
52
|
mediaNotificationManager.get()?.updateActions(controls)
|
|
51
53
|
}
|
|
52
54
|
|
|
@@ -172,31 +174,8 @@ class LockScreenManager(
|
|
|
172
174
|
if (artworkThread != null && artworkThread!!.isAlive) artworkThread!!.interrupt()
|
|
173
175
|
artworkThread = null
|
|
174
176
|
|
|
175
|
-
|
|
176
|
-
artist = null
|
|
177
|
-
album = null
|
|
178
|
-
description = null
|
|
179
|
-
duration = 0L
|
|
180
|
-
speed = 1.0F
|
|
181
|
-
elapsedTime = 0L
|
|
182
|
-
artwork = null
|
|
183
|
-
playbackState = PlaybackStateCompat.STATE_PAUSED
|
|
184
|
-
isPlaying = false
|
|
185
|
-
|
|
186
|
-
val emptyMetadata = MediaMetadataCompat.Builder().build()
|
|
187
|
-
mediaSession.get()?.setMetadata(emptyMetadata)
|
|
188
|
-
|
|
189
|
-
pb.setState(PlaybackStateCompat.STATE_NONE, 0, 0f)
|
|
190
|
-
pb.setActions(controls)
|
|
191
|
-
state = pb.build()
|
|
192
|
-
mediaSession.get()?.setPlaybackState(state)
|
|
177
|
+
mediaNotificationManager.get()?.cancelNotification()
|
|
193
178
|
mediaSession.get()?.setActive(false)
|
|
194
|
-
|
|
195
|
-
nb.setContentTitle("")
|
|
196
|
-
nb.setContentText("")
|
|
197
|
-
nb.setContentInfo("")
|
|
198
|
-
|
|
199
|
-
mediaNotificationManager.get()?.updateNotification(nb, isPlaying)
|
|
200
179
|
}
|
|
201
180
|
|
|
202
181
|
fun enableRemoteCommand(
|
|
@@ -258,16 +258,5 @@ class MediaNotificationManager(
|
|
|
258
258
|
}
|
|
259
259
|
super.onDestroy()
|
|
260
260
|
}
|
|
261
|
-
|
|
262
|
-
override fun onTimeout(startId: Int) {
|
|
263
|
-
stopForegroundService()
|
|
264
|
-
}
|
|
265
|
-
|
|
266
|
-
override fun onTimeout(
|
|
267
|
-
startId: Int,
|
|
268
|
-
fgsType: Int,
|
|
269
|
-
) {
|
|
270
|
-
stopForegroundService()
|
|
271
|
-
}
|
|
272
261
|
}
|
|
273
262
|
}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
package com.swmansion.audioapi.system
|
|
2
|
+
|
|
3
|
+
import com.facebook.react.bridge.ReactApplicationContext
|
|
4
|
+
import java.lang.ref.WeakReference
|
|
5
|
+
|
|
6
|
+
object NativeFileInfo {
|
|
7
|
+
private lateinit var reactContext: WeakReference<ReactApplicationContext>
|
|
8
|
+
|
|
9
|
+
fun initialize(reactContext: WeakReference<ReactApplicationContext>) {
|
|
10
|
+
this.reactContext = reactContext
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
@JvmStatic
|
|
14
|
+
fun getFilesDir(): String = reactContext.get()?.filesDir?.absolutePath ?: ""
|
|
15
|
+
|
|
16
|
+
@JvmStatic
|
|
17
|
+
fun getCacheDir(): String = reactContext.get()?.cacheDir?.absolutePath ?: ""
|
|
18
|
+
}
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
@@ -16,16 +16,13 @@
|
|
|
16
16
|
#include <audioapi/core/utils/worklets/SafeIncludes.h>
|
|
17
17
|
|
|
18
18
|
#include <memory>
|
|
19
|
-
#include <
|
|
19
|
+
#include <string>
|
|
20
20
|
|
|
21
21
|
namespace audioapi {
|
|
22
22
|
|
|
23
23
|
using namespace facebook;
|
|
24
24
|
|
|
25
25
|
class AudioAPIModuleInstaller {
|
|
26
|
-
private:
|
|
27
|
-
inline static std::vector<std::weak_ptr<AudioContext>> contexts_ = {};
|
|
28
|
-
|
|
29
26
|
public:
|
|
30
27
|
static void injectJSIBindings(
|
|
31
28
|
jsi::Runtime *jsiRuntime,
|
|
@@ -65,19 +62,6 @@ class AudioAPIModuleInstaller {
|
|
|
65
62
|
*jsiRuntime, audioEventHandlerRegistryHostObject));
|
|
66
63
|
}
|
|
67
64
|
|
|
68
|
-
static void closeAllContexts() {
|
|
69
|
-
for (auto it = contexts_.begin(); it != contexts_.end(); ++it) {
|
|
70
|
-
auto weakContext = *it;
|
|
71
|
-
|
|
72
|
-
if (auto context = weakContext.lock()) {
|
|
73
|
-
context->close();
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
it = contexts_.erase(it);
|
|
77
|
-
--it;
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
65
|
private:
|
|
82
66
|
static jsi::Function getCreateAudioContextFunction(
|
|
83
67
|
jsi::Runtime *jsiRuntime,
|
|
@@ -112,8 +96,6 @@ class AudioAPIModuleInstaller {
|
|
|
112
96
|
initSuspended,
|
|
113
97
|
audioEventHandlerRegistry,
|
|
114
98
|
runtimeRegistry);
|
|
115
|
-
AudioAPIModuleInstaller::contexts_.push_back(audioContext);
|
|
116
|
-
|
|
117
99
|
auto audioContextHostObject =
|
|
118
100
|
std::make_shared<AudioContextHostObject>(
|
|
119
101
|
audioContext, &runtime, jsCallInvoker);
|
|
@@ -157,7 +139,6 @@ class AudioAPIModuleInstaller {
|
|
|
157
139
|
sampleRate,
|
|
158
140
|
audioEventHandlerRegistry,
|
|
159
141
|
runtimeRegistry);
|
|
160
|
-
|
|
161
142
|
auto audioContextHostObject =
|
|
162
143
|
std::make_shared<OfflineAudioContextHostObject>(
|
|
163
144
|
offlineAudioContext, &runtime, jsCallInvoker);
|
|
@@ -180,17 +161,8 @@ class AudioAPIModuleInstaller {
|
|
|
180
161
|
const jsi::Value &thisValue,
|
|
181
162
|
const jsi::Value *args,
|
|
182
163
|
size_t count) -> jsi::Value {
|
|
183
|
-
auto options = args[0].getObject(runtime);
|
|
184
|
-
|
|
185
|
-
auto sampleRate = static_cast<float>(
|
|
186
|
-
options.getProperty(runtime, "sampleRate").getNumber());
|
|
187
|
-
auto bufferLength = static_cast<int>(
|
|
188
|
-
options.getProperty(runtime, "bufferLengthInSamples")
|
|
189
|
-
.getNumber());
|
|
190
|
-
|
|
191
164
|
auto audioRecorderHostObject =
|
|
192
|
-
std::make_shared<AudioRecorderHostObject>(
|
|
193
|
-
audioEventHandlerRegistry, sampleRate, bufferLength);
|
|
165
|
+
std::make_shared<AudioRecorderHostObject>(audioEventHandlerRegistry);
|
|
194
166
|
|
|
195
167
|
return jsi::Object::createFromHostObject(
|
|
196
168
|
runtime, audioRecorderHostObject);
|