From 8c739fa43946ba8cc5bc6c6226032154b9481a40 Mon Sep 17 00:00:00 2001 From: RblSb Date: Thu, 27 Feb 2020 20:24:51 +0300 Subject: Permanent items and player abstraction --- src/client/players/Raw.hx | 72 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/client/players/Raw.hx (limited to 'src/client/players') diff --git a/src/client/players/Raw.hx b/src/client/players/Raw.hx new file mode 100644 index 0000000..41b421c --- /dev/null +++ b/src/client/players/Raw.hx @@ -0,0 +1,72 @@ +package client.players; + +import haxe.Timer; +import js.html.Element; +import js.html.VideoElement; +import js.Browser.document; +import client.Main.ge; +import Types.VideoItem; + +class Raw implements IPlayer { + + final main:Main; + final player:Player; + var video:VideoElement; + final playerEl:Element = ge("#ytapiplayer"); + + public function new(main:Main, player:Player) { + this.main = main; + this.player = player; + } + + public function loadVideo(item:VideoItem):Void { + video = document.createVideoElement(); + video.id = "videoplayer"; + final url = main.tryLocalIp(item.url); + video.src = url; + video.controls = true; + final isTouch = untyped __js__("'ontouchstart' in window"); + if (!isTouch) Timer.delay(() -> { + video.controls = false; + video.onmouseover = e -> { + video.controls = true; + video.onmouseover = null; + video.onmousemove = null; + } + video.onmousemove = video.onmouseover; + }, 3000); + video.oncanplaythrough = player.onCanBePlayed; + video.onseeking = player.onSetTime; + video.onplay = player.onPlay; + video.onpause = player.onPause; + playerEl.appendChild(video); + video.pause(); + } + + public function removeVideo():Void { + if (video == null) return; + playerEl.removeChild(video); + video = null; + } + + public function play():Void { + if (video == null) return; + video.play(); + } + + 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; + } + +} -- cgit v1.2.3