js/remote-player.js
changeset 21 007254e97333
parent 11 9833f3e24105
equal deleted inserted replaced
20:8b0a464fb5ac 21:007254e97333
     1 function Player() {
     1 function Player(dimensions) {
     2 	
     2 	
     3 	var events = {},
     3 	var events = {},
     4         self = this,
     4         self = this,
     5         loaded = false,
     5         loaded = false,
     6 //        tvWindow,
     6         tvWindow,
     7         destination = document.location.href.replace(/^(https?:\/\/[^\/]+).*$/,'$1'),
     7         destination = document.location.href.replace(/^(https?:\/\/[^\/]+).*$/,'$1'),
     8         timeAtLoad,
     8         timeAtLoad,
     9         timeDelta = 0,
     9         timeDelta = 0,
    10         timeOut,
    10         timeOut,
    11         playAtLoad = false;
    11         playAtLoad = false,
       
    12         winDimensions = dimensions || { left: 0, top: 0, width: 640, height:360 };
    12     
    13     
    13     this.currentTime = 0;
    14     this.currentTime = 0;
    14     this.duration = 0;
    15     this.duration = 0;
    15     this.paused = true;
    16     this.paused = true;
    16     
    17     
    63 			tvWindow.postMessage(msg, destination);
    64 			tvWindow.postMessage(msg, destination);
    64 		}
    65 		}
    65 	}
    66 	}
    66 	
    67 	
    67 	$(".tv").click(function() {
    68 	$(".tv").click(function() {
    68 		tvWindow = window.open("tv.html","TV","width=640,height=360,toolbar=0,location=0,status=0,titlebar=0");
    69 		tvWindow = window.open("tv.html","TV", _(winDimensions).reduce(function(mem, v, k) { return mem + k + "=" + v + "," },"") + "toolbar=0,location=0,status=0,titlebar=0");
    69 		window.addEventListener("message",receiveMessage,false);
    70 		window.addEventListener("message",receiveMessage,false);
    70 	});
    71 	});
       
    72 	
       
    73 	$(window).on("unload", function() {
       
    74 	    if (typeof tvWindow !== "undefined" && tvWindow) {
       
    75 	        tvWindow.close();
       
    76 	    }
       
    77 	})
    71 	
    78 	
    72 	this.setCurrentTime = function(t) {
    79 	this.setCurrentTime = function(t) {
    73 		if (loaded) {
    80 		if (loaded) {
    74 			sendMessage("timeupdate:" + t);
    81 			sendMessage("timeupdate:" + t);
    75 		} else {
    82 		} else {