We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
I have a custom button and I want to be able to make this audio player play when I click on it.
My current React code looks like this:
const audioPlayerRef = useRef(null); const onPlayClick = () => { // TODO: Make the player play from here audioPlayerRef.play(); } return ( <Button className='rounded-full bg-gray-600 w-[40px] h-[40px] p-0' title='Play audio' onClick={() => onPlayClick()} > <Play size={24} /> </Button> <AudioPlayer ref={audioPlayerRef} src={transcript.file_url} autoPlayAfterSrcChange={false} customAdditionalControls={[]} layout='stacked-reverse' className='custom-audio-player' ></AudioPlayer> )
How can I make it play from my custom button? I appreciate all your help.
The text was updated successfully, but these errors were encountered:
You can start/pause playback using this code:
const playerRef = useRef<AudioPlayer>(null); const [isPlaying, setIsPlaying] = useState<boolean>(false); const handlePlayPause = () => { if (isPlaying) { playerRef?.current?.audio?.current?.pause(); } else { playerRef?.current?.audio?.current?.play(); } };
To determine status of player, use onPlay and onPause to set isPlaying state
onPlay
onPause
Sorry, something went wrong.
Thanks a ton! @stepannemejc
No branches or pull requests
I have a custom button and I want to be able to make this audio player play when I click on it.
My current React code looks like this:
How can I make it play from my custom button? I appreciate all your help.
The text was updated successfully, but these errors were encountered: