File tree Expand file tree Collapse file tree 3 files changed +1881
-0
lines changed
docs/.vitepress/components Expand file tree Collapse file tree 3 files changed +1881
-0
lines changed Original file line number Diff line number Diff line change 1+ <template >
2+ <div ref =" el" />
3+ </template >
4+
5+ <script setup>
6+ import { createElement } from ' react' ;
7+ import { createRoot } from ' react-dom/client' ;
8+ import { ref , onMounted , defineProps } from ' vue' ;
9+ import AudioPlayerWithRef from ' ./AudioPlayerWithRef.jsx' ;
10+
11+ const props = defineProps ({
12+ src: {
13+ type: String ,
14+ required: true
15+ }
16+ });
17+
18+ const el = ref ();
19+
20+ onMounted (() => {
21+ const root = createRoot (el .value );
22+ root .render (createElement (AudioPlayerWithRef, { ... props }));
23+ });
24+ </script >
25+ <style >
26+ .audio-example-with-ref button {
27+ padding : 1px 10px ;
28+ background : white ;
29+ color : black ;
30+ border-radius : 5px ;
31+ margin-right : 3px ;
32+ margin-top : 5px ;
33+ box-shadow : 1px 1px 8px 3px #ececec ;
34+ }
35+
36+ .dark .audio-example-with-ref button {
37+ box-shadow : none ;
38+ }
39+
40+ .audio-example-with-ref button :hover {
41+ background : #ddd ;
42+ }
43+ </style >
Original file line number Diff line number Diff line change 1+ import React , { useRef } from 'react' ;
2+ import { AudioPlayer } from 'react-audio-play' ;
3+
4+ export default function AudioPlayerWithRef ( props ) {
5+ const playerRef = useRef ( null ) ;
6+
7+ const handlePlay = ( ) => {
8+ playerRef . current ?. play ( ) ;
9+ } ;
10+
11+ const handlePause = ( ) => {
12+ playerRef . current ?. pause ( ) ;
13+ } ;
14+
15+ const handleStop = ( ) => {
16+ playerRef . current ?. stop ( ) ;
17+ } ;
18+
19+ const handleFocus = ( ) => {
20+ playerRef . current ?. focus ( ) ;
21+ } ;
22+
23+ return (
24+ < div className = 'audio-example-with-ref' >
25+ < AudioPlayer ref = { playerRef } src = { props . src } />
26+ < button onClick = { handlePlay } > Play</ button >
27+ < button onClick = { handlePause } > Pause</ button >
28+ < button onClick = { handleStop } > Stop</ button >
29+ < button onClick = { handleFocus } > Focus</ button >
30+ </ div >
31+ ) ;
32+ }
You can’t perform that action at this time.
0 commit comments