Skip to content
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

Click on Play button after a pause restart the sound #92

Open
jlariza opened this issue Nov 29, 2018 · 8 comments
Open

Click on Play button after a pause restart the sound #92

jlariza opened this issue Nov 29, 2018 · 8 comments
Labels

Comments

@jlariza
Copy link

jlariza commented Nov 29, 2018

Good day,

I am using the AWSSoundPlayer example to create a soundplayer.

However, everytime I click on the play button after I have paused the sound, it starts all over again, the currentTime goes back to zero. Is it possible to keep the time state?

Thank you

@voronianski
Copy link
Member

@jlariza are you sure that you pass all props properly? Also sharing code snippet would be helpful.

@jlariza
Copy link
Author

jlariza commented Nov 30, 2018

@voronianski I am using the same example, the only difference is that I am using a different url for the soundtrack.

@tbarshchovskyi-elopage
Copy link

tbarshchovskyi-elopage commented Feb 4, 2019

+1, same issue.
I use this type of url
} else if (this._track) { src = this._track.stream_url; }

Any update here? @voronianski @jlariza

@naveensomanna
Copy link

@jlariza I have the same issue did u get that solution?

@xanderjakeq
Copy link

Having a similar issue. pause/play works fine at first, but when the streamUrl is changed, pause, then click play, it will play the previous streamUrl.

my whole component:

const Player = props => {

	const {soundCloudAudio, streamUrl, trackTitle, currentTime, duration} = props;

	const [autoPlay, setAutoPlay] = useState(true);
	const [playing, setPlaying] = useState(false);

	const prevUrl = usePrevious(streamUrl);

	useEffect(() => {
		if(autoPlay){
			soundCloudAudio.play({streamUrl});
			setAutoPlay(false);
			setPlaying(true);
		} 
		if(prevUrl !== streamUrl) {
			setAutoPlay(true);
		}
	},[streamUrl])

	return (
		<PlayerContainer>
			<div id = 'options-container'>
				<PlayButton 
						{...props} 
						playing = {playing}
						onTogglePlay = {() => {
							setPlaying(!playing)
						}}
						className="playButton"/>
				<PrevButton {...props}/>
				<h2>{trackTitle}</h2>
				<Timer {...props}/>
			</div>
			<Progress 
					{...props}
					className = 'progressBarContainer'
					innerClassName = 'progress'
					value = {(currentTime/duration)*100 || 0}/>
		</PlayerContainer>
	);

	// referenced https://stackoverflow.com/questions/53446020/how-to-compare-oldvalues-and-newvalues-on-react-hooks-useeffect
	function usePrevious(value) {
		const ref = useRef();
		useEffect(() => {
		  ref.current = value;
		});
		return ref.current;
	}
};

@hassanamin994
Copy link

hassanamin994 commented May 29, 2019

I faced the same issue on the Progress example, a small workaround i used was to stop re-rendering the component by setting a key attribute on it

here's a code sample

<ProgressSoundPlayer
key={progress-player-stream-${this.getStreamUrl()}}
streamUrl={this.getStreamUrl()}
/>

and inside the ProgressSoundPlayer component, set a key attribute on all the sub components i used

<PlayButton
className="flex-none h5 button button-transparent button-grow rounded"
{...this.props}
key={progress-player-play-${this.props.streamUrl}}
/>

@rsxdalv
Copy link

rsxdalv commented Nov 27, 2019

Tried the key method, but can't get it to stop rerendering

@yuredev
Copy link

yuredev commented Dec 26, 2020

I am facing the same issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants