-
-
Notifications
You must be signed in to change notification settings - Fork 96
New issue
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
Button Play doesn't work #169
Comments
Please fork the codepen example in README to reproduce this error, then I can take a look. |
I have the same issue - it looks like src isn't loaded properly during first render in dev-mode. Here's an example of it not working: |
I should add that it works in production (after build), just not in development mode (npm start) |
Interesting, while investigating another problem I noticed that on localhost I can not play the audio file. I also added an onPlay function, that just logs the clicking of the button, but apparently it does not even trigger, so the button is not clicked at all. And yes, in production it works fine (see vercel link) https://react-h5-audio-player.vercel.app/ One last thing, I use the audio player in another project for some months now and this never seem to be an issue. But I'm quiet sure, it is the same version, but there have been some commits inbetween, but only to the README I think |
i dont have codepen or sandbox account, the issue is like i said, if i press button play when you are developing the app in your local doesnt work, but the other two button works well. i put the code example. |
i see the code of brian and is bit similar of mine and he had the same problem |
This package has the same problem as all other not updated packages right now.
Alright, I got it fixed: Here is the PR: #179 |
Note: The good news is that this issue only affects dev build, and it works fine in production build. |
Interesting, that the audio player would keep playing after the component gets unmounted. Do you have more info on that? I think replacing the function to remove src with audio.pause() function is a valid solution. |
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 |
Published 3.8.6 |
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 (
<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}
/>
);
}
The text was updated successfully, but these errors were encountered: