Skip to content

Commit 97cf9f8

Browse files
committed
chore: in list + hidden stop button + extract wave form on play
1 parent 891a7c5 commit 97cf9f8

File tree

3 files changed

+49
-18
lines changed

3 files changed

+49
-18
lines changed

example/src/App.tsx

Lines changed: 30 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ const RenderListItem = React.memo(
127127
onError={error => {
128128
console.log('Error in static player:', error);
129129
}}
130-
onCurrentProgressChange={(currentProgress, songDuration) => {
131-
console.log(
132-
`currentProgress ${currentProgress}, songDuration ${songDuration}`
133-
);
130+
onCurrentProgressChange={(_currentProgress, _songDuration) => {
131+
// console.log(
132+
// `currentProgress ${currentProgress}, songDuration ${songDuration}`
133+
// );
134134
}}
135135
onChangeWaveformLoadState={state => {
136136
setIsLoading(state);
@@ -225,6 +225,8 @@ const AppContainer = () => {
225225
const [list, setList] = useState<ListItem[]>([]);
226226
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] =
227227
useState<PlaybackSpeedType>(1.0);
228+
const [showAdvancedOptions, setShowAdvancedOptions] =
229+
useState<boolean>(false);
228230

229231
const { top, bottom } = useSafeAreaInsets();
230232
const styles = stylesheet({ top, bottom });
@@ -247,6 +249,10 @@ const AppContainer = () => {
247249
);
248250
};
249251

252+
const toggleAdvancedOptions = () => {
253+
setShowAdvancedOptions(!showAdvancedOptions);
254+
};
255+
250256
const handleStopPlayersAndExtractors = async () => {
251257
const { stopPlayersAndExtractors } = useAudioPlayer();
252258
const hasStoppedAll: boolean[] = await stopPlayersAndExtractors();
@@ -277,23 +283,31 @@ const AppContainer = () => {
277283
<GestureHandlerRootView style={styles.appContainer}>
278284
<View style={styles.screenBackground}>
279285
<View style={styles.container}>
280-
<View style={styles.simformImageContainer}>
286+
<Pressable
287+
style={styles.simformImageContainer}
288+
onPress={toggleAdvancedOptions}>
281289
<Image
282290
source={Icons.simform}
283291
style={styles.simformImage}
284292
resizeMode="contain"
285293
/>
286-
<Pressable
287-
style={styles.playBackControlPressable}
288-
onPress={handleStopPlayersAndExtractors}>
289-
<FastImage
290-
source={Icons.stop}
291-
style={styles.stopAllButton}
292-
resizeMode="contain"
293-
tintColor={Colors.pink}
294-
/>
295-
</Pressable>
296-
</View>
294+
</Pressable>
295+
{showAdvancedOptions && (
296+
<>
297+
<Pressable
298+
style={styles.stopAllRecordingContainer}
299+
onPress={handleStopPlayersAndExtractors}>
300+
<Image
301+
source={Icons.stop}
302+
style={styles.pinkButtonImage}
303+
resizeMode="contain"
304+
/>
305+
<Text style={styles.stopAllRecordingTitle}>
306+
{'Stop all players and extractors'}
307+
</Text>
308+
</Pressable>
309+
</>
310+
)}
297311
<ScrollView scrollEnabled={shouldScroll}>
298312
{list.map(item => (
299313
<RenderListItem

example/src/styles.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ const styles = (params: StyleSheetParams = {}) =>
5454
tintColor: Colors.white,
5555
alignSelf: 'flex-end',
5656
},
57-
stopAllButton: {
57+
pinkButtonImage: {
5858
height: scale(22),
5959
width: scale(22),
6060
tintColor: Colors.pink,
@@ -101,6 +101,17 @@ const styles = (params: StyleSheetParams = {}) =>
101101
justifyContent: 'space-around',
102102
flexDirection: 'row',
103103
},
104+
stopAllRecordingContainer: {
105+
alignItems: 'center',
106+
justifyContent: 'center',
107+
flexDirection: 'row',
108+
},
109+
stopAllRecordingTitle: {
110+
fontSize: scale(20),
111+
fontWeight: 'bold',
112+
color: Colors.pink,
113+
paddingLeft: scale(8),
114+
},
104115
loadingText: {
105116
color: Colors.black,
106117
},

src/components/Waveform/Waveform.tsx

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
7474
const [panMoving, setPanMoving] = useState(false);
7575
const [playerState, setPlayerState] = useState(PlayerState.stopped);
7676
const [recorderState, setRecorderState] = useState(RecorderState.stopped);
77+
const [isWaveformExtracted, setWaveformExtracted] = useState(false);
7778
const audioSpeed: number =
7879
playbackSpeed > playbackSpeedThreshold ? 1.0 : playbackSpeed;
7980

@@ -188,6 +189,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
188189
if (!isNil(waveforms) && !isEmpty(waveforms)) {
189190
setWaveform(waveforms);
190191
await preparePlayerAndGetDuration();
192+
setWaveformExtracted(true);
191193
}
192194
}
193195
} catch (err) {
@@ -230,7 +232,11 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
230232
if (mode === 'static') {
231233
try {
232234
if (playerState === PlayerState.stopped) {
233-
await preparePlayerForPath(currentProgress);
235+
if (isWaveformExtracted) {
236+
await preparePlayerForPath(currentProgress);
237+
} else {
238+
await getAudioWaveFormForPath(noOfSamples);
239+
}
234240
}
235241

236242
const play = await playPlayer({

0 commit comments

Comments
 (0)