/
test.html
139 lines (120 loc) · 3.71 KB
/
test.html
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
<!DOCTYPE html>
<html>
<head>
<title>Trampoline Test Page</title>
<script src="base.js"></script>
<script src="service.js"></script>
<script src="device.js"></script>
<script>
var endpoint = 'http://localhost:8090';
var service = new Service(endpoint);
var deviceList;
var statusBox;
var seekBar;
var isSeeking = false;
var devices = {}; // deviceId -> Device mapping
var targetDevice = null;
var currentStatus = null;
function queryDevices() {
service.getDevices(function(response) {
if (!response) {
window.console.log('service not running, unable to query devices');
return;
}
for (var n = 0; n < response.devices.length; n++) {
var deviceInfo = response.devices[n];
if (!devices[deviceInfo.id]) {
var device = new Device(service, deviceInfo);
devices[deviceInfo.id] = device;
if (!targetDevice) {
targetDevice = device;
}
var option = document.createElement('option');
option.innerText =
device.id + ' / ' + device.name + ' / ' + device.deviceId;
deviceList.options.add(option);
window.console.log('new device:');
window.console.log(device);
}
}
// TODO: remove devices no longer present
});
}
function updateStatus() {
if (!targetDevice) {
return;
}
targetDevice.getStatus(function(status) {
currentStatus = status;
if (!status) {
return;
}
if (!isSeeking) {
seekBar.value = (status.position / status.duration) * 100;
}
// TODO: better presentation
statusBox.innerText = JSON.stringify(status);
});
}
window.setInterval(function() {
updateStatus();
}, 500);
function seek(percent) {
if (!currentStatus) {
return;
}
var position = (percent / 100) * currentStatus.duration;
targetDevice.scrub(position);
}
function rewind() {
seek(0);
}
function pause() {
targetDevice.rate(0);
}
function resume() {
targetDevice.rate(1);
}
function stop() {
targetDevice.stop();
}
function test1() {
var content = 'http://wwwappskc.lonestar.edu/cgi/video/html5/test.m4v';
//var content = 'http://10.0.1.3:8090/content/test';
targetDevice.play(content, 0);
}
window.addEventListener('load', function() {
deviceList = document.getElementById('deviceList');
statusBox = document.getElementById('statusBox');
seekBar = document.getElementById('seekBar');
seekBar.addEventListener('mousedown', function() {
isSeeking = true;
});
seekBar.addEventListener('mouseup', function() {
seek(parseInt(seekBar.value));
isSeeking = false;
});
var kDeviceRefreshInterval = 5 * 1000;
window.setInterval(queryDevices, kDeviceRefreshInterval);
queryDevices();
});
</script>
</head>
<body>
<select id="deviceList">
</select>
<br/>
<div id="statusBox">
[status]
</div>
<br/>
<input id="seekBar" type="range" min="0" max="100" value="0" step="1"/>
<br/>
<a href="javascript:rewind();">rewind</a>
<a href="javascript:resume();">resume</a>
<a href="javascript:pause();">pause</a>
<a href="javascript:stop();">stop</a>
<br/>
<a href="javascript:test1();">test1</a>
</body>
</html>