forked from antonioru/beautiful-react-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
88 changed files
with
1,881 additions
and
1,438 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,49 @@ | ||
# useAudio | ||
|
||
Creates <audio> element, tracks its state and exposes playback controls. | ||
Creates an `<audio>` element, monitors its state and provides access to playback controls. | ||
|
||
### Why? 💡 | ||
|
||
- A quick way to use the `Audio` in your React components. | ||
- A speedy approach to integrating the audio feature into your React component | ||
- Enhances the readability of components involving the audio feature | ||
|
||
### Basic Usage: | ||
|
||
```jsx harmony | ||
import { useRef, useState } from 'react'; | ||
import { Button } from 'beautiful-react-ui'; | ||
import { Button, Typography } from 'antd'; | ||
import { PlayCircleFilled, PauseCircleFilled } from '@ant-design/icons'; | ||
|
||
import useAudio from 'beautiful-react-hooks/useAudio'; | ||
|
||
const UseAudioComponent = () => { | ||
const [state, controls] = useAudio("https://www.soundhelix.com/examples/mp3/SoundHelix-Song-1.mp3", { autoPlay: true }); | ||
const code = JSON.stringify(state, null, '\t'); | ||
|
||
const Actions = [ | ||
<Button onClick={controls.play} shape="round" icon={<PlayCircleFilled />} />, | ||
<Button onClick={controls.pause} shape="round" icon={<PauseCircleFilled />} />, | ||
<Button onClick={controls.mute}> | ||
Mute | ||
</Button>, | ||
<Button onClick={() => controls.setVolume(state.volume + 0.1)}>Vol +1</Button>, | ||
<Button onClick={() => controls.setVolume(state.volume - 0.1)}>Vol -1</Button>, | ||
<Button onClick={() => controls.seek(state.currentTime + 10)}>+10 secs</Button>, | ||
<Button onClick={() => controls.seek(state.currentTime - 10)}>-10 secs</Button> | ||
] | ||
|
||
return ( | ||
<DisplayDemo> | ||
{JSON.stringify(state, null, 2)} | ||
<br /> | ||
<Button onClick={controls.play}> | ||
Play | ||
</Button> | ||
<Button onClick={controls.pause}> | ||
Pause | ||
</Button> | ||
<br /> | ||
<Button onClick={controls.mute}> | ||
Mute | ||
</Button> | ||
<Button onClick={controls.unmute}> | ||
Unmute | ||
</Button> | ||
<br /> | ||
<Button onClick={() => controls.setVolume(.1)}>Volume: 10%</Button> | ||
<Button onClick={() => controls.setVolume(.5)}>Volume: 50%</Button> | ||
<Button onClick={() => controls.setVolume(1)}>Volume: 100%</Button> | ||
<br /> | ||
<Button onClick={() => controls.seek(state.currentTime + 10)}> | ||
Jump 10 seconds | ||
</Button> | ||
<Button onClick={() => controls.seek(state.currentTime - 10)}> | ||
Jump -10 seconds | ||
</Button> | ||
<DisplayDemo title="useAudio" actions={Actions}> | ||
<Typography.Paragraph code> | ||
<pre> | ||
{code} | ||
</pre> | ||
</Typography.Paragraph> | ||
</DisplayDemo> | ||
); | ||
}; | ||
|
||
<UseAudioComponent /> | ||
``` | ||
|
||
<!-- Types --> |
Oops, something went wrong.