diff options
| -rw-r--r-- | res/client.js | 127 | ||||
| -rw-r--r-- | src/client/Buttons.hx | 12 | ||||
| -rw-r--r-- | src/client/IPlayer.hx | 1 | ||||
| -rw-r--r-- | src/client/Player.hx | 22 | ||||
| -rw-r--r-- | src/client/players/Iframe.hx | 6 | ||||
| -rw-r--r-- | src/client/players/Raw.hx | 38 | ||||
| -rw-r--r-- | src/client/players/Youtube.hx | 10 |
7 files changed, 118 insertions, 98 deletions
diff --git a/res/client.js b/res/client.js index 2f9b418..8161f26 100644 --- a/res/client.js +++ b/res/client.js @@ -730,8 +730,14 @@ client_Buttons.initNavBar = function(main) { var swapLayoutBtn = window.document.querySelector("#swapLayoutBtn"); swapLayoutBtn.onclick = function(e5) { var p = window.document.querySelector("#main"); - p.insertBefore(p.children[2],p.children[0]); - p.insertBefore(p.children[2],p.children[1]); + if(window.document.querySelector("#main").firstElementChild == window.document.querySelector("#chatwrap")) { + p.appendChild(p.removeChild(p.children[1])); + p.appendChild(p.removeChild(p.children[0])); + p.appendChild(p.removeChild(p.children[1])); + } else { + p.insertBefore(p.children[2],p.children[0]); + p.insertBefore(p.children[2],p.children[1]); + } var p1 = window.document.querySelector("#controlsrow"); p1.insertBefore(p1.children[1],p1.children[0]); var p2 = window.document.querySelector("#playlistrow"); @@ -1647,7 +1653,6 @@ var client_Player = function(main) { this.skipSetTime = false; this.isLoaded = false; this.itemPos = 0; - this.currentSrc = ""; this.playerEl = window.document.querySelector("#ytapiplayer"); this.videoItemsEl = window.document.querySelector("#queue"); this.items = _$VideoList_VideoList_$Impl_$._new(); @@ -1727,7 +1732,6 @@ client_Player.prototype = { } this.itemPos = i; childs[this.itemPos].classList.add("queue_active"); - this.currentSrc = item.url; this.isLoaded = false; this.player.loadVideo(item); client_JsApi.fireVideoChangeEvents(item); @@ -1735,7 +1739,6 @@ client_Player.prototype = { } ,removeVideo: function() { client_JsApi.fireVideoRemoveEvents(this.items[this.itemPos]); - this.currentSrc = ""; this.player.removeVideo(); window.document.querySelector("#currenttitle").textContent = Lang.get("nothingPlaying"); } @@ -1852,6 +1855,7 @@ client_Player.prototype = { return this.items; } ,setItems: function(list,pos) { + var currentUrl = this.itemPos >= this.items.length ? "" : this.items[this.itemPos].url; this.clearItems(); if(pos != null) { this.itemPos = pos; @@ -1861,7 +1865,7 @@ client_Player.prototype = { } var _g = 0; while(_g < list.length) this.addVideoItem(list[_g++],true); - if(this.currentSrc != this.items[this.itemPos].url) { + if(currentUrl != this.items[this.itemPos].url) { this.setVideo(this.itemPos); } else { this.videoItemsEl.children[this.itemPos].classList.add("queue_active"); @@ -1920,6 +1924,12 @@ client_Player.prototype = { ,hasVideo: function() { return this.playerEl.children.length != 0; } + ,getDuration: function() { + if(this.itemPos >= this.items.length) { + return 0; + } + return this.items[this.itemPos].duration; + } ,play: function() { if(!this.main.isSyncActive) { return; @@ -1927,6 +1937,9 @@ client_Player.prototype = { if(this.player == null) { return; } + if(!this.player.isVideoLoaded()) { + return; + } this.player.play(); } ,pause: function() { @@ -1936,18 +1949,18 @@ client_Player.prototype = { if(this.player == null) { return; } - this.player.pause(); - } - ,getDuration: function() { - if(this.itemPos >= this.items.length) { - return 0; + if(!this.player.isVideoLoaded()) { + return; } - return this.items[this.itemPos].duration; + this.player.pause(); } ,getTime: function() { if(this.player == null) { return 0; } + if(!this.player.isVideoLoaded()) { + return 0; + } return this.player.getTime(); } ,setTime: function(time,isLocal) { @@ -1960,6 +1973,9 @@ client_Player.prototype = { if(this.player == null) { return; } + if(!this.player.isVideoLoaded()) { + return; + } this.skipSetTime = isLocal; this.player.setTime(time); } @@ -1967,6 +1983,9 @@ client_Player.prototype = { if(this.player == null) { return 1; } + if(!this.player.isVideoLoaded()) { + return 1; + } return this.player.getPlaybackRate(); } ,setPlaybackRate: function(rate,isLocal) { @@ -1979,6 +1998,9 @@ client_Player.prototype = { if(this.player == null) { return; } + if(!this.player.isVideoLoaded()) { + return; + } this.skipSetRate = isLocal; this.player.setPlaybackRate(rate); } @@ -2132,6 +2154,9 @@ client_players_Iframe.prototype = { this.playerEl.removeChild(this.video); this.video = null; } + ,isVideoLoaded: function() { + return this.video != null; + } ,play: function() { } ,pause: function() { @@ -2190,20 +2215,36 @@ client_players_Raw.prototype = { var url = this.main.tryLocalIp(item.url); if(this.video != null) { this.video.src = url; + this.restartControlsHider(); return; } this.video = window.document.createElement("video"); this.video.id = "videoplayer"; this.video.src = url; + this.restartControlsHider(); + this.video.oncanplaythrough = ($_=this.player,$bind($_,$_.onCanBePlayed)); + this.video.onseeking = ($_=this.player,$bind($_,$_.onSetTime)); + this.video.onplay = function(e) { + _gthis.playAllowed = true; + _gthis.player.onPlay(); + return; + }; + this.video.onpause = ($_=this.player,$bind($_,$_.onPause)); + this.video.onratechange = ($_=this.player,$bind($_,$_.onRateChange)); + this.playerEl.appendChild(this.video); + } + ,restartControlsHider: function() { + var _gthis = this; + if(client_Utils.isTouch()) { + return; + } this.video.controls = true; if(this.controlsHider != null) { this.controlsHider.stop(); } - if(!client_Utils.isTouch()) { - this.controlsHider = haxe_Timer.delay(function() { - return _gthis.video.controls = false; - },3000); - } + this.controlsHider = haxe_Timer.delay(function() { + return _gthis.video.controls = false; + },3000); this.video.onmousemove = function(e) { if(_gthis.controlsHider != null) { _gthis.controlsHider.stop(); @@ -2211,16 +2252,6 @@ client_players_Raw.prototype = { _gthis.video.controls = true; return _gthis.video.onmousemove = null; }; - this.video.oncanplaythrough = ($_=this.player,$bind($_,$_.onCanBePlayed)); - this.video.onseeking = ($_=this.player,$bind($_,$_.onSetTime)); - this.video.onplay = function(e1) { - _gthis.playAllowed = true; - _gthis.player.onPlay(); - return; - }; - this.video.onpause = ($_=this.player,$bind($_,$_.onPause)); - this.video.onratechange = ($_=this.player,$bind($_,$_.onRateChange)); - this.playerEl.appendChild(this.video); } ,removeVideo: function() { if(this.video == null) { @@ -2229,11 +2260,11 @@ client_players_Raw.prototype = { this.playerEl.removeChild(this.video); this.video = null; } + ,isVideoLoaded: function() { + return this.video != null; + } ,play: function() { var _gthis = this; - if(this.video == null) { - return; - } if(!this.playAllowed) { return; } @@ -2246,33 +2277,18 @@ client_players_Raw.prototype = { }); } ,pause: function() { - if(this.video == null) { - return; - } this.video.pause(); } ,getTime: function() { - if(this.video == null) { - return 0; - } return this.video.currentTime; } ,setTime: function(time) { - if(this.video == null) { - return; - } this.video.currentTime = time; } ,getPlaybackRate: function() { - if(this.video == null) { - return 1; - } return this.video.playbackRate; } ,setPlaybackRate: function(rate) { - if(this.video == null) { - return; - } this.video.playbackRate = rate; } }; @@ -2502,40 +2518,25 @@ client_players_Youtube.prototype = { } this.video = null; } + ,isVideoLoaded: function() { + return this.isLoaded; + } ,play: function() { - if(!this.isLoaded) { - return; - } this.youtube.playVideo(); } ,pause: function() { - if(!this.isLoaded) { - return; - } this.youtube.pauseVideo(); } ,getTime: function() { - if(!this.isLoaded) { - return 0; - } return this.youtube.getCurrentTime(); } ,setTime: function(time) { - if(!this.isLoaded) { - return; - } this.youtube.seekTo(time,true); } ,getPlaybackRate: function() { - if(!this.isLoaded) { - return 1; - } return this.youtube.getPlaybackRate(); } ,setPlaybackRate: function(rate) { - if(!this.isLoaded) { - return; - } this.youtube.setPlaybackRate(rate); } }; diff --git a/src/client/Buttons.hx b/src/client/Buttons.hx index 8a1264e..a7dd4e1 100644 --- a/src/client/Buttons.hx +++ b/src/client/Buttons.hx @@ -262,8 +262,16 @@ class Buttons { final swapLayoutBtn = ge("#swapLayoutBtn"); swapLayoutBtn.onclick = e -> { final p = ge("#main"); - p.insertBefore(p.children[2], p.children[0]); - p.insertBefore(p.children[2], p.children[1]); + if (ge("#main").firstElementChild == ge("#chatwrap")) { + // do not remove videowrap with insertBefore + // because this will recreate iframe-based players + p.appendChild(p.removeChild(p.children[1])); // gutter + p.appendChild(p.removeChild(p.children[0])); // chat + p.appendChild(p.removeChild(p.children[1])); // clear + } else { + p.insertBefore(p.children[2], p.children[0]); + p.insertBefore(p.children[2], p.children[1]); + } final p = ge("#controlsrow"); p.insertBefore(p.children[1], p.children[0]); final p = ge("#playlistrow"); diff --git a/src/client/IPlayer.hx b/src/client/IPlayer.hx index a620567..4cdcb0b 100644 --- a/src/client/IPlayer.hx +++ b/src/client/IPlayer.hx @@ -8,6 +8,7 @@ interface IPlayer { function getVideoData(url:String, callback:(data:VideoData)->Void):Void; function loadVideo(item:VideoItem):Void; function removeVideo():Void; + function isVideoLoaded():Bool; function play():Void; function pause():Void; function getTime():Float; diff --git a/src/client/Player.hx b/src/client/Player.hx index d4ed854..c853464 100644 --- a/src/client/Player.hx +++ b/src/client/Player.hx @@ -21,7 +21,6 @@ class Player { final videoItemsEl = ge("#queue"); final playerEl:Element = ge("#ytapiplayer"); var player:Null<IPlayer>; - var currentSrc = ""; var itemPos = 0; var isLoaded = false; var skipSetTime = false; @@ -118,7 +117,6 @@ class Player { itemPos = i; childs[itemPos].classList.add("queue_active"); - currentSrc = item.url; isLoaded = false; player.loadVideo(item); JsApi.fireVideoChangeEvents(item); @@ -127,7 +125,6 @@ class Player { public function removeVideo():Void { JsApi.fireVideoRemoveEvents(items[itemPos]); - currentSrc = ""; player.removeVideo(); ge("#currenttitle").textContent = Lang.get("nothingPlaying"); } @@ -261,11 +258,12 @@ class Player { } public function setItems(list:Array<VideoItem>, ?pos:Int):Void { + final currentUrl = itemPos >= items.length ? "" : items[itemPos].url; clearItems(); if (pos != null) itemPos = pos; if (list.length == 0) return; for (video in list) addVideoItem(video, true); - if (currentSrc != items[itemPos].url) setVideo(itemPos); + if (currentUrl != items[itemPos].url) setVideo(itemPos); else videoItemsEl.children[itemPos].classList.add("queue_active"); } @@ -321,43 +319,49 @@ class Player { return playerEl.children.length != 0; } + public function getDuration():Float { + if (itemPos >= items.length) return 0; + return items[itemPos].duration; + } + public function play():Void { if (!main.isSyncActive) return; if (player == null) return; + if (!player.isVideoLoaded()) return; player.play(); } public function pause():Void { if (!main.isSyncActive) return; if (player == null) return; + if (!player.isVideoLoaded()) return; player.pause(); } - public function getDuration():Float { - if (itemPos >= items.length) return 0; - return items[itemPos].duration; - } - public function getTime():Float { if (player == null) return 0; + if (!player.isVideoLoaded()) return 0; return player.getTime(); } public function setTime(time:Float, isLocal = true):Void { if (!main.isSyncActive) return; if (player == null) return; + if (!player.isVideoLoaded()) return; skipSetTime = isLocal; player.setTime(time); } public function getPlaybackRate():Float { if (player == null) return 1; + if (!player.isVideoLoaded()) return 1; return player.getPlaybackRate(); } public function setPlaybackRate(rate:Float, isLocal = true):Void { if (!main.isSyncActive) return; if (player == null) return; + if (!player.isVideoLoaded()) return; skipSetRate = isLocal; player.setPlaybackRate(rate); } diff --git a/src/client/players/Iframe.hx b/src/client/players/Iframe.hx index 1bb9855..3268a61 100644 --- a/src/client/players/Iframe.hx +++ b/src/client/players/Iframe.hx @@ -35,7 +35,7 @@ class Iframe implements IPlayer { removeVideo(); video = document.createDivElement(); video.id = "videoplayer"; - video.innerHTML = item.url; + video.innerHTML = item.url; // actually data if (video.firstChild.nodeName != "IFRAME" && video.firstChild.nodeName != "OBJECT") { // TODO move to getVideoData too @@ -54,6 +54,10 @@ class Iframe implements IPlayer { video = null; } + public function isVideoLoaded():Bool { + return video != null; + } + public function play():Void {} public function pause():Void {} diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx index e3c2ed1..4fa000b 100644 --- a/src/client/players/Raw.hx +++ b/src/client/players/Raw.hx @@ -27,7 +27,7 @@ class Raw implements IPlayer { } public function getVideoData(url:String, callback:(data:VideoData)->Void):Void { - var title = url.substr(url.lastIndexOf('/') + 1); + var title = url.substr(url.lastIndexOf("/") + 1); final matchName = ~/^(.+)\./; if (matchName.match(title)) title = matchName.matched(1); else title = Lang.get("rawVideo"); @@ -52,21 +52,13 @@ class Raw implements IPlayer { final url = main.tryLocalIp(item.url); if (video != null) { video.src = url; + restartControlsHider(); return; } video = document.createVideoElement(); video.id = "videoplayer"; video.src = url; - video.controls = true; - if (controlsHider != null) controlsHider.stop(); - if (!Utils.isTouch()) controlsHider = Timer.delay(() -> { - video.controls = false; - }, 3000); - video.onmousemove = e -> { - if (controlsHider != null) controlsHider.stop(); - video.controls = true; - video.onmousemove = null; - } + restartControlsHider(); video.oncanplaythrough = player.onCanBePlayed; video.onseeking = player.onSetTime; video.onplay = e -> { @@ -78,14 +70,31 @@ class Raw implements IPlayer { playerEl.appendChild(video); } + function restartControlsHider():Void { + if (Utils.isTouch()) return; + video.controls = true; + if (controlsHider != null) controlsHider.stop(); + controlsHider = Timer.delay(() -> { + video.controls = false; + }, 3000); + video.onmousemove = e -> { + if (controlsHider != null) controlsHider.stop(); + video.controls = true; + video.onmousemove = null; + } + } + public function removeVideo():Void { if (video == null) return; playerEl.removeChild(video); video = null; } + public function isVideoLoaded():Bool { + return video != null; + } + public function play():Void { - if (video == null) return; if (!playAllowed) return; final promise = video.play(); if (promise == null) return; @@ -96,27 +105,22 @@ class Raw implements IPlayer { } public function pause():Void { - if (video == null) return; video.pause(); } public function getTime():Float { - if (video == null) return 0; return video.currentTime; } public function setTime(time:Float):Void { - if (video == null) return; video.currentTime = time; } public function getPlaybackRate():Float { - if (video == null) return 1; return video.playbackRate; } public function setPlaybackRate(rate:Float):Void { - if (video == null) return; video.playbackRate = rate; } diff --git a/src/client/players/Youtube.hx b/src/client/players/Youtube.hx index 3ea0e72..0aa9f2b 100644 --- a/src/client/players/Youtube.hx +++ b/src/client/players/Youtube.hx @@ -235,33 +235,31 @@ class Youtube implements IPlayer { video = null; } + public function isVideoLoaded():Bool { + return isLoaded; + } + public function play():Void { - if (!isLoaded) return; youtube.playVideo(); } public function pause():Void { - if (!isLoaded) return; youtube.pauseVideo(); } public function getTime():Float { - if (!isLoaded) return 0; return youtube.getCurrentTime(); } public function setTime(time:Float):Void { - if (!isLoaded) return; youtube.seekTo(time, true); } public function getPlaybackRate():Float { - if (!isLoaded) return 1; return youtube.getPlaybackRate(); } public function setPlaybackRate(rate:Float):Void { - if (!isLoaded) return; youtube.setPlaybackRate(rate); } |
