Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(UNT-T26002): native prop handling #39

Merged
merged 1 commit into from
Jun 7, 2024
Merged
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
2 changes: 1 addition & 1 deletion android/src/main/java/com/audiowaveform/AudioRecorder.kt
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ class AudioRecorder {
encoder: Int,
outputFormat: Int,
sampleRate: Int,
bitRate: Int?,
bitRate: Int,
promise: Promise
) {
if (recorder == null) {
Expand Down
35 changes: 25 additions & 10 deletions android/src/main/java/com/audiowaveform/AudioWaveformModule.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
private var path: String? = null
private var outputFormat: Int = 0
private var sampleRate: Int = 44100
private var bitRate: Int? = null
private var bitRate: Int = 128000
private val handler = Handler(Looper.getMainLooper())

companion object {
Expand All @@ -51,8 +51,8 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
}

@ReactMethod
fun initRecorder(promise: Promise) {
checkPathAndInitialiseRecorder(encoder, outputFormat, sampleRate, bitRate, promise)
fun initRecorder(obj: ReadableMap?, promise: Promise) {
checkPathAndInitialiseRecorder(encoder, outputFormat, sampleRate, bitRate, promise, obj)
}

@ReactMethod
Expand All @@ -62,7 +62,7 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav

@ReactMethod
fun startRecording(obj: ReadableMap?, promise: Promise) {
initRecorder(promise)
initRecorder(obj, promise)
val useLegacyNormalization = true
audioRecorder.startRecorder(recorder, useLegacyNormalization, promise)
startEmittingRecorderValue()
Expand Down Expand Up @@ -275,9 +275,24 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
encoder: Int,
outputFormat: Int,
sampleRate: Int,
bitRate: Int?,
promise: Promise
bitRate: Int,
promise: Promise,
obj: ReadableMap?
) {

var sampleRateVal = sampleRate.toInt();
var bitRateVal = bitRate.toInt();

if(obj != null) {
if(obj.hasKey(Constants.bitRate)){
bitRateVal = obj.getInt(Constants.bitRate);
}

if(obj.hasKey(Constants.sampleRate)){
sampleRateVal = obj.getInt(Constants.sampleRate);
}
}

try {
recorder = MediaRecorder()
} catch (e: Exception) {
Expand All @@ -296,8 +311,8 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
recorder,
encoder,
outputFormat,
sampleRate,
bitRate,
sampleRateVal,
bitRateVal,
promise,
)
} catch (e: IOException) {
Expand All @@ -309,8 +324,8 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
recorder,
encoder,
outputFormat,
sampleRate,
bitRate,
sampleRateVal,
bitRateVal,
promise,
)
}
Expand Down
2 changes: 2 additions & 0 deletions android/src/main/java/com/audiowaveform/Utils.kt
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ object Constants {
const val waveformData = "waveformData"
const val updateFrequency = "updateFrequency"
const val currentDecibel = "currentDecibel"
const val bitRate = "bitRate"
const val sampleRate = "sampleRate"
}

enum class FinishMode(val value:Int) {
Expand Down