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
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
|
/*
* This module only works with the Samsung Media Players. For other player objects, the code need to be adjusted
*/
var mainPlayer;
var Player =
{
AVPlayerObj : null,
screenObj : null,
isLive : false,
isRecording : false,
mFormat : 0,
eUND : 0, // undefined
ePDL : 1,
eHLS : 2,
eHAS : 3,
url : "",
guid : "unknown",
startTime : 0,
duration : 0, // EpgDuration
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,
curAudioTrack : 0,
curSubtitleTrack : 0, // Zero means off
STOPPED : 0,
PLAYING : 1,
PAUSED : 2,
FORWARD : 3,
REWIND : 4,
effectMode : 0, // 3DEffect Mode value (range from 0 to 7)
aspectRatio :0,
eASP16to9 :0,
eASP4to3 :1,
eASPcrop16to9 :2,
bufferStartTime : 0,
requestStartTime :0
};
Player.init = function() {
this.screenObj = document.getElementById('pluginObjectScreen');
if (this.AVPlayerObj != null)
return false; // that prevents Main.init to overwrite the callbacks.
var success = true;
Main.log("success vale : " + success);
this.state = this.STOPPED;
try {
var custom = webapis.avplay;
Main.logToServer("webapis.ver= " + webapis.ver);
custom.getAVPlay(Player.onAVPlayObtained, Player.onGetAVPlayError);
}
catch(exp) {
Main.log('Player.init: getAVplay Exception :[' +exp.code + '] ' + exp.message);
}
this.skipDuration = Config.skipDuration; // Use Config default also here
Main.log("success= " + success);
return success;
};
// This function is called when Stop was pressed
Player.resetAtStop = function () {
// the default is for plain on-demand recording
// should be called with the Diplayer overlay Reset
if (this.state != Player.STOPPED) {
Main.log("ERROR in Player.reset: should not be here");
return;
}
this.aspectRatio = this.eASP16to9;
if (this.effectMode != 0) {
Player.screenObj.Set3DEffectMode(0);
}
this.effectMode = 0;
this.bufferState = 0;
Player.ResetTrickPlay(); // is the GUI resetted as well?
Player.adjustSkipDuration (0);
this.cptOffset = 0;
this.curPlayTime = 0;
this.totalTime = -1; // negative on purpose
this.totalTimeStr = "0:00:00";
this.curPlayTimeStr = "0:00:00";
this.isLive =false;
this.isRecording = false;
this.mFormat =Player.eUND;
this.curAudioTrack =0;
this.curSubtitleTrack = 0;
};
Player.toggleAspectRatio = function () {
/* var height = Player.plugin.GetVideoHeight();
var width = Player.plugin.GetVideoWidth();
Main.logToServer ("Resolution= " + width + " x " + height );
Main.log ("Resolution= " + width + " x " + height );
*/
switch (this.aspectRatio) {
case this.eASP16to9:
//it is 16 to 9, so do 4 to 3
this.aspectRatio = this.eASP4to3;
Notify.showNotify("4 : 3", true);
break;
case this.eASP4to3:
// it is 4 to 3. do cropped do 16 to 9
this.aspectRatio = this.eASPcrop16to9;
Notify.showNotify("Crop 16 : 9", true);
break;
case this.eASPcrop16to9:
// it is cropped 16 to 9
this.aspectRatio = this.eASP16to9;
Notify.showNotify("16 : 9", true);
// Main.logToServer("Player.toggleAspectRatio: 16 by 9 Now");
break;
}
Player.setFullscreen();
};
Player.toggle3DEffectMode = function () {
Main.logToServer("Player.toggle3DEffectMode");
if (Main.isTvSet() == false) {
if( 1 == Player.screenObj.Flag3DTVConnect() ) {
Main.logToServer("BDPlayer connected to 3D TV");
Player.setNew3DEffectMode();
}
else {
Main.logToServer("BDPlayer connected to 2D TV");
Notify.showNotify("No 3DTV connected, sorry", true);
}
}
else {
if( 1 == Player.screenObj.Flag3DEffectSupport() ) {
Main.logToServer("3D TV!");
Player.setNew3DEffectMode();
}
else {
Main.logToServer("2D TV..;-(");
Notify.showNotify("No 3DTV, sorry", true);
}
}
};
Player.setNew3DEffectMode = function () {
this.effectMode ++;
if (this.effectMode > 7)
this.effectMode = 0;
Main.logToServer("New 3D Effect effectMode= " + this.effectMode );
Player.screenObj.Set3DEffectMode(this.effectMode);
/* if( 2 == Player.screenObj.Get3DEffectMode() ) {
Player.screenObj.Set3DEffectMode(0);
}
else {
Player.screenObj.Set3DEffectMode(2);
};
*/
var mode = Player.screenObj.Get3DEffectMode();
Main.logToServer("New 3D Effect effectMode= " + this.effectMode + " plgMode= " + mode);
// switch (Player.screenObj.Get3DEffectMode()) {
if (this.effectMode == mode ) {
switch (this.effectMode) {
case 0:
Notify.showNotify("3D Off", true);
break;
case 1:
Notify.showNotify("3D Top Bottom", true);
break;
case 2:
Notify.showNotify("3D Side-By-Side", true);
break;
case 3:
Notify.showNotify("3D Line-by-Line", true);
break;
case 4:
Notify.showNotify("3D Vertical Stripe", true);
break;
case 5:
Notify.showNotify("3D Mode frame sequence", true);
break;
case 6:
Notify.showNotify("3D Checker BD", true);
break;
case 7:
Notify.showNotify("3D: 2D to 3D", true);
break;
}
}
else {
Notify.showNotify("3D Issue Wanted= " + this.effectMode + " but got= " + mode +"!!!!", true);
}
};
Player.setWindow = function() {
// this.plugin.SetDisplayArea(458, 58, 472, 270);
};
Player.setFullscreen = function() {
// this.plugin.SetDisplayArea(0, 0, 960, 540);
var resolution = Player.AVPlayerObj.getVideoResolution().split("|");
var w = resolution[0];
var h = resolution[1];
Main.logToServer ("Player.setFullscreen: Resolution= " + w + " x " + h );
Main.log ("Resolution= " + w + " x " + h );
switch (this.aspectRatio) {
case this.eASP16to9:
// this.plugin.SetDisplayArea(0, 0, 960, 540);
// this.plugin.SetCropArea(0, 0, w, h);
Player.AVPlayerObj.setDisplayArea({left: 0, top:0, width:960, height:540 });
Player.AVPlayerObj.setCropArea(Player.onCropSuccess, Player.onError, {left: 0, top:0, width:w, height:h });
Main.logToServer("Player.setFullscreen: 16 by 9 Now");
break;
case this.eASP4to3:
// it is 4 to 3. do cropped do 16 to 9
// this.plugin.SetDisplayArea(120, 0, 720, 540);
// this.plugin.SetCropArea(0, 0, w, h);
Player.AVPlayerObj.setDisplayArea({left: 120, top:0, width:720, height:540 });
Player.AVPlayerObj.setCropArea(Player.onCropSuccess, Player.onError, {left: 0, top:0, width:w, height:h });
// 4/3 = x/540
Main.logToServer("Player.setFullscreen: 4 by 3 Now");
break;
case this.eASPcrop16to9:
// it is cropped 16 to 9
var z = Math.ceil(w*w*27 /(h*64));
Main.logToServer("Player.setFullscreen: Crop 16 by 9 Now: z= " + z);
// this.plugin.SetDisplayArea(0, 0, 960, 540);
// this.plugin.SetCropArea(0, Math.round((h-z)/2), w, z);
Player.AVPlayerObj.setDisplayArea({left: 0, top:0, width:960, height:540 });
Player.AVPlayerObj.setCropArea(Player.onCropSuccess, Player.onError, {left: 0, top:Math.round((h-z)/2), width:w, height:z });
break;
}
};
//successcallback
//function onAVPlayObtained(avplay) {
Player.onAVPlayObtained = function (avplay) {
Player.AVPlayerObj = avplay;
Player.AVPlayerObj.hide();
Main.logToServer("onAVPlayObtained: sName= " + avplay.sName+ " sVersion: " + avplay.sVersion);
var cb = new Object();
cb.containerID = 'webapiplayer';
cb.zIndex = 0;
cb.bufferingCallback = new Object();
cb.bufferingCallback.onbufferingstart= Player.onBufferingStart;
cb.bufferingCallback.onbufferingprogress = Player.onBufferingProgress;
cb.bufferingCallback.onbufferingcomplete = Player.onBufferingComplete;
cb.playCallback = new Object;
cb.playCallback.oncurrentplaytime = Player.OnCurrentPlayTime;
cb.playCallback.onresolutionchanged = Player.onResolutionChanged;
cb.playCallback.onstreamcompleted = Player.OnRenderingComplete;
cb.playCallback.onerror = Player.onError;
cb.displayRect= new Object();
cb.displayRect.top = 0;
cb.displayRect.left = 0;
cb.displayRect.width = 960;
cb.displayRect.height = 540;
cb.autoRatio = false;
try {
Player.AVPlayerObj.init(cb);
}
catch (e) {
Main.log("Player: Error during init: " + e.message);
Main.logToServer("Player: Error during init: " + e.message);
};
};
//errorcallback
//function onGetAVPlayError(error) {
Player.onGetAVPlayError = function (error) {
Main.log('Player.onGetAVPlayError: ' + error.message);
Main.logToServer('Player.onGetAVPlayError: ' + error.message);
};
Player.deinit = function() {
Main.log("Player deinit !!! " );
Main.logToServer("Player deinit !!! " );
if (Player.AVPlayerObj != null) {
Player.AVPlayerObj.stop();
}
};
Player.getNumOfAudioTracks = function () {
return (Player.AVPlayerObj.totalNumOfAudio != null) ? Player.AVPlayerObj.totalNumOfAudio : "Unknown";
};
Player.getNumOfSubtitleTracks = function () {
return (Player.AVPlayerObj.totalNumOfSubtitle != null) ? Player.AVPlayerObj.totalNumOfSubtitle : "Unknown";
};
Player.nextAudioTrack = function () {
var new_track = (Player.curAudioTrack +1 ) % Player.AVPlayerObj.totalNumOfAudio;
// Player.curAudioTrack = (Player.curAudioTrack +1 ) % Player.AVPlayerObj.totalNumOfAudio;
try {
// if (Player.AVPlayerObj.setAudioStreamID(Player.curAudioTrack) == false) {
if (Player.AVPlayerObj.setAudioStreamID(new_track) == false) {
Main.logToServer("Player.nextAudioTrack: Failed to set audio track to " + new_track);
Display.showPopup("Player.nextAudioTrack: Failed to set audio track to " + new_track);
}
else {
Player.curAudioTrack = new_track;
Main.logToServer("Player.nextAudioTrack: Track= " + Player.curAudioTrack);
Notify.showNotify("Audio Track " + Player.curAudioTrack, true);
}
}
catch (e) {
Main.logToServer("Player.nextAudioTrack: Caught Error: " + e.message);
Display.showPopup("Player.nextAudioTrack: Caught Error: " + e.message);
}
};
Player.nextSubtitleTrack = function () {
if (!Player.AVPlayerObj.getSubtitleAvailable() ) {
return;
}
Player.curSubtitleTrack = (Player.curSubtitleTrack +1 ) % (Player.AVPlayerObj.totalNumOfSubtitle +1);
try {
if (Player.AVPlayerObj.setSubtitleStreamID(Player.curSubtitleTrack) == false) {
Main.logToServer("Player.nextSubtitleTrack: Failed to set subtitle track to " + Player.curSubtitleTrack);
Display.showPopup("Player.nextSubtitleTrack: Failed to set subtitle track to " + Player.curSubtitleTrack);
}
else {
Main.logToServer("Player.nextSubtitleTrack: Track= " + Player.curSubtitleTrack);
Notify.showNotify("Subtitle " + Player.curSubtitleTrack, true);
}
}
catch (e) {
Main.logToServer("Player.nextSubtitleTrack: Caught Error: " + e.message);
Display.showPopup("Player.nextSubtitleTrack: Caught Error: " + e.message);
}
};
Player.getBuffer = function (){
var res = {};
var buffer_byte = (Config.totalBufferDuration * Config.tgtBufferBitrate) / 8.0;
var initial_buf = Config.initialBuffer;
if (Player.isLive == true)
initial_buf = initial_buf *4;
res.totalBufferSize = Math.round(buffer_byte);
res.initialBufferSize = Math.round( buffer_byte * initial_buf/ 100.0);
res.pendingBufferSize = Math.round(buffer_byte * Config.pendingBuffer /100.0);
Main.logToServer("Setting totalBufferSize= " + res.totalBufferSize +"Byte initialBufferSize= " +res.initialBufferSize + "byte pendingBufferSize= " +res.pendingBufferSize +"byte " );
return res;
};
Player.setVideoURL = function(url) {
this.url = url;
Main.log("Player.setVideoURL: URL = " + this.url);
};
Player.setCurrentPlayTimeOffset = function(val) {
// val in milli sec
this.cptOffset = val;
// Display.showPopup("CurrentPlayTimeOffset= " + this.cptOffset);
};
Player.setDuration = function () {
Player.totalTime = Data.getCurrentItem().childs[Main.selectedVideo].payload.dur * 1000;
Player.totalTimeStr =Display.durationString(Player.totalTime / 1000.0);
};
Player.getDuration = function () {
return Player.totalTime;
};
Player.getDurationStr = function () {
return Player.totalTimeStr;
};
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();
Player.AVPlayerObj.show();
Spinner.show();
Display.updatePlayTime();
Display.status("Play");
Display.hideStatus();
Display.showProgress();
this.state = this.PLAYING;
Player.ResetTrickPlay();
Player.skipDuration = Config.skipDuration; // reset
Main.log ("Player.playVideo: StartPlayback for " + this.url);
this.requestStartTime = new Date().getTime();
if (Player.isRecording == false) {
if (resume_pos == -1)
resume_pos = 0;
try {
Main.logToServer("Player.play Start playback of url= " + this.url + " resume= " + resume_pos + " sec");
// Player.AVPlayerObj.open (this.url, Player.getBuffer());
Player.AVPlayerObj.open (this.url);
Player.AVPlayerObj.play(Player.onPlaySuccess, Player.onError, resume_pos);
}
catch (e) {
Main.log("Player.play: Error caugth " + e.msg);
Main.logToServer("Player.play: Error caugth " + e.msg);
Display.showPopup("Player.play: Error caugth " + e.msg);
}
}
else {
if (resume_pos == -1)
resume_pos = 0;
Player.setCurrentPlayTimeOffset(resume_pos * 1000.0);
try {
Main.logToServer("Player.play Start playback of url= " + this.url + " time= " + resume_pos + " sec");
// Player.AVPlayerObj.open(this.url+ "?time=" + resume_pos, Player.getBuffer() );
Player.AVPlayerObj.open(this.url+ "?time=" + resume_pos );
Player.AVPlayerObj.play(Player.onPlaySuccess , Player.onError);
}
catch(e) {
Main.log("Player.play: Error: " + e.message);
Main.logToServer("Player.play: Error: " + e.message);
Display.showPopup("Player.play: Error: " + e.message);
};
Main.logToServer("Player.play with ?time=" + resume_pos);
}
if ((this.mFormat == this.eHLS) && (this.isLive == false)){
Notify.showNotify("No Trickplay", true);
}
// pluginObj.setOffScreenSaver();
}
};
Player.pauseVideo = function() {
Display.showProgress();
Main.logToServer("pauseVideo");
this.state = this.PAUSED;
Display.status("Pause");
Display.showStatus();
var res = false;
try {
res = Player.AVPlayerObj.pause();
}
catch(e) {
Main.log("Player.pause: Error " + e.message);
Main.logToServer("Player.pause: Error " + e.message);
Display.showPopup("Player.pause: Error " + e.message);
}
if (res == false)
Display.showPopup("pause ret= " + ((res == true) ? "True" : "False"));
// pluginObj.setOnScreenSaver();
};
Player.stopVideo = function() {
if (this.state != this.STOPPED) {
this.state = this.STOPPED;
Display.status("Stop");
Display.hideStatus();
Player.AVPlayerObj.hide();
try {
Player.AVPlayerObj.stop();
}
catch (e) {
}
if (this.stopCallback) {
Main.log(" StopCallback");
this.stopCallback();
}
// Cleanup
Display.resetAtStop();
Spinner.hide();
// pluginObj.setOnScreenSaver();
}
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 = false;
try {
res = Player.AVPlayerObj.resume();
}
catch (e){
}
if (res == false)
Display.showPopup("resume ret= " + ((res == true) ? "True" : "False"));
// pluginObj.setOffScreenSaver();
};
Player.numKeyJump = function (key) {
Display.showProgress();
switch (Config.playKeyBehavior) {
case 1:
var cur_skip_duration = this.skipDuration;
this.skipDuration = key * 60;
this.skipForwardVideo();
this.skipDuration = cur_skip_duration;
break;
default:
Player.jumpToVideo(key * 10);
break;
}
};
Player.jumpToVideo = function(percent) {
Spinner.show();
if (this.isLive == true) {
return;
}
if (this.state != this.PLAYING) {
Main.logToServer ("Player.jumpToVideo: Player not Playing");
return;
}
Player.bufferState = 0;
Display.showProgress();
//TODO: the totalTime should be set already
if (this.totalTime == -1 && this.isLive == false)
this.totalTime = Player.AVPlayerObj.getDuration();
var tgt = Math.round(((percent-2)/100.0) * this.totalTime/ 1000.0);
var res = false;
this.requestStartTime = new Date().getTime();
if (Player.isRecording == false) {
if (tgt > (Player.curPlayTime/1000.0))
res = Player.AVPlayerObj.jumpForward(tgt - (Player.curPlayTime/1000.0));
else
res = Player.AVPlayerObj.jumpBackward( (Player.curPlayTime/1000.0)- tgt);
}
else {
Player.AVPlayerObj.stop();
var old = Player.curPlayTime;
Player.setCurrentPlayTimeOffset(tgt * 1000.0);
// Player.AVPlayerObj.open(this.url+ "?time=" + tgt, Player.getBuffer() );
Player.AVPlayerObj.open(this.url+ "?time=" + tgt);
res = Player.AVPlayerObj.play(Player.onPlaySuccess , Player.onError);
Main.logToServer("Player.play with ?time=" + tgt);
if (res == false)
Player.setCurrentPlayTimeOffset(old);
}
Main.logToServer("Player.jumpToVideo: jumpTo= " + percent + "% of " + (this.totalTime/1000) + "sec tgt = " + tgt + "sec cpt= " + (this.curPlayTime/1000) +"sec" + " res = " + res);
if (res == false)
Display.showPopup("ResumePlay ret= " + ((res == true) ? "True" : "False"));
};
Player.skipForwardVideo = function() {
this.requestStartTime = new Date().getTime();
Display.showProgress();
var res = false;
if (Player.isRecording == false)
res = Player.AVPlayerObj.jumpForward(Player.skipDuration);
else {
Spinner.show();
this.bufferState = 0;
Player.AVPlayerObj.stop();
var old = Player.curPlayTime;
var tgt = (Player.curPlayTime/1000.0) + Player.skipDuration;
Player.setCurrentPlayTimeOffset(tgt * 1000.0);
// Player.AVPlayerObj.open(this.url+ "?time=" + tgt, Player.getBuffer());
Player.AVPlayerObj.open(this.url+ "?time=" + tgt);
res = Player.AVPlayerObj.play(Player.onPlaySuccess , Player.onError);
Main.logToServer("Player.skipForwardVideo with ?time=" + tgt);
if (res == false)
Player.setCurrentPlayTimeOffset(old);
}
if (res == false) {
Display.showPopup("Jump Forward ret= " + ((res == true) ? "True" : "False"));
}
};
Player.skipBackwardVideo = function() {
this.requestStartTime = new Date().getTime();
Display.showProgress();
var res = false;
if (Player.isRecording == false)
res = Player.AVPlayerObj.jumpBackward(Player.skipDuration);
else {
Spinner.show();
this.bufferState = 0;
Player.AVPlayerObj.stop();
var tgt = (Player.curPlayTime/1000.0) - Player.skipDuration;
if (tgt < 0)
tgt = 0;
Player.setCurrentPlayTimeOffset(tgt * 1000.0);
// Player.AVPlayerObj.open(this.url+ "?time=" + tgt, Player.getBuffer());
Player.AVPlayerObj.open(this.url+ "?time=" + tgt);
res = Player.AVPlayerObj.play(Player.onPlaySuccess , Player.onError);
Main.logToServer("Player.skipBackwardVideo with ?time=" + tgt);
if (res == false)
Player.setCurrentPlayTimeOffset(old);
}
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.isInTrickplay = function() {
return (this.trickPlaySpeed != 1) ? true: false;
};
Player.fastForwardVideo = function() {
if (this.trickPlayDirection == 1) {
this.trickPlaySpeed = this.trickPlaySpeed * 2;
}
else {
// I am in rewind mode, thus decrease speed
this.trickPlaySpeed = this.trickPlaySpeed / 2;
if (this.trickPlaySpeed <= 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
}
if (Player.isRecording == true) {
if (this.trickPlaySpeed > 2)
this.trickPlaySpeed = 2;
}
if (this.trickPlaySpeed != 1) {
Main.log("Player.fastForwardVideo: updating display");
Display.setTrickplay (this.trickPlayDirection, this.trickPlaySpeed);
}
else {
Player.ResetTrickPlay();
return;
}
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 (Player.AVPlayerObj.setSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
Player.ResetTrickPlay();
// this.trickPlaySpeed = 1;
// this.trickPlayDirection = 1;
}
};
Player.RewindVideo = function() {
if ((this.trickPlayDirection == 1) && (this.trickPlaySpeed == 1)){
this.trickPlayDirection = -1;
this.trickPlaySpeed = this.trickPlaySpeed * 2;
}
else if (this.trickPlayDirection == 1) {
// I am in fast forward mode, so decrease
this.trickPlaySpeed = this.trickPlaySpeed / 2;
if (this.trickPlaySpeed < 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = -1;
}
}
else
this.trickPlaySpeed = this.trickPlaySpeed * 2;
if (Player.isRecording == true) {
if (this.trickPlayDirection <0 )
Player.ResetTrickPlay();
return;
}
if (this.trickPlaySpeed != 1) {
Display.setTrickplay (this.trickPlayDirection, this.trickPlaySpeed);
}
else {
Player.ResetTrickPlay();
return;
}
Main.log("Rewind: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
if (Player.AVPlayerObj.setSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
Player.ResetTrickPlay();
}
Main.log("Rewind: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
Main.logToServer("Rewind: Direction= " + ((this.trickPlayDirection == 1) ? "Forward": "Backward") + "trickPlaySpeed= " + this.trickPlaySpeed);
};
Player.ResetTrickPlay = function() {
if (this.trickPlaySpeed != 1) {
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
Main.log("Reset Trickplay " );
if (Player.AVPlayerObj.setSpeed(this.trickPlaySpeed * this.trickPlayDirection) == false) {
Display.showPopup("trick play returns false. Reset Trick-Play" );
this.trickPlaySpeed = 1;
this.trickPlayDirection = 1;
}
}
if (Player.skipDuration != 30) {
Display.setSkipDuration(Player.skipDuration );
}
else {
Display.resetStartStop();
}
};
Player.getState = function() {
return this.state;
};
// ------------------------------------------------
// Global functions called directly by the player
//------------------------------------------------
Player.onResolutionChanged = function () {
Main.log('Player.onResolutionChanged : ');
};
Player.onError = function () {
Main.log('Player.onError: ' );
Main.logToServer('Player.onError: ' );
};
Player.onPlaySuccess = function () {
Player.OnStreamInfoReady();
};
Player.onCropSuccess = function () {
Main.log('Player.onCropSuccess: ');
// Main.logToServer('Player.onCropSuccess: ');
};
Player.onBufferingStart = function() {
// Main.logToServer("Buffer Start: cpt= " + (Player.curPlayTime/1000.0) +"sec");
Main.log("Buffer Start: cpt= " + (Player.curPlayTime/1000.0) +"sec");
Player.bufferStartTime = new Date().getTime();
if (this.requestStartTime != 0) {
this.requestStartTime = 0;
}
Spinner.show();
Player.bufferState = 0;
Display.bufferUpdate();
Display.showProgress();
Display.status("Buffering...");
};
Player.onBufferingProgress = function(percent) {
Player.bufferState = percent;
Display.bufferUpdate();
Display.showProgress();
};
Player.onBufferingComplete = function() {
Display.status("Play");
Display.hideStatus();
Spinner.hide();
Main.logToServer("onBufferingComplete cpt= " +(Player.curPlayTime/1000.0) +"sec - Buffering Duration= " + (new Date().getTime() - Player.bufferStartTime) + " ms");
Main.log("onBufferingComplete cpt= " +(Player.curPlayTime/1000.0) +"sec - Buffering Duration= " + (new Date().getTime() - Player.bufferStartTime) + " ms");
Player.bufferState = 100;
Display.bufferUpdate();
Display.showProgress();
// Player.setFullscreen();
// or I should set it according to the aspect ratio
Display.hide();
};
Player.OnCurrentPlayTime = function(time) {
Main.log ("Player.OnCurrentPlayTime " + time.millisecond);
if (typeof time == "number")
Player.curPlayTime = parseInt(time) + parseInt(Player.cptOffset);
else
Player.curPlayTime = parseInt(time.millisecond) + parseInt(Player.cptOffset);
// Update the Current Play Progress Bar
Display.updateProgressBar();
if (Player.isRecording == true) {
Display.updateRecBar(Player.startTime, Player.duration);
}
Main.log ("Player.OnCurrentPlayTime: curPlayTimeStr= " + Player.curPlayTimeStr);
Player.curPlayTimeStr = Display.durationString(Player.curPlayTime / 1000.0);
Display.updatePlayTime();
};
Player.OnStreamInfoReady = function() {
Main.log("*** OnStreamInfoReady ***");
// Main.logToServer("*** OnStreamInfoReady ***");
Player.setFullscreen();
if ((Player.isLive == false) && (Player.isRecording == false)) {
Player.totalTime = Player.AVPlayerObj.getDuration();
}
Player.totalTimeStr =Display.durationString(Player.totalTime / 1000.0);
Main.log("Player.totalTimeStr= " + Player.totalTimeStr);
};
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();
};
|