// ------------------------------------------------------------------------------------------- // // avia player // // ------------------------------------------------------------------------------------------- (function($) { "use strict"; var autostarted = false, container = null, monitorstart = function( container ) { var play_pause = container.find('.av-player-player-container .mejs-playpause-button'); if( play_pause.length == 0 ) { settimeout( function(){ monitorstart( container ); }, 200 ); } if( ! play_pause.hasclass('mejs-pause') ) { play_pause.trigger( 'click' ); } }; $.fn.aviaplayer = function( options ) { if( ! this.length ) return; return this.each(function() { var _self = {}; _self.container = $( this ); _self.stoploop = false; _self.container.find('audio').on('play', function() { if( _self.stoploop ) { this.pause(); _self.stoploop = false; } }); if( _self.container.hasclass( 'avia-playlist-no-loop' ) ) { _self.container.find('audio').on('ended', function() { // find the last track in the playlist so that when the last track ends we can pause the audio object var lasttrack = _self.container.find('.wp-playlist-tracks .wp-playlist-item:last a'); if ( this.currentsrc === lasttrack.attr('href') ) { _self.stoploop = true; } }); } /** * limit autostart to the first player with this option set only * * dom is not loaded completely and we have no event when player is loaded. * we check for play button and perform a click */ if( _self.container.hasclass( 'avia-playlist-autoplay' ) && ! autostarted ) { if( ( _self.container.css('display') == 'none') || ( _self.container.css("visibility") == "hidden" ) ) { return; } autostarted = true; settimeout( function(){ monitorstart( _self.container, _self ); }, 200 ); } }); }; }(jquery));