Autoplay causing auto-restart when `src` is changed and `playing=true`
See original GitHub issueIf you change the source while playing=true, and then you pause and play again, you will notice the song restarts every time that you pause and replay.
To fix this simply remove autoplay from initHowler(). It’s not actually required because you call toggleHowler() right after which will handle “autoplaying” the track.
initHowler (props = this.props) {
this.destroyHowler()
if (typeof Howl !== 'undefined') { // Check if window is available
this.howler = new Howl({
src: props.src,
/* - autoplay: props.playing, <-- Remove me! */
mute: props.mute,
loop: props.loop,
onend: props.onEnd,
onplay: props.onPlay,
onpause: props.onPause,
onload: props.onLoad,
onloaderror: props.onLoadError
})
}
}
You can see a fork of the repo in which I made the change here: https://github.com/karlfloersch/react-howler – I didn’t submit a PR because I messed with the repo to get npm i --save https://github.com/karlfloersch/react-howler.git to work.
Issue Analytics
- State:
- Created 7 years ago
- Comments:12 (6 by maintainers)
Top Results From Across the Web
when <video> src is changed, video doesn't auto play on iOS
I have some code to change the src attr of a video on mobile. It looks like this: <div class="product-video--mobile swiper-slide"> <video ...
Read more >react-howler from thangngoc89 - GithubHelp
Autoplay causing auto-restart when `src` is changed and `playing=true `. If you change the source while playing=true, and then you pause and play...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found

I’ve isolated the issue to be that we’re calling
play()immediately after invokingautoplay. If I don’t callplay()right after initializing, everything works great. I was also able to reproduce this in my JSBin as well by callingplay()after auto starting.I’m going to open a Howler bug but we can also play a little more nicely with Howler by changing
componentWillReceiveProps()to nottoggleHowlerwhen the src is changing.Thanks for pointing this out. I’ll make a fix asap as well as install from github so you won’t need to mess around with the repo