Skip to content

Commit fc73d21

Browse files
fix(UNT-T22087): fix audio playback flickering when seek in android
1 parent c8cb1b3 commit fc73d21

File tree

4 files changed

+18
-13
lines changed

4 files changed

+18
-13
lines changed

android/src/main/java/com/audiowaveform/AudioPlayer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ class AudioPlayer(
151151

152152
private fun startListening(promise: Promise) {
153153
try {
154-
audioPlaybackListener = object : CountDownTimer(player.duration, 10) {
154+
audioPlaybackListener = object : CountDownTimer(player.duration, UpdateFrequency.Low.value) {
155155
override fun onTick(millisUntilFinished: Long) {
156156
val currentPosition = player.currentPosition.toString()
157157
val args: WritableMap = Arguments.createMap()

android/src/main/java/com/audiowaveform/AudioWaveformModule.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -309,13 +309,13 @@ class AudioWaveformModule(context: ReactApplicationContext): ReactContextBaseJav
309309
args.putDouble(Constants.currentDecibel, currentDecibel/1000)
310310
}
311311
}
312-
handler.postDelayed(this, 500)
312+
handler.postDelayed(this, UpdateFrequency.Low.value)
313313
reactApplicationContext.getJSModule(DeviceEventManagerModule.RCTDeviceEventEmitter::class.java)?.emit(Constants.onCurrentRecordingWaveformData, args)
314314
}
315315
}
316316

317317
private fun startEmittingRecorderValue() {
318-
handler.postDelayed(emitLiveRecordValue, 500)
318+
handler.postDelayed(emitLiveRecordValue, UpdateFrequency.Low.value)
319319
}
320320

321321
private fun stopEmittingRecorderValue() {

example/android/app/src/main/AndroidManifest.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
<uses-permission android:name="android.permission.INTERNET" />
44
<uses-permission android:name="android.permission.RECORD_AUDIO" />
5-
<uses-permission android:name="android.permission.READ_MEDIA_AUDIO" />
65

76
<application
87
android:name=".MainApplication"

src/components/Waveform/Waveform.tsx

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ export const Waveform: <T extends StaticOrLive>(
193193
const startPlayerAction = async (args?: IStartPlayerRef) => {
194194
try {
195195
const play = await playPlayer({
196-
finishMode: FinishMode.loop,
196+
finishMode: FinishMode.stop,
197197
playerKey: `PlayerFor${path}`,
198198
path: path,
199199
...args,
@@ -391,15 +391,12 @@ export const Waveform: <T extends StaticOrLive>(
391391
});
392392
const subscribeData2 = onCurrentDuration(data => {
393393
if (data.playerKey === `PlayerFor${path}`) {
394-
if (!panMoving) {
395-
setCurrentProgress(data.currentDuration);
396-
}
394+
setCurrentProgress(data.currentDuration);
397395
}
398396
});
399397
const subscribeData3 = onCurrentExtractedWaveformData(() => {
400398
// write logic for subscription
401399
});
402-
403400
const subscribeData4 = onCurrentRecordingWaveformData(result => {
404401
if (mode === 'live') {
405402
if (!isNil(result.currentDecibel)) {
@@ -416,7 +413,7 @@ export const Waveform: <T extends StaticOrLive>(
416413
subscribeData3.remove();
417414
subscribeData4.remove();
418415
};
419-
}, [panMoving]);
416+
}, []);
420417

421418
useEffect(() => {
422419
if (!isNil(onPlayerStateChange)) {
@@ -430,15 +427,24 @@ export const Waveform: <T extends StaticOrLive>(
430427
}
431428
}, [recorderState]);
432429

430+
useEffect(() => {
431+
if (panMoving) {
432+
if (playerState === PlayerState.playing) {
433+
pausePlayerAction();
434+
}
435+
} else {
436+
if (playerState === PlayerState.paused) {
437+
startPlayerAction();
438+
}
439+
}
440+
}, [panMoving]);
441+
433442
const panResponder = useRef(
434443
PanResponder.create({
435444
onMoveShouldSetPanResponder: () => true,
436445
onPanResponderGrant: () => {
437446
setPanMoving(true);
438447
(onPanStateChange as Function)(true);
439-
if (playerState === PlayerState.playing) {
440-
pausePlayerAction();
441-
}
442448
},
443449
onPanResponderStart: () => {},
444450
onPanResponderMove: event => {

0 commit comments

Comments
 (0)