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: adds creation, saving and playback of audio #762

Merged
merged 48 commits into from
Oct 10, 2024
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
Show all changes
48 commits
Select commit Hold shift + click to select a range
c2ddc7d
Adds functionality for asking for permissions for Audio. Adds Audio n…
cimigree Sep 26, 2024
11c6fe7
Adds messages
cimigree Sep 26, 2024
ace81dd
Adds ability to create a recording.
cimigree Sep 26, 2024
42f40d0
Adds messages.
cimigree Sep 26, 2024
7491659
Adds ability to playback and save audio recordings.
cimigree Sep 26, 2024
1e41c3a
Adds messages.
cimigree Sep 26, 2024
e121508
Adds play arrow image.
cimigree Sep 26, 2024
7583f81
Playback working and can play from midway.
cimigree Sep 30, 2024
c37d204
Tightens playback.
cimigree Sep 30, 2024
c644f95
Merges with develop.
cimigree Sep 30, 2024
03343cf
Merge branch 'feat/add-audio-creation' into feat/add-audio-save-playback
cimigree Sep 30, 2024
c0ccfaa
Changes from Erik etc.
cimigree Oct 1, 2024
2b4be6d
Adds back header for when returning to record another.
cimigree Oct 1, 2024
b9f1815
Wraps everything in row. Prevents going back. Removes header.Adds two…
cimigree Oct 2, 2024
d6c57c6
Use callback added. Changes to touchable opacity. Adjusts constant lo…
cimigree Oct 2, 2024
08d5196
Uses use callback. Changes if to ternary. Uses BottomModalContent.
cimigree Oct 2, 2024
19dc94a
Trying to handle dismissing modal when app is closed and restarted.
cimigree Oct 2, 2024
a4ff0d0
chore: update icon on error bottom sheet
ErikSin Oct 2, 2024
3093210
chore: added ability for custom message
ErikSin Oct 2, 2024
173b32a
Undoing recent changes
cimigree Oct 3, 2024
9dd91fa
Adjusts function definitions and calls at runtime
cimigree Oct 3, 2024
15aa90b
Passing on dismiss
cimigree Oct 3, 2024
7a7218e
Removing go back
cimigree Oct 3, 2024
42827b2
Trying removal of back handler
cimigree Oct 3, 2024
3d93b66
Trying some fixes
cimigree Oct 3, 2024
656d0e5
Testing out sheet sizes
cimigree Oct 3, 2024
24e4db1
Trying full size
cimigree Oct 3, 2024
36ddb91
Messing with full screen.
cimigree Oct 3, 2024
f7f4ffb
Trying different order
cimigree Oct 3, 2024
c115345
Blocking touch events when modal open.
cimigree Oct 3, 2024
8018ceb
Adds flex.
cimigree Oct 3, 2024
5a7c6ac
Disabling audio press when modal is open.
cimigree Oct 3, 2024
5a9c2d0
Timeout
cimigree Oct 3, 2024
836e1e5
Trying without timeout
cimigree Oct 7, 2024
71ef897
Removes references to isOpen
cimigree Oct 7, 2024
1225d55
Tries using on dismiss
cimigree Oct 7, 2024
c030e85
Removes console log. Adds switch statement. Tries timeout with permis…
cimigree Oct 7, 2024
030a977
Uses on dismiss in permissions modal
cimigree Oct 7, 2024
077e8ab
chore: updated styling
ErikSin Oct 7, 2024
8b8b97b
Uses blur event instead of the onDismiss
cimigree Oct 7, 2024
6d86fa6
Merge branch 'chore-update-error-icon' of https://github.com/digidem/…
cimigree Oct 7, 2024
fc6cf2b
Passes reset. Removes wrapping.
cimigree Oct 7, 2024
70467b8
Goes back to using onmodal dismiss
cimigree Oct 7, 2024
a7130e8
Merge branch 'develop' into feat/add-audio-save-playback
cimigree Oct 7, 2024
797d89a
Fixes mistakes in handling modal dismissal
cimigree Oct 7, 2024
85fedb1
Tidies up modal dismissal action
cimigree Oct 8, 2024
47e64e8
Removes unused prop.
cimigree Oct 8, 2024
8c66867
Updates var name, removes status bar, changes state for permission.
cimigree Oct 8, 2024
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
36 changes: 36 additions & 0 deletions messages/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,21 @@
"description": "Title of dialog that shows when cancelling a new observation",
"message": "Discard observation?"
},
"AudioPlaybackScreen.DeleteAudioRecordingModal.successDescription": {
"message": "Your <bold>{audioRecording}</bold> was added."
},
"AudioPlaybackScreen.DeleteAudioRecordingModal.successTitle": {
"message": "Success!"
},
"AudioPlaybackScreen.SuccessAudioRecordingModal.audioRecording": {
"message": "Audio Recording"
},
"AudioPlaybackScreen.SuccessAudioRecordingModal.recordAnother": {
"message": "Record Another"
},
"AudioPlaybackScreen.SuccessAudioRecordingModal.returnToEditor": {
"message": "Return to Editor"
},
"Modal.GPSDisable.button": {
"message": "Enable"
},
Expand Down Expand Up @@ -360,6 +375,27 @@
"description": "Screen title for audio permission screen",
"message": "Recording Audio with CoMapeo"
},
"screens.AudioScreen.CreateRecording.RecordingActive.description": {
"message": "Less than {length} {length, plural, one {minute} other {minutes}} left"
},
"screens.AudioScreen.CreateRecording.RecordingDone.deleteBottomSheetDescription": {
"message": "Your Audio Recording will be permanently deleted. This cannot be undone."
},
"screens.AudioScreen.CreateRecording.RecordingDone.deleteBottomSheetPrimaryButtonText": {
"message": "Delete"
},
"screens.AudioScreen.CreateRecording.RecordingDone.deleteBottomSheetSecondaryButtonText": {
"message": "Cancel"
},
"screens.AudioScreen.CreateRecording.RecordingDone.deleteBottomSheetTitle": {
"message": "Delete?"
},
"screens.AudioScreen.CreateRecording.RecordingIdle.description": {
"message": "Record up to {length} {length, plural, one {minute} other {minutes}}"
},
"screens.AudioScreen.Playback.description": {
"message": "Total length: {length}"
},
"screens.CameraScreen.goToSettings": {
"message": "Go to Settings"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,11 @@ import {
SavedPhoto,
} from '../../../contexts/PhotoPromiseContext/types';
import {deletePhoto, replaceDraftPhotos} from './photosMethods';
import {ClientGeneratedObservation, Position} from '../../../sharedTypes';
import {
ClientGeneratedObservation,
Position,
AudioRecording,
} from '../../../sharedTypes';
import {Observation, Preset} from '@comapeo/schema';
import {usePresetsQuery} from '../../server/presets';
import {matchPreset} from '../../../lib/utils';
Expand All @@ -23,7 +27,7 @@ const emptyObservation: ClientGeneratedObservation = {

export type DraftObservationSlice = {
photos: Photo[];
audioRecordings: [];
audioRecordings: AudioRecording[];
value: Observation | null | ClientGeneratedObservation;
observationId?: string;
actions: {
Expand Down Expand Up @@ -53,6 +57,7 @@ export type DraftObservationSlice = {
) => void;
updateTags: (tagKey: string, value: Observation['tags'][0]) => void;
updatePreset: (preset: Preset) => void;
addAudioRecording: (audioRecording: AudioRecording) => void;
};
};

Expand Down Expand Up @@ -173,6 +178,10 @@ const draftObservationSlice: StateCreator<DraftObservationSlice> = (
},
});
},
addAudioRecording: recording =>
set({
audioRecordings: [...get().audioRecordings, recording],
}),
},
});

Expand Down
22 changes: 22 additions & 0 deletions src/frontend/hooks/server/media.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {useActiveProject} from '../../contexts/ActiveProjectContext';
import {ProcessedDraftPhoto} from '../../contexts/PhotoPromiseContext/types';
import type {MapeoProjectApi} from '@comapeo/ipc';
import {ClientApi} from 'rpc-reflector';
import {AudioRecording} from '../../sharedTypes';

export function useCreateBlobMutation(opts: {retry?: number} = {}) {
const {projectApi} = useActiveProject();
Expand Down Expand Up @@ -34,6 +35,27 @@ export function useCreateBlobMutation(opts: {retry?: number} = {}) {
});
}

export function useCreateAudioBlobMutation(opts: {retry?: number} = {}) {
const {projectApi} = useActiveProject();

return useMutation({
retry: opts.retry,
mutationFn: async (audio: AudioRecording) => {
const {uri, createdAt} = audio;

return projectApi.$blobs.create(
{
original: new URL(uri).pathname,
},
{
mimeType: 'audio/mp4',
timestamp: createdAt,
},
);
},
});
}

const resolveAttachmentUrlQueryOptions = (
projectId: string,
projectApi: ClientApi<MapeoProjectApi>,
Expand Down
10 changes: 10 additions & 0 deletions src/frontend/hooks/useDraftObservation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
PhotoPromiseWithMetadata,
UnprocessedDraftPhoto,
} from '../contexts/PhotoPromiseContext/types';
import {AudioRecording} from '../sharedTypes';
// react native does not have a random bytes generator, `non-secure` does not require a random bytes generator.
import {nanoid} from 'nanoid/non-secure';
import * as Sentry from '@sentry/react-native';
Expand All @@ -29,6 +30,7 @@ export const useDraftObservation = () => {
updateTags,
updatePreset,
existingObservationToDraft,
addAudioRecording,
} = _usePersistedDraftObservationActions();

const addPhoto = useCallback(
Expand Down Expand Up @@ -92,6 +94,13 @@ export const useDraftObservation = () => {
[deletePersistedPhoto, deletePhotoPromise],
);

const addAudio = useCallback(
(audioRecording: AudioRecording) => {
addAudioRecording(audioRecording);
},
[addAudioRecording],
);

cimigree marked this conversation as resolved.
Show resolved Hide resolved
return {
addPhoto,
clearDraft,
Expand All @@ -102,5 +111,6 @@ export const useDraftObservation = () => {
updatePreset,
usePreset,
existingObservationToDraft,
addAudio,
};
};
3 changes: 3 additions & 0 deletions src/frontend/images/PlayArrow.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
33 changes: 33 additions & 0 deletions src/frontend/screens/Audio/AnimatedBackground.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
import React from 'react';
import {Dimensions, StyleSheet} from 'react-native';
import Animated, {SharedValue, useAnimatedStyle} from 'react-native-reanimated';
import {useSafeAreaInsets} from 'react-native-safe-area-context';

import {MAX_RECORDING_DURATION_MS} from './constants';

export function AnimatedBackground({
elapsedTimeValue,
}: {
elapsedTimeValue: SharedValue<number>;
}) {
const {top} = useSafeAreaInsets();
const {height} = Dimensions.get('window');

const animatedStyles = useAnimatedStyle(() => ({
height:
(height + top) *
(elapsedTimeValue.value * (1 / MAX_RECORDING_DURATION_MS)),
backgroundColor: `hsl(216, 100%, ${elapsedTimeValue.value * (1 / MAX_RECORDING_DURATION_MS) * 50}%)`,
}));

return <Animated.View style={[styles.fill, animatedStyles]} />;
}

const styles = StyleSheet.create({
fill: {
position: 'absolute',
zIndex: -1,
bottom: 0,
width: '100%',
},
});
78 changes: 78 additions & 0 deletions src/frontend/screens/Audio/ContentWithControls.tsx
cimigree marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
import React, {ReactNode} from 'react';
import {StyleSheet, View} from 'react-native';
import {Bar} from 'react-native-progress';
import {Duration} from 'luxon';

import {MEDIUM_GREY, WHITE} from '../../lib/styles';
import {ScreenContentWithDock} from '../../sharedComponents/ScreenContentWithDock';
import {Text} from '../../sharedComponents/Text';

export function ContentWithControls({
controls,
message,
progress,
timeElapsed,
}: {
controls: ReactNode;
message?: string;
progress?: number;
timeElapsed: number;
}) {
return (
<ScreenContentWithDock
contentContainerStyle={styles.contentContainer}
dockContainerStyle={styles.dockContainer}
dockContent={controls}>
<View style={styles.container}>
<View style={styles.timerContainer}>
<Text style={styles.timerText}>
{Duration.fromMillis(timeElapsed).toFormat('mm:ss')}
</Text>

{typeof progress === 'number' ? (
<Bar
// Setting to 0 seems to have issues on Android: https://github.com/oblador/react-native-progress/issues/56
progress={progress > 0 ? progress : 0.00000001}
indeterminate={false}
width={null}
color={WHITE}
borderColor="transparent"
borderRadius={0}
borderWidth={0}
unfilledColor={MEDIUM_GREY}
/>
) : (
<View />
)}
</View>
<Text style={styles.message}>{message}</Text>
</View>
</ScreenContentWithDock>
);
}

const styles = StyleSheet.create({
contentContainer: {flex: 1},
dockContainer: {paddingVertical: 24},
container: {
flex: 1,
justifyContent: 'flex-end',
},
timerContainer: {
flex: 1,
justifyContent: 'center',
gap: 48,
},
message: {
color: WHITE,
fontSize: 20,
textAlign: 'center',
},
timerText: {
fontFamily: 'Rubik',
fontSize: 96,
fontWeight: 'bold',
color: WHITE,
textAlign: 'center',
},
});
Loading
Loading