@@ -5,19 +5,20 @@ FaCC that creates an `<audio>` element to play audio tracks, re-renders on audio
55## Usage
66
77``` jsx
8- import {Audio } from ' mol-fe-react /lib/Audio' ;
8+ import {Audio } from ' libreact /lib/Audio' ;
99
1010< Audio autoPlay src= ' https://www.soundhelix.com/examples/mp3/SoundHelix-Song-2.mp3' > {(control , state ) => {
1111 JSON .stringify (state, null , 4 )
1212}}< / Audio>
1313```
1414
15+
1516## Props
1617
1718In addition to props below also accepts all [ React's media events] ( https://reactjs.org/docs/events.html#media-events ) .
1819
1920``` tsx
20- export interface IAudioProps {
21+ interface IAudioProps {
2122 src: string ;
2223 autoPlay? : boolean ;
2324 loop? : boolean ;
@@ -36,6 +37,56 @@ export interface IAudioProps {
3637 - ` volume ` - optional, number, audio volume in ` [0..1] ` range, defaults to ` 1 ` .
3738 - ` noJs ` - optional, React element(s) to render insided the ` <audio> ` tag.
3839
40+
41+ ## Arguments
42+
43+ The ` children ` function receives two arguments, ` audio ` instance as * controller* and ` state ` .
44+
45+ ``` jsx
46+ < Audio autoPlay src= {src}> {(audio , state ) =>
47+
48+ }< / Audio>
49+ ```
50+
51+ First argument is the ` <Audio> ` component instance with the following public signature.
52+
53+ ``` ts
54+ interface IAudio {
55+ el: HTMLAudioElement ;
56+ play();
57+ pause();
58+ seek(time : number );
59+ volume(value : number );
60+ mute();
61+ unmute();
62+ }
63+ ```
64+
65+ , where
66+
67+ - ` el ` - ` <audio> ` element DOM node.
68+
69+ The second argument is the state of the ` <Audio> ` component with the following signature.
70+
71+ ``` ts
72+ interface IAudioState {
73+ time? : number ;
74+ duration? : number ;
75+ isPlaying? : boolean ;
76+ muted? : boolean ;
77+ volume? : number ;
78+ }
79+ ```
80+
81+ , where
82+
83+ - ` time ` - current time in seconds.
84+ - ` duration ` - total audio track duration in seconds.
85+ - ` isPlaying ` - whether the audio track is currently playing.
86+ - ` muted ` - whether ` muted ` attribute is set on the audio element.
87+ - ` volume ` - current volume in range ` [0..1] ` .
88+
89+
3990## Example
4091
4192Play a sample audio track with control buttons.
0 commit comments