I have a strange problem with the JWPlayer.
JavaScript:
$(document).ready(function ubsrt()
{
ktp_system = 0;
});
function mp3Player(v_url,v_title)
{
$('#console_box').append('<br />1-> start');
if(ktp_system == 1) // <--- Did not work
{
$('#console_box').append('1 = return false');
return false; // <--- Did not work
}
$('#console_box').append('<br />2-> '+ktp_system+'');
ktp_system['mp3Player'] = 1; //<--- fixed in the example to ktp_system = 1;
window.onbeforeunload = function() { return 'Es läuft noch ein Audio-Stream!' ; }
$('body').append('<div id="mp3Player" class="no_dra"></div>');
$.getScript('http://player.longtailvideo.com/jwplayer.js', function ()
{
jwplayer("mp3Player").setup({
flashplayer: "http://player.longtailvideo.com/player.swf",
file: ''+v_url+'',
autostart: "true",
height: 25,
width: 300,
controlbar: "bottom"
});
$('#mp3Player_wrapper').prepend('<div style="float:left;"><strong>MP3 Player</strong></div><div id="ktp_mp3player_close" onclick="window.onbeforeunload = null; jwplayer(\'mp3Player\').remove(); $(\'#mp3Player, #mp3Player_wrapper\').detach();" style="position:absolute; right:10px; top:10px; cursor:pointer; display:none; background-position:-32px -192px; height: 16px; width: 16px; " class="iconset"> </div><div style="clear:both;"></div><div id="ktp_mp3player_title" style="width:300px; overflow:hidden; margin-bottom:3px;" class="small">'+v_url+'</div>');
$('#mp3Player_wrapper').css('z-index','107').css('width','300px').css('position','absolute').css('padding','10px 10px 40px 10px').addClass('dra').addClass('bg_one');
$("#mp3Player_wrapper").hover( function () { $('#ktp_mp3player_close').show(); }, function () { $('#ktp_mp3player_close').hide(); });
$('#mp3Player').addClass('no_dra');
});
$('#console_box').append('<br />3-> '+ktp_system+'');
return false;
}
HTML:
<body>
<input type="button" onclick="mp3Player('http://chaosradio.ccc.de/archive/chaosradio_168.mp3');" value="play" />
<br /><br />
<div id="console_box"><hr /></div>
</body>
Working example: http://jsbin.com/opuvum/11/edit#preview
Everything works fine but when i press the play button again, my check if(ktp_system == 1) will be ignored … but why?
It is not your condition:
which is the problem. After the first click on the play button, the function
mp3Playernever gets called, and so your condition is not evaluated. You can see this withalertstatements added in the appropriate places, at the beginning ofmp3Player()and right after yourifclause:http://jsbin.com/ireret/2/edit
It appears the event listener for the button is not surviving. This is a result of something that happens in your
jwplayercall. You’ll notice that if you comment just that call out, it works as expected, and the condition is evaluated:http://jsbin.com/eqofil/2/edit
Somewhere along the line, the button’s
clickevent must be getting unbound. I didn’t wade through the minified jwplayer source to trace it further, but one way that fixes this is to use.click()or.live()to bind the click event to the button:http://jsbin.com/opuvum/14/edit
Hope this helps.