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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
|
/*
* This module only works with the Samsung Media Players. For other player objects, the code need to be adjusted
*/
var Player =
{
plugin : null,
pluginBD : null,
mFrontPanel : null,
isLive : false,
isRecording : false,
url : "",
guid : "unknown",
startTime : 0,
duration : 0,
resumePos : -1,
state : 0,
cptOffset : 0, // millis
curPlayTime : 0, // millis
totalTime : -1, // millis
skipDuration : 30,
curPlayTimeStr : "00:00:00", // millis
totalTimeStr : "",
stopCallback : null, /* Callback function to be set by client */
errorCallback : null,
originalSource : null,
bufferState : 0, // buffer state in %
trickPlaySpeed : 1, // Multiple of 2 only.
trickPlayDirection : 1,
STOPPED : 0,
PLAYING : 1,
PAUSED : 2,
FORWARD : 3,
REWIND : 4
};
Player.init = function() {
var success = true;
Main.log("success vale : " + success);
this.state = this.STOPPED;
this.plugin = document.getElementById("pluginPlayer");
this.pluginBD = document.getElementById("pluginBD");
try {
this.pluginBD.DisplayVFD_Show(0101); // Stop
}
catch (e) {
}
/* var pl_version = "";
try {
pl_version = this.plugin.GetPlayerVersion();
}
catch (e) {
Main.logToServer("Error while getting player version: " +e);
}
Main.logToServer("PlayerVersion= " + pl_version);
*/
if (!this.plugin)
{
Main.log("success vale this.plugin : " + success);
success = false;
}
this.skipDuration = Config.skipDuration; // Use Config default also here
// var vermsg = this.plugin.GetPlayerVersion();
// Main.log ("player plugin version: " +vermsg);
this.plugin.OnCurrentPlayTime = 'Player.OnCurrentPlayTime';
this.plugin.OnStreamInfoReady = 'Player.OnStreamInfoReady';
this.plugin.OnBufferingStart = 'Player.onBufferingStart';
this.plugin.OnBufferingProgress = 'Player.onBufferingProgress';
this.plugin.OnBufferingComplete = 'Player.onBufferingComplete';
this.plugin.OnConnectionFailed = 'Player.OnConnectionFailed'; // fails to connect to the streaming server
this.plugin.OnStreamNotFound = 'Player.OnStreamNotFound'; // 404 file not found
this.plugin.OnNetworkDisconnected = 'Player.OnNetworkDisconnected'; // when the ethernet is disconnected or the streaming server stops supporting the content in the middle of streaming.
this.plugin.OnRenderingComplete = 'Player.OnRenderingComplete';
Main.log("success= " + success);
return success;
};
Player.deinit = function()
{
Main.log("Player deinit !!! " );
if (this.plugin)
{
this.plugin.Stop();
}
};
Player.setWindow = function() {
// this.plugin.SetDisplayArea(458, 58, 472, 270);
};
Player.setFullscreen = function() {
this.plugin.SetDisplayArea(0, 0, 960, 540);
};
Player.setBuffer = function (){
var res = true;
var buffer_byte = (Config.totalBufferDuration * Config.tgtBufferBitrate) / 8.0;
var initial_buf = Config.initialBuffer;
if (Player.isLive == true)
initial_buf = initial_buf *2;
Main.logToServer("Seting TotalBufferSize to " + Math.round(buffer_byte) +"Byte dur= " +Config.totalBufferDuration + "sec init_buffer_perc= " +initial_buf +"% pend_buffer_perc= " +Config.pendingBuffer + "% initialTimeOut= " +Config.initialTimeOut + "sec");
//The SetTotalBufferSize function sets the streaming buffer size of media player.
res = this.plugin.SetTotalBufferSize(Math.round(buffer_byte));
if (res == false) {
Display.showPopup("SetTotalBufferSize(" + Math.round(buffer_byte) +") returns error");
Main.logToServer("SetTotalBufferSize(" + Math.round(buffer_byte) +") returns error");
}
// The SetInitialBuffer function sets the first buffering size as percentage of buffer size before starting playback.
res = this.plugin.SetInitialBuffer(Math.round( buffer_byte * initial_buf/ 100.0));
if (res == false) {
Display.showPopup("SetInitialBuffer(" + Math.round(buffer_byte * initial_buf/ 100.0) +") returns error");
Main.logToServer("SetInitialBuffer(" + Math.round(buffer_byte * initial_buf/ 100.0) +") returns error");
}
//he SetInitialTimeOut function sets the maximum time out value for initial buffering before starting playback.
res = this.plugin.SetInitialTimeOut(Config.initialTimeOut);
if (res == false) {
Display.showPopup("SetInitialTimeOut(" + 2 +") returns error");
Main.logToServer("SetInitialTimeOut(" + 2 +") returns error");
}
// The SetPendingBuffer function sets the size of a buffer as percentage of total buffer size that media player goes out from buffering status.
res = this.plugin.SetPendingBuffer(Math.round(buffer_byte * Config.pendingBuffer /100.0));
if (res == false) {
Display.showPopup("SetPendingBuffer(" + Math.round(buffer_byte * Config.pendingBuffer /100.0) +") returns error");
Main.logToServer("SetPendingBuffer(" + Math.round(buffer_byte * Config.pendingBuffer /100.0) +") returns error");
}
};
Player.setVideoURL = function(url) {
this.url = url;
Main.log("URL = " + this.url);
};
Player.setCurrentPlayTimeOffset = function(val) {
// val in milli sec
this.cptOffset = val;
// Display.showPopup("CurrentPlayTimeOffset= " + this.cptOffset);
};
Player.playVideo = function(resume_pos) {
if (Config.deviceType != 0) {
Display.showPopup ("Only supported for TVs");
return;
}
if (this.url == null) {
Main.log("No videos to play");
}
else {
Player.bufferState = 0;
Display.bufferUpdate();
Spinner.show();
// Player.curPlayTime = 0;
Display.updatePlayTime();
Display.status("Play");
Display.hideStatus();
// Display.showStatus();
Display.showProgress();
this.state = this.PLAYING;
Player.setBuffer();
Player.ResetTrickPlay();
Player.skipDuration = Config.skipDuration; // reset
Main.log ("Player.playVideo: StartPlayback for " + this.url);
if (resume_pos == -1)
this.plugin.Play( this.url );
else
this.plugin.ResumePlay(this.url, resume_pos);
Audio.plugin.SetSystemMute(false);
pluginObj.setOffScreenSaver();
this.pluginBD.DisplayVFD_Show(0100); // Play
}
};
Player.pauseVideo = function() {
Display.showProgress();
Main.logToServer("pauseVideo");
this.state = this.PAUSED;
Display.status("Pause");
Display.showStatus();
var res = this.plugin.Pause();
if (res == false)
Display.showPopup("pause ret= " + ((res == true) ? "True" : "False"));
pluginObj.setOnScreenSaver();
this.pluginBD.DisplayVFD_Show(0102); // Pause
};
Player.stopVideo = function() {
if (this.state != this.STOPPED) {
this.state = this.STOPPED;
Display.status("Stop");
this.plugin.Stop();
Player.bufferState = 0;
// Display.setTime(0);
if (this.stopCallback) {
Main.log(" StopCallback");
this.stopCallback();
}
Spinner.hide();
pluginObj.setOnScreenSaver();
this.pluginBD.DisplayVFD_Show(0101); // Stop
}
else {
Main.log("Ignoring stop request, not in correct state");
}
};
Player.resumeVideo = function() {
Main.logToServer("resumeVideo");
Display.showProgress();
this.state = this.PLAYING;
Display.status("Play");
Display.hideStatus();
var res = this.plugin.Resume();
if (res == false)
Display.showPopup("resume ret= " + ((res == true) ? "True" : "False"));
pluginObj.setOffScreenSaver();
this.pluginBD.DisplayVFD_Show(0100); // Play
};
Player.jumpToVideo = function(percent) {
if (this.isLive == true) {
return;
}
Player.bufferState = 0;
Display.showProgress();
if (this.state != this.PLAYING) {
Main.log ("Player not Playing");
return;
}
if (this.totalTime == -1 && this.isLive == false)
this.totalTime = this.plugin.GetDuration();
var tgt = Math.round(((percent-2)/100.0) * this.totalTime/ 1000.0);
Main.log("jumpToVideo= " + percent + "% of " + (this.totalTime/1000) + "sec tgt = " + tgt + "sec curPTime= " + (this.curPlayTime/1000) +"sec");
// Display.showPopup("jumpToVideo= " + percent + "% of " + (this.totalTime/1000) + "sec<br>--> tgt = " + tgt + "sec curPTime= " + (this.curPlayTime/1000)+"sec");
this.plugin.Stop();
// Display.showStatus();
var res = this.plugin.ResumePlay(this.url, tgt );
if (res == false)
Display.showPopup("ResumePlay ret= " + ((res == true) ? "True" : "False"));
};
Player.skipForwardVideo = function() {
var res = this.plugin.JumpForward(Player.skipDuration);
if (res == false) {
Display.showPopup("Jump Forward ret= " + ((res == true) ? "True" : "False"));
}
};
Player.skipBackwardVideo = function() {
var res = this.plugin.JumpBackward(Player.skipDuration);
if (res == false) {
Display.showPopup("Jump Backward ret= " + ((res == true) ? "True" : "False"));
}
};
Player.adjustSkipDuration = function (dir) {
if (Player.isLive == true) {
return;
}
switch (dir) {
case 0:
// Reset
Player.skipDuration = Config.skipDuration;
Display.setSkipDuration(Player.skipDuration );
break;
case 1:
// Increase
Player.skipDuration += Config.skipDuration;
Display.setSkipDuration(Player.skipDuration );
break;
case 2:
// Decrease
Player.skipDuration -= Config.skipDuration;
if (Player.skipDuration < Config.skipDuration)
Player.skipDuration = Config.skipDuration;
Display.setSkipDuration(Player.skipDuration );
break;
};
};
Player.fastForwardVideo = function() {
if (this.trickPlayDirection == 1)
this.trickPlaySpeed = this.trickPlaySpeed * 2;
else {
this.trickPlaySpeed = this.trickPlaySpeed / 2;
if (this.trickPlaySpeed < 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = -1;
}
}
Main.log("FastForward: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
Main.logToServer("FastForward: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
if (this.plugin.SetPlaybackSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
};
Player.RewindVideo = function() {
if (this.trickPlayDirection == 1) {
this.trickPlaySpeed = this.trickPlaySpeed / 2;
if (this.trickPlaySpeed < 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
}
else
this.trickPlaySpeed = this.trickPlaySpeed * 2;
if (this.plugin.SetPlaybackSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
Main.log("Rewind: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
Main.logToServer("Rewind: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
if (this.plugin.SetPlaybackSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
};
Player.ResetTrickPlay = function() {
if (this.trickPlaySpeed != 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
Main.log("Reset Trickplay " );
if (this.plugin.SetPlaybackSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
}
};
Player.getState = function() {
return this.state;
};
// ------------------------------------------------
// Global functions called directly by the player
//------------------------------------------------
Player.onBufferingStart = function() {
Main.logToServer("Buffer Start: " + Player.curPlayTime);
Player.bufferStartTime = new Date().getTime();
Spinner.show();
Player.bufferState = 0;
Display.bufferUpdate();
// should trigger from here the overlay
Display.showProgress();
Display.status("Buffering...");
// Display.showStatus();
};
Player.onBufferingProgress = function(percent)
{
// should trigger from here the overlay
Display.status("Buffering:" + percent + "%");
Player.bufferState = percent;
Display.bufferUpdate();
Display.showProgress();
};
Player.onBufferingComplete = function() {
Display.status("Play");
Display.hideStatus();
Spinner.hide();
Main.logToServer("Buffer Completed - Buffering Duration= " + (new Date().getTime() - Player.bufferStartTime) + " ms");
Player.bufferState = 100;
Display.bufferUpdate();
Display.showProgress();
Player.setFullscreen();
Display.hide();
Main.logToServer("onBufferingComplete ");
/* Player.pauseVideo();
window.setTimeout(Player.resumeVideo, 1000); */
};
Player.OnCurrentPlayTime = function(time) {
Player.curPlayTime = parseInt(time) + parseInt(Player.cptOffset);
// Update the Current Play Progress Bar
Display.updateProgressBar();
if (Player.isRecording == true) {
Display.updateRecBar(Player.startTime, Player.duration);
}
Player.curPlayTimeStr = Display.durationString(Player.curPlayTime / 1000.0);
Display.updatePlayTime();
};
Player.OnStreamInfoReady = function() {
Main.log("*** OnStreamInfoReady ***");
Main.logToServer("GetCurrentBitrates= " + Player.plugin.GetCurrentBitrates());
if ((Player.isLive == false) && (Player.isRecording == false)) {
Player.totalTime = Player.plugin.GetDuration();
}
// Player.curPlayTimeStr = Display.durationString(Player.totalTime / 1000.0);
Player.totalTimeStr =Display.durationString(Player.totalTime / 1000.0);
var height = Player.plugin.GetVideoHeight();
var width = Player.plugin.GetVideoWidth();
// Display.showPopup("Resolution= " + height + " x " +width);
Main.logToServer("Resolution= " + width + " x " + height );
};
Player.OnRenderingComplete = function() {
// Do Something
Player.stopVideo();
};
Player.OnConnectionFailed = function() {
// fails to connect to the streaming server
Main.log ("ERROR: Failed to connect to the streaming server");
Main.logToServer("ERROR: Failed to connect Url= "+ Player.url);
// widgetAPI.putInnerHTML(document.getElementById("popup"), "Failed to connect to the streaming server");
Display.showPopup("Failed to connect to the streaming server");
};
Player.OnStreamNotFound = function() {
// 404 file not found
Main.log ("ERROR: Stream Not Found");
// widgetAPI.putInnerHTML(document.getElementById("popup"), "Stream Not Found");
Display.showPopup("Stream Not Found");
};
Player.OnNetworkDisconnected = function() {
// when the ethernet is disconnected or the streaming server stops supporting the content in the middle of streaming.
Main.log ("ERROR: Lost Stream (Unavailable?)");
// widgetAPI.putInnerHTML(document.getElementById("popup"), "Lost Stream (Unavailable?)");
Display.showPopup("Lost Stream (Unavailable?)");
Server.saveResume();
};
|