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.

Autoplay causing auto-restart when `src` is changed and `playing=true`

See original GitHub issue

If 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:closed
  • Created 7 years ago
  • Comments:12 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
Stenersoncommented, Aug 28, 2016

I’ve isolated the issue to be that we’re calling play() immediately after invoking autoplay. If I don’t call play() right after initializing, everything works great. I was also able to reproduce this in my JSBin as well by calling play() 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 not toggleHowler when the src is changing.

  componentWillReceiveProps (props) {
    if (props.src !== this.props.src) {
      this.initHowler(props)
    } else {
      this.toggleHowler(props) // Moved this into an else rather than always calling it
    }
  }
1reaction
thangngoc89commented, Aug 10, 2016

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

Read more comments on GitHub >

github_iconTop 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 >

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