wpse-playlist icon indicating copy to clipboard operation
wpse-playlist copied to clipboard

Disable loop?

Open cyberfunk opened this issue 7 years ago • 7 comments

Hello, I made a big mistake and listened to my podcast using cellular data. My phone plan is limited so when I fell asleep the hour long podcast played in a loop for several hours eating up cellular data and I woke up to new charges to my account:-O How do I stop the player from looping so other listeners won't have similar blunders?

cyberfunk avatar Jan 16 '17 18:01 cyberfunk

Hi @cyberfunk

Sorry to hear about that.

This loop is hardcoded into the native playlist in the WordPress core:

https://github.com/WordPress/WordPress/blob/fe0b8a2aaf49ff5f33a866309ed8730fd7675674/wp-includes/js/mediaelement/wp-playlist.js

Maybe you see a way there to override the Backbone view through a plugin?

birgire avatar Feb 10 '17 17:02 birgire

I think the else-part here is responsible for the looping:

ended : function () {
   if ( this.index + 1 < this.tracks.length ) {
       this.next();
    } else {
        this.index = 0;
        this.setCurrent();
    }
},

birgire avatar Feb 10 '17 17:02 birgire

Hi @birgire thanks for your input on the matter. I found a solution on a stackoverflow forum that worked perfectly. I can't add the code here because GitHub keeps truncating it even using the insert code feature but you can find it at the bottom of this page: http://stackoverflow.com/questions/37012165/how-to-stop-the-wordpress-audio-playlist-from-playing-the-next-soundtracks-autom it's the code that has 99 at the end.

cyberfunk avatar Feb 10 '17 18:02 cyberfunk

@cyberfunk thanks for sharing the solution that worked for you.

I will check it out, though the first test gave me an error:

Uncaught (in promise) DOMException: The play() request was interrupted by a call to pause().

birgire avatar Feb 10 '17 19:02 birgire

The solution that worked first for me was at the very top of that page:

change (this.index=0,this.setCurrent())} to (this.index=0)} in one of the core wordpress files. The only trouble with that is the file is replaced everytime you update or reinstall wordpress. I needed a permanent solution and the code at the bottom worked. Are you saying that it does not work for you?

cyberfunk avatar Feb 10 '17 20:02 cyberfunk

This was the code I tested:

add_action( 'wp_footer', function () {
?>
<script>
jQuery(function ($) {
    $('.mejs-mediaelement audio').on('ended', function (e) {
        e.preventDefault();
        $(this)[0].player.pause();
    });
});
</script>
<?php
},99);

but it throws the above javascript error for me.

yes, we should avoid core modifications.

birgire avatar Feb 11 '17 10:02 birgire

Are you using the default WordPress audio player? Also be very careful where you paste the code. Double check that it's not posted in the middle of another code string/sentence. You also might have a conflict with another plugin depending on what you've installed and your themes default plugins. There are so many moving parts with WordPress it's challenging to trouble shoot another individuals unique theme/setup.

cyberfunk avatar Feb 11 '17 11:02 cyberfunk

As there has not been activity on this ticket for a long time, I close it for now, but welcome to open in the future.

birgire avatar Jan 15 '23 13:01 birgire