audio.player
A player for src, owned by the component setting up: it is made when the
component mounts and released when it unmounts. { scope: app } makes one
the app holds for its life.
Utilisation
Play a track and record a voice note
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>
);
}Signatures
(src: AudioSource, options?: AudioPlayerOptions): AudioPlayerParamètres
| Nom | Type | Requis | Description |
|---|---|---|---|
src | AudioSource | Oui | — |
options | AudioPlayerOptions | Non | — Par défaut: {} |
Retourne
Généré depuis les déclarations TypeScript publiques : signatures, props et valeurs par défaut viennent de la source vérifiée, les descriptions de sa JSDoc. Aucune valeur par défaut n'est inventée.