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.

SetMusic() forces AutoPlay to true

See original GitHub issue


Calling setMusic on a paused player will automatically play the music, even with autoplay=false.

The Steps to Reproduce

  1. Load music into APlayer instance.
  2. Play music.
  3. Stop music.
  4. Change music loaded into APlayer (e.g.[0] = {...}).
  5. Call setMusic() (e.g. ap.setMusic(0)) to update the appearance of the player.

Expected Behavior: The player should reload the information (including metadata, if autoplay="metadata" was set) but should not begin playback. Actual Behavior: The player automatically begins playback.

Demo of the Problem

Please see this JSFiddle for an example. Do the following to see it:

  1. Press the Play button.
  2. Press the Pause button.
  3. Press the custom Swap button.

I don’t know why but the audio in the JSFiddle also won’t change. All other information properly changes but the loaded music does not update. Perhaps this is another bug?

Version Information

APlayer: 1.6.0 Browsers: All

Extra Information

This is likely caused by setting this.option.autoplay = true; at the end of the setMusic function. At the very least, that line should be guarded by a check for playlist, rather than a single loaded audio file. Another option would be to check the mode option for circulation or order.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:5 (5 by maintainers)

github_iconTop GitHub Comments

ericdrobinsoncommented, Dec 12, 2017

I’m working on a fix for this right now, actually, and will issue a PR soon.

The key insight is that autoplay is being used for multiple purposes:

  1. Whether to start the audio playback when the page loads.
  2. Whether to continue playing in a list context.

Whoops. Changing one affects the other! Rather, autoplay should only be checked during initialization (the constructor). Then, the second situation I outlined above can be handled in the code that calls setMusic, here. Wherever it makes sense, you simply add a call to after setMusic and it’s effectively the same thing (albeit safer).

In the case that someone clicks on a music entry in a playlist (whether the player is playing or stopped), the code already handles this by assuming the intention is to play the music (see this line).

That said, it would be useful to add an API for determining whether the APlayer instance was playing music or not. In that case, however, I’d suggest adding a member function like this:

isPlaying() {
    return !;

That would be faster than checking the state of the DOM…

ericdrobinsoncommented, Dec 31, 2017

Recommend closing this issue as it was fixed by #174.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to make audio autoplay on chrome - Stack Overflow
Solution #1. My solution here is to create an iframe <iframe src="audio/source.mp3" allow="autoplay" style="display:none" id="iframeAudio"> ...
Read more >
Autoplay guide for media and Web Audio APIs
This sets the autoplay property on the element to true , and when autoplay is ... This is done by calling the media...
Read more >
JS to force auto-playing in modern browsers
I activated an autoplay in a Joomla music player plugin and I also used JS ... true); audio.src = source; audio.autoplay = true;...
Read more >
Audio Autoplay in Chrome - The Enable Now Expert
The actual Chrome policy is: Autoplay with sound is (only) allowed if: The user has interacted with the domain (click, tap, etc.).
Read more >
HTML audio autoplay Attribute - W3Schools
The autoplay attribute is a boolean attribute. When present, the audio will automatically start playing as soon as it can do so without...
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 Post

No results found

github_iconTop Related Hashnode Post

No results found