audio.AudioPlayerOptions
Sets how an audio player starts out (its volume, speed and looping) and which scope owns it.
Verwendung
Play a track and record a voice note
Dieser Typ wird verwendet von audio.player
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>
);
}Typdeklaration
export type AudioPlayerOptions = ScopeOptions & {
/** 0 to 1. Defaults to 1. */
volume?: number;
/** 0.5 to 2, pitch kept. Defaults to 1. */
rate?: number;
/** Starts over at the end instead of stopping. Defaults to false. */
loop?: boolean;
};Mitglieder 4
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
scope | typeof appModule | Nein | — |
volume | number | Nein | 0 to 1. Defaults to 1. |
rate | number | Nein | 0.5 to 2, pitch kept. Defaults to 1. |
loop | boolean | Nein | Starts over at the end instead of stopping. Defaults to false. |
scope — verschachtelte Felder
scope Felder
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
watch | <E extends keyof Events>(event: E, listener: Events[E]) => EventSubscription | Ja | Calls listener when the system warns that memory runs low. In a
component it stops when the component unmounts; elsewhere the returned
subscription stops it. |
state | ReadonlySignal<State> | Ja | Whether the app is in the foreground. Watched, it follows the platform;
starting to observe reports the state the platform starts from, which
catches a change made in between. Standard: AppStateModule.state |
openSettings | () => Promise<void> | Ja | Opens this app's page in the system Settings. Standard: AppStateModule.openSettings |
watch — Methodensignaturen
Signaturen
<E extends keyof Events>(event: E, listener: Events[E]): EventSubscriptionTypparameter
| Name | Einschränkung | Standard |
|---|---|---|
E | "memoryWarning" | — |
Parameter
| Name | Typ | Erforderlich | Beschreibung |
|---|---|---|---|
event | E | Ja | — |
listener | Events[E] | Ja | — |
Rückgabe
openSettings — Methodensignaturen
Signaturen
(): Promise<void>Parameter
Keine Parameter.
Rückgabe
Promise<void>
Generiert aus den öffentlichen TypeScript-Deklarationen: Signaturen, Props und Standardwerte stammen aus der geprüften Quelle, Beschreibungen aus deren JSDoc. Kein Standardwert ist erfunden.