question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Button Play doesn't work

See original GitHub issue

hello, im using the audio player, the button next and previous work well but, when i open at the first time or reloaded the web, the button play doesn’t load and play the first song, only works if i clicke previous or next. other doubt: i test the code in stackblitz with the code example and it works! and is the same i use in this example, but in my localhost doesnt work please help me 😦

here is my code:

import { useState } from “react”; import AudioPlayer from “react-h5-audio-player”; import “react-h5-audio-player/lib/styles.css”;

export default function AudioPlayerComponent() { const musicTracks = [ { name: “song1”, src: “https://res.cloudinary.com/mp3”, // only for the example }, { name: “song2”, src: “https://res.cloudinary.com/mp3”, // only for the example }, ];

const [trackIndex, setTrackIndex] = useState(0);

const handleClickPrevious = () => { setTrackIndex((currentTrack) => currentTrack === 0 ? musicTracks.length - 1 : currentTrack - 1 ); };

const handleClickNext = () => { setTrackIndex((currentTrack) => currentTrack < musicTracks.length - 1 ? currentTrack + 1 : 0 ); };

return ( <div className="audio"> <AudioPlayer style={{ backgroundColor: “transparent”, color: “purple”, fontFamily: “monospace”, marginTop: “-70px”, fontSize: “15px”, }} src={musicTracks[trackIndex].src} onPlay={musicTracks[trackIndex].src} showSkipControls={true} showJumpControls={false} header={Now playing: ${musicTracks[trackIndex].name}} onClickPrevious={handleClickPrevious} onClickNext={handleClickNext} onEnded={handleClickNext} /> </div> ); }

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:11 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
lhz516commented, Sep 24, 2022

Published 3.8.6

0reactions
lhz516commented, Sep 24, 2022

Oh never mind, I just tested it and found that the audio won’t stop when the component is destroyed. Let me just remove this line

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to fix play/pause button on keyboard not working?
How to fix play/pause button on keyboard not working? · Fix 1. Run keyboard troubleshooter · Fix 2. Disable Google Play Music (if...
Read more >
Solved: The play button doesn't work and I can't play anyt...
The play buttons are unresponsive and no play bar appears when I'm listening on my laptop. I can switch devices from laptop to...
Read more >
4 Methods For Resolving Audacity Play Button Not Working
We will be using this article to discussing some common solutions for the Audacity play button not working so that you can fix...
Read more >
What can I do if a play button doesn't work on dj equipment?
This video touches on some tips for DJs who don't know how to use DJ equipment if a play button doesn't work.I post...
Read more >
Play button doesn't work : r/gog - Reddit
Play button doesn't work. Hey there,. I just downloaded Slain: Back From Hell and can't get the game to run. The play button...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found