简体   繁体   中英

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!

edit:

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');
});
</script>

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM