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
|
/*
* This module only works with the Samsung Media Players. For other player objects, the code need to be adjusted
*/
var Player =
{
plugin : null,
isLive : false,
isRecording : false,
startTime : 0,
duration : 0,
state : 0,
cptOffset : 0, // millis
curPlayTime : 0, // millis
totalTime : -1, // millis
curPlayTimeStr : "00:00:00", // millis
totalTimeStr : "",
stopCallback : null, /* Callback function to be set by client */
errorCallback : null,
originalSource : null,
bufferState : 0, // buffer state in %
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");
if (!this.plugin)
{
Main.log("success vale this.plugin : " + success);
success = false;
}
// 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 (btr){
var res = true;
var buffer_byte = (Config.totalBufferDuration * Config.tgtBufferBitrate) / 8.0;
Main.logToServer("Seting TotalBufferSize to " + Math.round(buffer_byte) +"Byte dur= " +Config.totalBufferDuration + "sec init_buffer_perc= " +Config.initialBuffer +"% 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 * Config.initialBuffer/ 100.0));
if (res == false) {
Display.showPopup("SetInitialBuffer(" + Math.round(buffer_byte * Config.initialBuffer/ 100.0) +") returns error");
Main.logToServer("SetInitialBuffer(" + Math.round(buffer_byte * Config.initialBuffer/ 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() {
if (Config.deviceType != 0) {
Display.showPopup ("Only supported for TVs");
return;
}
if (this.url == null) {
Main.log("No videos to play");
}
else
{
// Player.curPlayTime = 0;
Display.updatePlayTime();
Display.status("Play");
Display.showStatus();
Display.showProgress();
this.state = this.PLAYING;
// if (this.plugin.InitPlayer(this.url) == false)
// Display.showPopup("InitPlayer returns false");
Player.setBuffer(15000000.0);
Main.log ("StartPlayback for " + this.url);
// if (this.plugin.StartPlayback() == false)
// Display.showPopup("StartPlayback returns false");
this.plugin.Play( this.url );
Audio.plugin.SetSystemMute(false);
}
};
Player.pauseVideo = function() {
Display.showProgress();
Main.logToServer("pauseVideo");
this.state = this.PAUSED;
Display.status("Pause");
var res = this.plugin.Pause();
if (res == false)
Display.showPopup("pause ret= " + ((res == true) ? "True" : "False"));
};
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) {
this.stopCallback();
}
}
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");
var res = this.plugin.Resume();
if (res == false)
Display.showPopup("resume ret= " + ((res == true) ? "True" : "False"));
};
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(Config.skipDuration);
if (res == false)
Display.showPopup("Jump Forward ret= " + ((res == true) ? "True" : "False"));
};
Player.skipBackwardVideo = function() {
var res = this.plugin.JumpBackward(Config.skipDuration);
if (res == false)
Display.showPopup("Jump Backward ret= " + ((res == true) ? "True" : "False"));
};
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();
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();
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);
/* var height = Player.plugin.GetVideoHeight();
var width = Player.GetVideoWidth();
Display.showPopup("Resolution= " + height + " x " +width);
Main.log("Resolution= " + height + " x " +width);
*/
};
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");
// 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?)");
};
|