Skip to content

Commit 5579919

Browse files
committed
feat: doc updated added ref
1 parent e756fd9 commit 5579919

File tree

3 files changed

+64
-5
lines changed

3 files changed

+64
-5
lines changed

documentation/docs/examples.md

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,51 @@ Preview
8181

8282
<small>Music Source: <a :href="music.getCurrentMusic().sourceLink" target="_blank">{{music.getCurrentMusic().title}}</a></small>
8383

84-
## Example 4: Darkmode using basic style props
84+
## Example 4: Usage with ref (available from v1.0.4)
85+
86+
```tsx
87+
import { useRef } from 'react';
88+
import { AudioPlayer, AudioPlayerRef } from 'react-audio-play';
89+
90+
function App() {
91+
const playerRef = useRef<AudioPlayerRef>(null);
92+
93+
const handlePlay = () => {
94+
playerRef.current?.play();
95+
};
96+
97+
const handlePause = () => {
98+
playerRef.current?.pause();
99+
};
100+
101+
const handleStop = () => {
102+
playerRef.current?.stop();
103+
};
104+
105+
const handleFocus = () => {
106+
playerRef.current?.focus();
107+
};
108+
109+
return (
110+
<div>
111+
<AudioPlayer ref={playerRef} src="path/to/audio.mp3" autoPlay />
112+
<button onClick={handlePlay}>Play</button>
113+
<button onClick={handlePause}>Pause</button>
114+
<button onClick={handleStop}>Stop</button>
115+
<button onClick={handleFocus}>Focus</button>
116+
</div>
117+
);
118+
}
119+
120+
```
121+
122+
Preview
123+
124+
<AudioPlayerRefExample :src="music.nextMusic().url"/>
125+
126+
<small>Music Source: <a :href="music.getCurrentMusic().sourceLink" target="_blank">{{music.getCurrentMusic().title}}</a></small>
127+
128+
## Example 5: Darkmode using basic style props
85129

86130
```js
87131
import { AudioPlayer } from "react-audio-play";
@@ -104,7 +148,7 @@ Preview
104148

105149
<small>Music Source: <a :href="music.getCurrentMusic().sourceLink" target="_blank">{{music.getCurrentMusic().title}}</a></small>
106150

107-
## Example 5: Using Style Object
151+
## Example 6: Using Style Object
108152

109153
```js
110154
import { AudioPlayer } from "react-audio-play";
@@ -127,7 +171,7 @@ Preview
127171

128172
<small>Music Source: <a :href="music.getCurrentMusic().sourceLink" target="_blank">{{music.getCurrentMusic().title}}</a></small>
129173

130-
## Example 6: Using Custom CSS
174+
## Example 7: Using Custom CSS
131175

132176
::: code-group
133177

@@ -183,7 +227,7 @@ Preview
183227

184228
<small>Music Source: <a :href="music.getCurrentMusic().sourceLink" target="_blank">{{music.getCurrentMusic().title}}</a></small>
185229

186-
## Example 7: More Playing With CSS
230+
## Example 8: More Playing With CSS
187231

188232
::: code-group
189233

@@ -255,6 +299,7 @@ Preview
255299
<script setup>
256300
import { Music } from './.vitepress/lib/Music.ts';
257301
import AudioPlayerWrapper from './.vitepress/components/AudioPlayerWrapper.vue';
302+
import AudioPlayerRefExample from './.vitepress/components/AudioPlayerRefExample.vue';
258303

259304
const music = new Music();
260305
</script>

documentation/docs/index.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,20 @@ The **AudioPlayer** component accepts the following props:
5252
| `width` | string, optional | The width of the audio player. For example, `"100%"`, `"300px"`, etc. |
5353
| `style` | object, optional | An object containing additional inline styles for the component. |
5454
55+
56+
## Advanced Usage
57+
58+
Starting with version `v1.0.4`, you can access certain actions of the `AudioPlayer` component programmatically using a `ref` with the following interface:
59+
60+
- `play`: Function to start audio playback.
61+
- `pause`: Function to pause audio playback.
62+
- `stop`: Function to stop the audio playback.
63+
- `focus`: Function to focus on the audio player component.
64+
65+
::: info
66+
[Example Here](/examples.html#example-4-usage-with-ref-available-from-v1-0-4)
67+
:::
68+
5569
## Keyboard Shortcuts
5670
5771
Below are the keyboard shortcuts available when the audio player is focused. They can be turned off by setting the `hasKeyBindings` prop to `false`.

documentation/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
},
1212
"dependencies": {
1313
"react": "^18.3.1",
14-
"react-audio-play": "^1.0.3",
14+
"react-audio-play": "^1.0.4",
1515
"react-dom": "^18.3.1"
1616
}
1717
}

0 commit comments

Comments
 (0)