Skip to content
Merged
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
19 changes: 16 additions & 3 deletions apps/common-app/src/examples/Record/Record.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ const Record: FC = () => {
/// This stops only the recording, not the audio context
const stopEcho = async () => {
audioRecorder.stop();
audioContext.suspend();

audioRecorder.disconnect();
setStatus(Status.Idle);
Expand All @@ -109,7 +110,7 @@ const Record: FC = () => {
AudioManager.setAudioSessionOptions({
iosCategory: 'playAndRecord',
iosMode: 'default',
iosOptions: ['defaultToSpeaker', 'allowBluetoothA2DP'],
iosOptions: ['allowBluetoothA2DP', 'allowBluetoothHFP'],
});

const success = await AudioManager.setAudioSessionActivity(true);
Expand Down Expand Up @@ -146,6 +147,16 @@ const Record: FC = () => {
return;
}

const result = audioRecorder.start();

if (result.status === 'error') {
Alert.alert(
'Recording Error',
`Failed to start recording: ${result.message}`
);
return;
}

setStatus(Status.Recording);

setTimeout(async () => {
Expand Down Expand Up @@ -174,7 +185,7 @@ const Record: FC = () => {
}

if (audioContext.state === 'suspended') {
audioContext.resume();
await audioContext.resume();
}

const tNow = audioContext.currentTime;
Expand All @@ -191,7 +202,9 @@ const Record: FC = () => {
setStatus(Status.Playback);

setTimeout(
() => {
async () => {
await audioContext.suspend();
await AudioManager.setAudioSessionActivity(false);
setStatus(Status.Idle);
},
(nextStartAt - tNow) * 1000
Expand Down