Search code examples
jqueryprettyphotoaudio-playersoundcloud-stratus

External click event to pause query audio player


So basically I have Stratus2 media player running on a parallax website. There are other media files accessible within the website as well (youtube videos that play in prettyPhoto lightbox). Is there a function that can pause the Stratus player, whenever the user clicks on these media files?

$('.video').click(function() {

 $.stratus.stop()

}
)

Solution

  • Include the above mentioned library along with jQuery in your page. Now suppose each of the media elements on your page have a class "media" applied to them. Now the following code will publish an event on click of any of these items..

     $(".media").click(function() { 
        jQuery.pubsub.publish('media.clicked', {});
     });
    

    and the following code will be required to subscribe to this event published above and stop the previous media from playing.

    jQuery.pubsub.subscribe('media.clicked', function(topic, msg){
        $.stratus.stop();
    });