
Stop rest players and play the current one when multiple players
How i can stop all players and play the current one? Here is my code
jQuery('.musicitem').each(function(){
var getCurrentMusicLink = jQuery(this).find('#getCurrentMusicLink').val();
var getCurrentPost = jQuery(this).find('#currentpostID').val();
var musicaudiotrack = jQuery(this).find('.musicaudiotrack');
var postid = "musicaudiowrap"+getCurrentPost;
var playerInstance = jwplayer(postid).setup({
width: "100%",
androidhls: 'true',
type: "hls",
fallback:true,
sources: [
{
file: getCurrentMusicLink,
}
],
pauseMedia : function(playingMediaId) {
jQuery('.musicaudioinnerwrap').find('.jwplayer, object').each(function(){
var currentMediaId = jQuery(this).attr('id');
if(jwplayer(this).getState() == "PLAYING" || jwplayer(this).getState() == "BUFFERING" ) {
if(currentMediaId != playingMediaId){
jwplayer(this).play(false);
}
}
});
},
autostart: false,
logo: {
hide: true
}
});
jQuery(this).find('.musicplaybutton').click(function(){
if(jQuery(this).parent().parent().parent().siblings().find('.musicaudioinnerwrap').is(':visible')){
jQuery(this).parent().parent().parent().siblings().find('.musicaudioinnerwrap').hide();
jQuery(this).parent().parent().parent().siblings().find('.musicaudiotracktopwrap').show();
}
jQuery(this).parent().hide();
jQuery(this).parent().parent().find('.musicaudioinnerwrap').show();
var currentmusictitle = jQuery(this).parent().parent().parent().find('.musictitlewrap .musicmaintitle').text();
var currentmusicpublisheddate = jQuery(this).parent().parent().parent().find('.musictitlewrap .publishtextmusic').html();
jQuery('.musicmaintitletop').text(currentmusictitle);
jQuery('.publishtextmusictop').html(currentmusicpublisheddate);
jwplayer().play();
});
});
I need some dynamic way of stopping all players and playing the clicked one.
Thanks in advance.