aboutsummaryrefslogtreecommitdiffstats
path: root/src/client/players/Raw.hx
blob: 41b421c4ba8d3efd1dc33171e68ae6dfd0e47a09 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
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;
	}

}
send patches to the email below
yukais@pinapelz.com
include the subject [PATCH repo_name]
pinapelz.com
homepage