// utility method that duck-punches Object // to handle object construction & inheritance if(typeof Object.beget !== 'function') { Object.beget = function(o) { var F = function() { }; F.prototype = o; return new F(); }; } // now to make a new object based on the prototype 'foo', we go // var bar = Object.beget(foo); var globaltime = -1; // flp_comm prototype // this object makes calls to the server and invokes the callback // provided by the object that intiated the call. var flp_comm = { label : 'flp_comm', url_base : 'http://player2.entropymedia.com', cache_url_base : 'http://www.pbs.org', session_key : "0", track_session : function(json_data) { if(json_data.ses != this.session_key) { this.session_key = json_data.ses; } }, getdir_fromcache : function(v) { $.jsonp({ callback : 'get_json', callbackParameter : 'callback', context : v, cache : false, success : v.load_data, error : function () { v.cblockcheck = true; }, //need to hack jquery to modify jsonp callback url : this.cache_url_base + '/wgbh/pages/frontline/.json/getdir/getdir' + v.pkg_id + '.json' })}, getdir_fromsvc : function(v) { v.cblockcheck = false; $.jsonp({ callback : 'get_json', callbackParameter : 'callback', success : v.load_data, context : v, error: function () { v.isblocked = true; v.loaded = true; }, url : this.url_base + '/json/core', data : {"method" : "getdir", "brn" : v.brand_id, "pkg" : v.pkg_id, "big" : 1} })}, getrel_fromcache : function(v) { $.jsonp({ callback : 'get_json', callbackParameter : 'callback', success : v.load_reldata, error : v.get_relc_from_svc, context : v, cache : false, url : this.cache_url_base + '/wgbh/pages/frontline/.json/getrel/getrels' + v.seg_id + '.json' })}, getrel_fromsvc : function(v) { $.jsonp({ callback : 'get_json', callbackParameter : 'callback', success : v.load_reldata, context : v, url : this.url_base + '/json/core', data : {"method" : "getrel", "seg" : v.seg_id, "pkg" : v.pkg_id} })}, sendlog : function(v,currenttime,sourcer) { $.jsonp({ callback : 'get_json', callbackParameter : 'callback', success : this.track_session, context : this, url : this.url_base + '/json/core', data : {"method" : "logtim", "seg" : v.seg_id, "pkg" : v.pkg_id, "ses" : this.session_key, "tim" : currenttime, "src" : sourcer } })} }; // video protoype var flp_video = { label : 'flp_video', loaded : false, relloaded : false, cblockcheck : false, isblocked : false, roundonefail : false, ispassword : false, mobilefriendly: false, fullshowmode: false, tp_media_id: 0, related_content : new Array(), jsondata : new Array(), pkg_id : 0, seg_id : 0, clean : function () { this.tp_media_id = 0; this.loaded = false; this.pkg_id = 0; this.seg_id = 0; this.jsondata.length = 0; }, parse_video_id : function(id) { this.rest_id = id; this.nola = id.substring(0,4); this.fullshow = (id.substring(7,8) == 'c' || id.substring(7,8) == 'o' || id.substring(7,8) == 'p')? true:false; this.brand_id = parseInt(id.substring(4,6), 16); if(id.substring(7,id.length).indexOf('q') != -1){ var rem = id.substring(7,id.length).split(/q/); this.pkg_id = parseInt(rem[1],16); this.seg_id = parseInt(rem[0],16); } else { this.fullshowmode = true; this.pkg_id = parseInt(id.substring(7,id.length),16); } return this; }, set_timer : function(t) { this.timer = t; }, get_data_from_server : function(server) { server.getdir_fromcache(this); return this; }, get_data_from_svc : function(server) { // if the above call fails (geoip blocking), the jsonpcallback will call this // to get data directly from the web service server.getdir_fromsvc(this); return this; }, get_relc_from_server : function(server) { server.getrel_fromcache(this); return this; }, get_relc_from_svc : function(server) { server.getrel_fromsvc(this); return this; }, load_data : function(data) { var haserror = false; if(data.error != null && data.error != ''){ haserror = true; if(data.error == 'access from this location is blocked'){ this.isblocked = true; } if(data.error == 'package requires password'){ this.ispassword = true; } } if(!haserror){ this.pkg_title = data.pkt; this.pkg_link = data.url; this.pkg_len = 0; this.brand_title = data.brt; this.itunes_link = data.itn; this.pkg_desc = data.pkd; this.embeddable = (data.emb == 1)? true:false; this.tp_media_id = parseInt(data.mid); this.progid = data.prgid; this.jsondata = data; // let's hang onto the json so we can load the other segments var i, seg; var fauxstartmode = (data.ditems[1] != undefined && data.ditems[1].tim == 0)? true:false; var tim = 0; for(i=0;i b }); for(var x = 0; x < rela.length; x++){ for(var y = 0; y < relc.length; y++){ if(rela[x] == relc[y].tim){ this.related_content.push(relc[y]); } } } this.relloaded = true; return this; } }; function jsbridge (msg){ if(console){ console.log(msg); } } var flp_player = { label : 'flp_player', mode : 'npa', receptive : false, chupdate_callback : null, htmlplayer : null, isinseek : false, currenttime : 0, isplaying: false, wasad: false, isready : false, playercode : 'npaplayer', chdata : {}, waitmode : false, tasks : {}, origin : '*', // this makes me so, so nervous updateIvl : 0, register_task : function(evt, func) { this.add_task_to_queue(func, evt); }, add_task_to_queue : function(func, evt) { this.tasks[evt] = func; }, legacy_player : function () { this.mode = 'npa'; var player_code = '
loading
'; return player_code; }, legacy_player_init : function(id,w,h,ap,emb,fullshow) { // w += 2; // compensate for skin width h += 32; // compensate for control height; this.isready = true; var subthis = this; var config = new Array(); this.receptive = true; config.pap_url = location.href; config.pap_ffw = w; config.pap_ffh = h; config.pap_legacymode = true; config.pap_hash = id; if(ap){ config.pap_play = true; } if(fullshow){ config.pap_fullshow = true; config.pap_arrowonly = true; } else { config.pap_fullshow = false; config.pap_standalone = true; config.pap_arrowonly = false; } if(!emb){ config.pap_relatedexternal = true; } else { config.pap_replay = true; } config.pap_usecache = true; config.pap_evtmgr = this.legacy_player_evthandle; swfobject.embedSWF("/wgbh/pages/frontline/video/flv/e11b.swf","npaplayer",w,h,"9.0.115.0",null,config, { 'wmode':'opaque', 'scale':'noscale', 'salign':'tl', 'menu':false, 'allowFullScreen':true, 'allowScriptAccess':'always' }, { id:'npap',name:'npap' }); }, legacy_player_evthandle : function (evt, ch) { if(evt == 'onPlay'){ this.flp_player.evthandle('playing'); this.flp_player.isplaying = true; } if(evt == 'onPause' || evt == 'onStop'){ this.flp_player.evthandle('paused'); this.flp_player.isplaying = false; } if(evt == 'onDone'){ this.flp_player.evthandle('ended'); this.flp_player.evthandle('endchapter'); this.flp_player.isplaying = false; } if(evt == 'onChapter'){ this.flp_player.evthandle('chapterup'); } }, cove_player : function() { this.mode = 'cove'; var player_code = '
loading
'; return player_code; }, cove_report : function (ev) { if(console){ console.log(ev); } }, cove_player_start : function(mediaid,w,h,ap,inchdata,st,en,extemb,override) { // h += 18; // compensate for control height; this.playercode = 'npaplayer'; var aptext = '&autoplay=true'; if(!ap){ aptext = '&autoplay=false' } if(override){ confinement = '&start=' + st; if(en){ confinement = '&end=' + en; } } var subthis = this; $("#npaplayer_outer").html(''); this.videowindow = document.getElementById('videoIframe').contentWindow; if (typeof window.addEventListener === 'function') { window.addEventListener("message", function(evt) { subthis.messagerouter(evt,subthis); }, false); } else { window.attachEvent("onmessage",function(evt) { subthis.messagerouter(evt,subthis); }); } if(!ap){ this.isplaying = false; } }, messagerouter : function (evt,subthis) { var data=evt.data,action=evt.data.split('::')[0],value=evt.data.split('::')[1]; if(action === "getPosition"){ globaltime = (parseInt(value)); } if(action === "initialized"){ // subthis.mediaready(); } if(action === "video"){ if(value === "playing"){ subthis.evthandle('playing'); clearInterval(subthis.updateIvl); subthis.updateIvl = setInterval(function () { subthis.videowindow.postMessage('getPosition', subthis.origin); }, 500); subthis.isplaying = true; } if(value === "paused"){ subthis.evthandle('paused'); clearInterval(subthis.updateIvl); subthis.isplaying = false; } if(value === "finished"){ subthis.evthandle('endchapter'); subthis.evthandle('ended'); clearInterval(subthis.updateIvl); subthis.isplaying = false; } } }, previous_clip : function () { // tpController.previousClip(); }, cove_timeupd : function (timeobj, thing) { thing.currenttime = parseInt(timeobj.data.currentTime / 1000); }, evthandle : function (caller) { if(caller != undefined){ if(this.tasks[caller]){ this.tasks[caller].call(); } } }, reset_player : function () { // tpController.resetPlayer(); }, adcheck : function () { if(this.mode == 'cove'){ var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window[this.playercode] } else { a=document[this.playercode] } return a.adstatus(); } }, isalive : function () { var ret = true; if(this.mode == 'cove'){ ret = false; var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window[this.playercode] } else { a=document[this.playercode] } try { var x = a.adstatus(); ret = true; } catch (e) { ret = false; } } this.trycount = 0; return ret; }, html5_player : function (filen,w,h,tmb,ap) { this.mode = 'html5'; if(filen.indexOf('http') == -1){ filen = 'http://www-tc.pbs.org' + filen; } var player_code = ''; this.receptive = true; return player_code; }, html5_evt : function () { this.htmlplayer = document.getElementById('npavid'); var subthis = this; this.htmlplayer.addEventListener('ended',function () { subthis.evthandle('endchapter'); subthis.evthandle('ended'); subthis.isplaying = false;},true); this.htmlplayer.addEventListener('error',function () { subthis.evthandle('error'); subthis.isplaying = false; },true); this.htmlplayer.addEventListener('playing',function () { subthis.evthandle('playing'); subthis.isplaying = true; },true); this.htmlplayer.addEventListener('pause',function () { subthis.evthandle('paused'); subthis.isplaying = false; },true); }, play : function () { if(this.mode == 'npa'){ // play goes here } else { if(this.mode == 'html5'){ this.htmlplayer.play(); } else { this.videowindow.postMessage('play', this.origin); } } }, playchapter : function (chidx,isfirst) { if(this.isready){ if(this.waitmode){ this.wait_stop(); } if(this.mode == 'cove'){ // tpController.seekToPosition(chdata[chidx]*1000); // tpController.pause(false); } else { var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window['npap'] } else { a=document['npap'] } a.chapterload(chidx+1,isfirst); } } else { var subthis = this; if(!this.waitmode){ this.wait_start(); } setTimeout(function () { subthis.playchapter(chidx,isfirst) }, 500); } }, wait_start : function () { this.waitmode = true; if($("#v_replacementthumb")){ $("#v_replacementthumb").html(''); $("#v_replacementthumb").show(); } }, wait_stop : function () { this.waitmode = false; if($("#v_replacementthumb")){ $("#v_replacementthumb").hide(); } $("#v_impatient").fadeOut("slow",function () { $("#v_impatient").html(''); $("#v_impatient").remove(); }); }, playbutton : function () { if(this.mode == 'cove'){ if(this.isready){ if(this.waitmode){ this.wait_stop(); } this.videowindow.postMessage('play', this.origin); } else { var subthis = this; if(!this.waitmode){ this.wait_start(); } setTimeout(function () { subthis.playbutton() }, 500); } } else { if(this.mode == 'npa'){ var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window['npap'] } else { a=document['npap'] } a.pap_play(); } else { this.htmlplayer.play(); } } }, receptiveness : function () { this.receptive = true; }, pause : function () { if(this.mode == 'cove'){ this.videowindow.postMessage('pause', this.origin); } else { if(this.mode == 'npa'){ var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window['npap'] } else { a=document['npap'] } a.pap_pause(); } else { this.htmlplayer.pause(); } } }, seek : function (seekpoint,dontplay,firsttime) { if(this.isready){ isinseek = false; if(this.mode == 'cove'){ var pt = parseInt(seekpoint); this.videowindow.postMessage('seek::'+pt, this.origin); if(!this.isplaying && !dontplay){ // if(!firsttime){ // this.thismovie('npaplayer').playerPlay(); // } else { // tpController.clickPlayButton(); // } } } else { // so far only cove supports seek } } else { isinseek = true; var subthis = this; var recreload = setTimeout(function () { subthis.seek(parseInt(seekpoint)) }, 500); } }, timerupdate : function () { if(this.mode == "cove"){ this.currenttime = globaltime; } if(this.receptive){ // cove time management via their onmediaplaying event if(this.mode == 'html5'){ this.currenttime = parseInt(this.htmlplayer.currentTime); } if(this.mode == 'npa'){ var a; if(navigator.appName.indexOf("Microsoft")!=-1) { a=window['npap'] } else { a=document['npap'] } var rett = a.gettime(); this.currenttime = parseInt(rett.showtime); } } return this.currenttime; }, chapterswitch : function (targetfile) { if(targetfile.indexOf('http') == -1){ targetfile = 'http://www-tc.pbs.org' + targetfile; } this.htmlplayer.autoplay = true; this.htmlplayer.src = targetfile; this.htmlplayer.load(); this.htmlplayer.play(); } };