audio.AudioMode
The app's audio session, which configure sets.
Usage
Play a track and record a voice note
This type is used by audio.configure
import { Box, Button, VStack, Text, audio, onMount } from 'kuito';
function Track() {
// The component owns it: made when it mounts, released when it unmounts.
const song = audio.player('https://example.com/song.mp3', { loop: true });
const { time, duration } = song;
return (
<VStack>
{/* A 280-point bar that fills from the left, moved on the UI thread. */}
<Box width={280} height={4} overflow="hidden">
<Box
width={280}
height={4}
backgroundColor="#e50914"
translateX={duration.value > 0 ? (time.value / duration.value - 1) * 280 : -280}
/>
</Box>
<Button onPress={() => (song.playing.value = !song.playing.value)}>
{song.playing.value ? 'Pause' : 'Play'}
</Button>
<Button onPress={() => void song.seek(time.value + 30)}>Skip</Button>
</VStack>
);
}
function Memo() {
const recorder = audio.recorder({ quality: 'medium', metering: true });
onMount(() => void audio.configure({ allowsRecording: true }));
return (
<VStack>
<Box height={8} backgroundColor="#e5484d" opacity={1 + recorder.level.value / 60} />
<Button onPress={() => void recorder.start()}>Record</Button>
<Button onPress={async () => console.log((await recorder.stop()).uri)}>Stop</Button>
</VStack>
);
}Type declaration
export type AudioMode = Mode;Members 5
| Name | Type | Required | Description |
|---|---|---|---|
playsInSilentMode | boolean | Yes | iOS: play while the ring/silent switch is on silent. Defaults to true. |
mixWithOthers | boolean | Yes | Play alongside other apps' audio instead of stopping it. Defaults to false. |
duckOthers | boolean | Yes | Lower other apps' audio while this app plays. Defaults to false. |
allowsRecording | boolean | Yes | iOS: needed before a recorder starts. Defaults to false. |
staysActiveInBackground | boolean | Yes | Keep playing in the background; iOS also needs ios.backgroundModes: ['audio']. Defaults to false. |
Generated from the public TypeScript declarations: signatures, props and defaults come from the checked source, descriptions from its JSDoc. No defaults are invented.