Skip to content

Commit

Permalink
chore: in list + hidden stop button + extract wave form on play
Browse files Browse the repository at this point in the history
  • Loading branch information
dprevost-LMI committed Nov 16, 2024
1 parent b5b8452 commit c0f4eab
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 6 deletions.
35 changes: 30 additions & 5 deletions example/src/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,10 @@ const RenderListItem = React.memo(
onError={error => {
console.log('Error in static player:', error);
}}
onCurrentProgressChange={(currentProgress, songDuration) => {
console.log(
`currentProgress ${currentProgress}, songDuration ${songDuration}`
);
onCurrentProgressChange={(_currentProgress, _songDuration) => {
// console.log(
// `currentProgress ${currentProgress}, songDuration ${songDuration}`
// );
}}
onChangeWaveformLoadState={state => {
setIsLoading(state);
Expand Down Expand Up @@ -253,6 +253,8 @@ const AppContainer = () => {
const [nbOfRecording, setNumberOfRecording] = useState<number>(0);
const [currentPlaybackSpeed, setCurrentPlaybackSpeed] =
useState<PlaybackSpeedType>(1.0);
const [showAdvancedOptions, setShowAdvancedOptions] =
useState<boolean>(false);

const { top, bottom } = useSafeAreaInsets();
const styles = stylesheet({ top, bottom });
Expand Down Expand Up @@ -310,6 +312,10 @@ const AppContainer = () => {
);
};

const toggleAdvancedOptions = () => {
setShowAdvancedOptions(!showAdvancedOptions);
};

const handleStopPlayersAndExtractors = async () => {
const { stopPlayersAndExtractors } = useAudioPlayer();
const hasStoppedAll: boolean[] = await stopPlayersAndExtractors();
Expand Down Expand Up @@ -340,12 +346,31 @@ const AppContainer = () => {
<GestureHandlerRootView style={styles.appContainer}>
<View style={styles.screenBackground}>
<View style={styles.container}>
<View style={styles.headerContainer}>
<Pressable
style={styles.simformImageContainer}
onPress={toggleAdvancedOptions}>
<Image
source={Icons.simform}
style={styles.simformImage}
resizeMode="contain"
/>
</Pressable>
{showAdvancedOptions && (
<>
<Pressable
style={styles.stopAllRecordingContainer}
onPress={handleStopPlayersAndExtractors}>
<Image
source={Icons.stop}
style={styles.pinkButtonImage}
resizeMode="contain"
/>
<Text style={styles.stopAllRecordingTitle}>
{'Stop all players and extractors'}
</Text>
</Pressable>
</>
)}
<Pressable
style={[
styles.deleteRecordingContainer,
Expand Down
11 changes: 11 additions & 0 deletions example/src/styles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,17 @@ const styles = (params: StyleSheetParams = {}) =>
color: Colors.pink,
paddingLeft: scale(8),
},
stopAllRecordingContainer: {
alignItems: 'center',
justifyContent: 'center',
flexDirection: 'row',
},
stopAllRecordingTitle: {
fontSize: scale(20),
fontWeight: 'bold',
color: Colors.pink,
paddingLeft: scale(8),
},
loadingText: {
color: Colors.black,
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/Waveform/Waveform.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
const [panMoving, setPanMoving] = useState(false);
const [playerState, setPlayerState] = useState(PlayerState.stopped);
const [recorderState, setRecorderState] = useState(RecorderState.stopped);
const [isWaveformExtracted, setWaveformExtracted] = useState(false);
const audioSpeed: number =
playbackSpeed > playbackSpeedThreshold ? 1.0 : playbackSpeed;

Expand Down Expand Up @@ -193,6 +194,7 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
if (!isNil(waveforms) && !isEmpty(waveforms)) {
setWaveform(waveforms);
await preparePlayerAndGetDuration();
setWaveformExtracted(true);
}
}
} catch (err) {
Expand Down Expand Up @@ -235,7 +237,11 @@ export const Waveform = forwardRef<IWaveformRef, IWaveform>((props, ref) => {
if (mode === 'static') {
try {
if (playerState === PlayerState.stopped) {
await preparePlayerForPath(currentProgress);
if (isWaveformExtracted) {
await preparePlayerForPath(currentProgress);
} else {
await getAudioWaveFormForPath(noOfSamples);
}
}

const play = await playPlayer({
Expand Down

0 comments on commit c0f4eab

Please sign in to comment.