bbruman bbruman - 1 month ago 12
Javascript Question

Autoplay WordPress Audio Playlist (MediaElement.js)

WordPress does not offer an 'autoplay' option for the Audio playlists like they do single audio embeds.

Since WordPress is using MediaElement.js, there should be a work-around, yes?

I've searched around plenty and have not found a workable answer.

For example, Autoplay MediaElementPlayer

Lots of good variations there, but none seem to work with the WordPress playlist player element.

My lack of Javascript and jQuery is limited, but the CSS unique selector I've found on the playlist is

div.mejs-button.mejs-playpause-button.mejs-play > button

Therefore I was hoping a solution such as

$(document).ready(function() {
$("div.mejs-button.mejs-playpause-button.mejs-play > button").trigger('click');

at the top of the single-page template I have my player on - would work, but no avail.

Anyone know of a suitable work around for this? Since WP does not inherently support it, I'm assuming a javascript or jQuery solution is required. TY!


Here is the play control:

<div class="mejs-controls"><div class="mejs-button mejs-playpause-button mejs-play">
<button type="button" aria-controls="mep_0" title="Play" aria-label="Play"></button></div>


I was close.

<script type="text/javascript">
$(window).bind("load", function() {
$("div.mejs-button.mejs-playpause-button.mejs-play > button").trigger('click');

The solution was to use $(window).bind("load", function() instead of $(document).ready(function() so that the script is run only after the page has loaded.