I want to load jwplayer dynamically using jquery or javascript. I want to do this because the browser on which FLASH is not installed jwplayer in not behaving as expected.
Hence I want to check first whether flash player is installed or not into the browser if yes than only I want to load jwplayer.To check flash installed or not i m using below
var hashFlash=((typeof navigator.plugins != "undefined" && typeof navigator.plugins["Shockwave Flash"] == "object") || (window.ActiveXObject && (new ActiveXObject("ShockwaveFlash.ShockwaveFlash")) != false));
if hashFlash is true than only i will load jwplayer to play video/audio.
I am using below code to load jwplayer dynamically.
function loadjwplayer(filename) {
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("src", filename);
alert(fileref);
document.getElementsByTagName("head")[0].appendChild(fileref);
}
OR through jquery as below
$.getScript("/jwplayer/jwplayer.js");
After that i will add audio/video player into the we page as per requirement using below.
function load_jwplayer_skin( div_id, audio_file) {
jwplayer(div_id).setup({
file: audio_file,
flashplayer: "/jwplayer/jwplayer.flash.swf",
primary: "flash",
width: "350",
height: "25",
});
}
and use it into html as below
<div id='audio_1'>......</div>
<script>
load_jwplayer_skin('audio_1','my_fev_song.mp3');
</script>
But I am getting below error "Uncaught Referenceerror: Jwplayer is not defined inside function load_jwplayer_skin ".
The same is working fine if I load jwplayer using ..... at head of the page.Hence it seems me that jwplayer is not available in global scope.
Please someone suggest me how to proceed.