ProgramPlayerFullScreen.js
40.4 KB
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
//全屏播放
var Common = require('Common');
var Network = require('Network');
var TVFocus = require('TVFocus');
var FocusInfo = require('FocusInfo');
var TVCanvas = require('TVCanvas');
var Utils = require('Utils');
var BusinessParameter = require('BusinessParameter');
cc.Class({
extends: TVCanvas,
properties: {
videoPlay: cc.VideoPlayer,
playOrPauseIcon: cc.Sprite,
playTitle: cc.Label, //剧情名称
progressBarIcon: cc.Sprite, //进度块
durationText: cc.Label, //时间
totalTimeText: cc.Label, //总时间
volumeIcon: cc.Sprite, //声音
volumeValue: cc.Sprite, //声音进度条
volumeControl: cc.Node, //声音控制
orderIcon: cc.Sprite, //订购
collectIcon: cc.Sprite, //收藏
playContainer: cc.Node,
playProgressBarValue: cc.Sprite, //播放进度值
_strAppId: '',
_strParentCId: '',
_strId: '', //节目ID
_strName: '', //节目名称
_iAuthStatus: 0, //判断鉴权 1-已订购,0-未订购,2-欠费停机,3-无法正常观看点播
_iProgramType: -1,//视频资源类型,1-电影,2-电视剧
_iEpisodeIndex: 0, //剧集数
_iEpisodeCount: 0, //总剧集数
_strEpisodeId: '',
_strMediaCode: '', //剧集mediaCode
_strEpisodeName: '', //奇缘 第二集
_iVolumeContainerHeight: 0, //声音进度条高度
_iPlayContainerWidth: 0, //播放进度总宽度
_iPlayProgress: 1, //播放进度
_iPlayProgressStep: 1, //快进步距
_iVideoPlayTotalTime: 0,
_bPlay: false,
_bCollect: false,
_strCollectDefaultId: "",// 默认收藏
_iMaxVolume: 0, //系统最大音量
},
onLoad() {
this._super();
//-----------上下文及参数相关处理------------
let aSceneContext = this._cApplication.getSceneContext();
let aSceneParameter = this._cApplication.getSceneParameter();
//上下文预设
this._oSceneContext = {
focusPath: this.videoPlayer,
};
//参数相关处理
if (aSceneParameter.length) {
this._strAppId = aSceneParameter[aSceneParameter.length - 1].appId;//应用id
this._strId = aSceneParameter[aSceneParameter.length - 1].id; //节目ID
this._strName = aSceneParameter[aSceneParameter.length - 1].name; //节目名称(这些是电视剧详情传过来的)
this._strMediaCode = aSceneParameter[aSceneParameter.length - 1].mediaCode; //剧集mediaCode
this._iEpisodeIndex = aSceneParameter[aSceneParameter.length - 1].episodeNum || 1; //剧集数
}
this._strAppId = this._strAppId || "tdde7add064d218a84"; //为了方便测试
this._strId = this._strId || '935';
//从其他界面退回来的
if (this._cApplication.getBackStatus()) {
let oSceneContext = aSceneContext.pop();
if (oSceneContext) {
this._oSceneContext = oSceneContext;
}
this._cApplication.setBackStatus(false);
}
//-----上下文处理结束---------
switch (this._strAppId) {
case BusinessParameter.SONG_APPID:
this._strParentCId = BusinessParameter.SONG_FREE_CID;
break;
case BusinessParameter.ENHLISH_APPID:
this._strParentCId = BusinessParameter.ENGLISH_FREE_CID;
break;
case BusinessParameter.STORY_APPID:
this._strParentCId = BusinessParameter.STORY_FREE_CID;
break;
case BusinessParameter.SCIENCE_APPID:
this._strParentCId = BusinessParameter.SCIENCE_FREE_CID;
break;
case BusinessParameter.EDUCATION_APPID:
this._strParentCId = BusinessParameter.EDUCATION_FREE_CID;
break;
case BusinessParameter.CLASSICAL_APPID:
this._strParentCId = BusinessParameter.CLASSICAL_FREE_CID;
break;
case BusinessParameter.ART_APPID:
this._strParentCId = BusinessParameter.ART_FREE_CID;
break;
};
this._iVolumeContainerHeight = this.volumeValue.node.height;
this._iPlayContainerWidth = this.playContainer.width;
// 调用AppActivity方法
if (Utils.isMobile()) {
var iCurrentVolume = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "currentVolume", "()I");//反射获取系统音量
this._iMaxVolume = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "maxVolume", "()I");//反射获取系统音量
this.volumeValue.node.height = this._iVolumeContainerHeight * (iCurrentVolume / this._iMaxVolume);//更新声音进度条
}
this.videoPlay.remoteURL = "http://ivi.bupt.edu.cn/hls/cctv1hd.m3u8"; //测试播放器
// this.videoPlay.remoteURL = "http://vjs.zencdn.net/v/oceans.mp4";
// cc.log("------------------------------->"+cc.find("TopCanvas/VideoPlayer", this.node));
cc.find("VideoPlayer", this.node).on('ready-to-play', function (event) {
this.videoPlay.play();
if (!this.playContainerCallback) { //定时隐藏控制背景函数
this.playContainerCallback = function () {
this.playContainer.opacity = 0;
}
}
this.unschedule(this.playContainerCallback);
this.playContainer.opacity = 255;
this.scheduleOnce(this.playContainerCallback, 5);
}, this);
this.initFocus();
this.getProgramRequest();
this.getDefaultCollectRequest(); //获取收藏Id
this.getMediaCollectionRequest(); //该片是否收藏过
this.getEpisodeRequest();
this.playTheSong(); //获取播放地址
},
//播放器点击事件
onVideoPlayerEvent(sender, event) {
if (event === cc.VideoPlayer.EventType.META_LOADED) {
var duration = this.videoPlay.getDuration(); //200.617083-单位是秒
if (duration) {
this.totalTimeText.string = Utils.formatSecond2Minute(duration); //将秒转化为分
this._iVideoPlayTotalTime = duration;
this._iPlayProgressStep = Math.ceil(duration.toFixed(2) / 100); //计算快进步距
}
else {
this.totalTimeText.string = 0;
}
} else if (event === cc.VideoPlayer.EventType.CLICKED) {
if (this.videoPlay.isPlaying()) {
this._bPlay = false;
this.videoPlay.pause();
} else {
this._bPlay = true;
this.videoPlay.play();
//--------------测试播放-----------
this.videoPlay.volume = 0;
// this.volumeValue.node.height = this.volumeValue.node.height * this.videoPlay.volume;
this.playProgressBarValue.node.width = this._iPlayContainerWidth * (this.videoPlay.currentTime / this._iVideoPlayTotalTime);
//--------------测试结束-----------
}
} else if (event === cc.VideoPlayer.EventType.COMPLETED) { //监听播放结束
cc.log("播放已完成。。。。");
// this.videoPlay.remoteURL = "http://139.196.37.202:8080/sparrow.lab/wcaf.ts"; //测试播放器
this.videoPlay.play();
}
},
update() {
this.durationText.string = Utils.formatSecond2Minute(this.videoPlay.currentTime); //将秒转化为分
this.playProgressBarValue.node.width = this._iPlayContainerWidth * (this.videoPlay.currentTime / this._iVideoPlayTotalTime);//实时更新进度
// this._cFocus.fly(this.playProgressBarValue.node.width, this._fiCurrentFocus.getTop(),
// this._fiCurrentFocus.getWidth(), this._fiCurrentFocus.getHeight(),Common.FOCUS_FLY_DURATION, 1.0); //焦点框跟上去
},
//获取节目名称
getProgramRequest: function () {
//根据Id获取详情
let oGetProgramPara = {
"view": "json",
"start": 0,
"limit": 1,
"ids": this._strId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "Media/List", null, oGetProgramPara,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
this._strName = oJSONResult.resultSet[0].name;
if (oJSONResult.resultSet[0].type == 4) { //剧集
this._iProgramType = "animation";
} else if (oJSONResult.resultSet[0].type == 3) { //电影
this._iProgramType = "movie";
}
this.getIdsRequest();
} else {
cc.log("Error When Get ProgramRequest..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get ProgramRequest..." + error);
}
},
function (error) {
cc.log("Error When Get ProgramRequest..." + error);
}, this, "uuid");
},
//根据节目获取分类判断影片是否免费
getIdsRequest: function () {
//根据Id获取详情
let oGetIdsParas = {
"view": "json",
"start": 0,
"limit": 1,
"mediaId": this._strId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "Category/ListByMedia", null, oGetIdsParas,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
var strParentCId = oJSONResult.resultSet[0].parent_id;
if (strParentCId == this._strParentCId) {
this._iAuthStatus = 1;
}
//获取剧集
if (this._iEpisodeIndex && this._iProgramType == 'animation') {
this.getEpisodeRequest();
} else {
if (this._iAuthStatus != 1) { //判断下是否订购
}
this.getBookMarkRequest();
}
} else {
cc.log("Error When Get IdsRequest..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get IdsRequest..." + error);
}
},
function (error) {
cc.log("Error When Get IdsRequest..." + error);
}, this, "uuid");
},
//获取剧集数
getEpisodeRequest: function () {
let oGetEpisodeParas = {
"view": "json",
"start": 0,
"limit": 1,
"index": this._iEpisodeIndex,
"sortField": "index",
"sortDirection": "asc",
"mediaId": this._strId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "Episode/ListByMedia", null, oGetEpisodeParas,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
this._iEpisodeCount = oJSONResult.count;
var oProgram = oJSONResult.resultSet[0];
if (oProgram.id) {
if (oProgram.index == this._iEpisodeIndex) {
this._strMediaCode = oProgram.media_code;
this._strEpisodeId = oProgram.id;
this._strEpisodeName = oProgram.name; //电视剧有这个字段,电影没有
if (typeof (this._strEpisodeName) == 'undefined') {
this._strEpisodeName = this._strName;
}
this.getBookMarkRequest();
}
}
if (this._iAuthStatus != 1) { //判断是否订购
}
} else {
cc.log("Error When Get EpisodeRequest..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get EpisodeRequest..." + error);
}
},
function (error) {
cc.log("Error When Get EpisodeRequest..." + error);
}, this, "uuid");
},
//获取播放记录的时间
getBookMarkRequest: function () {
let oGetEpisodeParas = {
"view": "json",
"start": 0,
"limit": 1,
"mediaId": this._strId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/ListBookmark", null, oGetEpisodeParas,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
if (oJSONResult.count != 0) {
if (this._strEpisodeId == oJSONResult.resultSet[0].episode_id) {
this._iPlayProgress = parseInt(oJSONResult.resultSet[0].start_time);
if (this._iAuthStatus != 1) { //未订购就从0开始播放
this._iPlayProgress = 1;
}
} else {
this._iPlayProgress = 1;
}
// this.playTheSong();
}
} else {
cc.log("Error When Get BookMark..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get BookMark..." + error);
}
},
function (error) {
cc.log("Error When Get BookMark..." + error);
}, this, "uuid");
},
//获取默认收藏
getDefaultCollectRequest: function () {
let oDefaultCollectRequestParameters = {
"view": "json",
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/GetDefaultCollection", null, oDefaultCollectRequestParameters,
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
this._strCollectDefaultId = oJSONResult.resultSet[0].id || "";
} else {
cc.log("Error When Get DefaultCollect..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get DefaultCollect..." + error);
}
},
function (error) {
cc.log("Error When Get DefaultCollect..." + error);
}, this, "uuid");
},
//该片是否收藏过
getMediaCollectionRequest: function () {
var self = this;
let oMediaCollectionParameters = {
"view": "json",
"mediaIds": this._strId,
"needCollection": "1",
"start": 0,
"limit": 1,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/ListMediaAdditional", null, oMediaCollectionParameters, //
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
var aCollectedSongs = oJSONResult.resultSet[0];
if (aCollectedSongs.collections[0]) {
if (aCollectedSongs.collections[0].media_id == this._strId) {//已收藏
this._bCollect = true;
cc.loader.loadRes('button/collected', cc.SpriteFrame, function (err, spriteFrame) {
spriteFrame.setRect(cc.rect(0, 0, 124, 60));
self.collectIcon.spriteFrame = spriteFrame;
});
} else {
this._bCollect = false;
cc.loader.loadRes('button/collect', cc.SpriteFrame, function (err, spriteFrame) {
spriteFrame.setRect(cc.rect(0, 0, 124, 60));
self.collectIcon.spriteFrame = spriteFrame;
});
}
} else {
this._bCollect = false;
cc.loader.loadRes('button/collect', cc.SpriteFrame, function (err, spriteFrame) {
spriteFrame.setRect(cc.rect(0, 0, 124, 60));
self.collectIcon.spriteFrame = spriteFrame;
});
}
} else {
cc.log("Error When Get MediaCollection..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get MediaCollection..." + error);
}
},
function (error) {
cc.log("Error When Get MediaCollection..." + error);
}, this, "uuid");
},
//由Android原生回调回来
getPlayUrlForFullScreen: function (playUrl) {
cc.log("getPlayUrlForFullScreen------------------------>" + playUrl);
this.videoPlay.remoteURL = playUrl; //
cc.find("VideoPlayer", this.node).on('ready-to-play', function (event) {
cc.log("ready-to-play---------------------------->");
this.videoPlay.play();
if (!this.playContainerCallback) { //定时隐藏控制背景函数
this.playContainerCallback = function () {
this.playContainer.opacity = 0;
}
}
this.unschedule(this.playContainerCallback);
this.playContainer.opacity = 255;
this.scheduleOnce(this.playContainerCallback, 5);
}, this);
},
playTheSong: function () {
cc.log("playTheSong-------------------------------->");
if (Utils.isMobile()) {
jsb.reflection.callStaticMethod("org/cocos2dx/javascript/ReflectActivity", "getPlayURL", "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V", this._strId, this._strEpisodeId, this._strAppId, "getPlayUrlForFullScreen");//获取播放器地址
}
// let oGetPlayURLPara = {
// "view": "json",
// "mediaId": this._strId,
// "episodeId": this._strEpisodeId,
// "appId": this._strAppId,
// "token": Common.TEST_API_TOKEN
// };
// Network.ajax("GET", Common.TOPDRAW_API_SERVER + "Platform/Play", null, oGetPlayURLPara, //能够传回去播放次数
// function (strResponse) {
// try {
// var oJSONResult = JSON.parse(strResponse);
// if (oJSONResult.businessCode == 'success') {
// this.playTitle.string = this._strEpisodeName;
// var strPlayURL = oJSONResult.resultSet[0].playurl;
// if (!strPlayURL) {
// //测试地址
// // strPlayURL = 'http://202.99.114.93/88888891/16/20180117/269801686/269801686.ts';
// // strPlayURL = "http://139.196.37.202:8080/sparrow.lab/80sTest_hd.mp4"; //测试地址
// }
// //strPlayURL = "http://202.99.114.93/88888891/16/20180117/269801686/269801686.ts"; //强制更改测试地址
// cc.log("play the song play URL -------------------->" + strPlayURL);
// this.videoPlay.remoteURL = strPlayURL; //
// //this.videoPlay.play();
// cc.find("VideoPlayer", this.node).on('ready-to-play', function (event) {
// cc.log("ready-to-play---------------------------->");
// this.videoPlay.play();
// if (!this.playContainerCallback) { //定时隐藏控制背景函数
// this.playContainerCallback = function () {
// this.playContainer.opacity = 0;
// }
// }
// this.unschedule(this.playContainerCallback);
// this.playContainer.opacity = 255;
// this.scheduleOnce(this.playContainerCallback, 5);
// }, this);
// } else {
// cc.log("Error When Get GetPlayURL..." + oJSONResult.description);
// }
// } catch (error) {
// cc.log("Exception When Get GetPlayURL..." + error);
// }
// },
// function (error) {
// cc.log("Error When Get GetPlayURL..." + error);
// }, this, "uuid");
},
//添加收藏
add2Collection: function () {
var self = this;
let oAddCollectionParameters = {
"view": "json",
"mediaId": this._strId,
"collectionId": this._strCollectDefaultId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/AddMedia2Collection", null, oAddCollectionParameters, //
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
this._bCollect = true;
cc.loader.loadRes('button/collected', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 60, 124, 60));
});
} else {
cc.log("Error When Get AddCollection..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get AddCollection..." + error);
}
},
function (error) {
cc.log("Error When Get AddCollection..." + error);
}, this, "uuid");
},
//取消收藏
removeFromCollection: function () {
var self = this;
let oRemoveCollectionParameters = {
"view": "json",
"mediaId": this._strId,
"collectionId": this._strCollectDefaultId,
"appId": this._strAppId,
"token": Common.TEST_API_TOKEN
};
Network.ajax("GET", Common.TOPDRAW_API_SERVER + "User/RemoveMediaFromCollection", null, oRemoveCollectionParameters, //
function (strResponse) {
try {
var oJSONResult = JSON.parse(strResponse);
if (oJSONResult.businessCode == 'success') {
this._bCollect = false;
cc.loader.loadRes('button/collect', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 60, 124, 60));
});
} else {
cc.log("Error When Get RemoveCollection..." + oJSONResult.description);
}
} catch (error) {
cc.log("Exception When Get RemoveCollection..." + error);
}
},
function (error) {
cc.log("Error When Get RemoveCollection..." + error);
}, this, "uuid");
},
initFocus: function () {
this.playOrPauseIcon.spriteFrame.setRect(cc.rect(0, 68, 68, 68)); //默认焦点
var fiPlayIcon = this.playOrPauseIcon.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_play'] = this.playOrPauseIcon;
fiPlayIcon.init(
null, true
);
this.progressBarIcon.spriteFrame.setRect(cc.rect(0, 0, 44, 37));
var fiProgressBar = this.progressBarIcon.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_progress_bar'] = this.progressBarIcon;
fiProgressBar.init(
null, true
);
this.volumeIcon.spriteFrame.setRect(cc.rect(0, 0, 68, 68));
var fiVolume = this.volumeIcon.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_volume'] = this.volumeIcon;
fiVolume.init(
null, true
);
this.orderIcon.spriteFrame.setRect(cc.rect(0, 0, 124, 60));
var fiOrder = this.orderIcon.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_order_button'] = this.orderIcon;
fiOrder.init(
null, true
);
// this.collectIcon.spriteFrame.setRect(cc.rect(0, 0, 124, 60));
var fiCollect = this.collectIcon.addComponent(FocusInfo);//
this._aFocusTargets[0]['to_collect'] = this.collectIcon;
fiCollect.init(
null, true
);
var nodeFocus = new cc.Node('nodeFocus');
this.node.addChild(nodeFocus, 10);
this._cFocus = this.node.getChildByName('nodeFocus').addComponent(TVFocus);
this._cFocus.init('focusContainer', this,
this.playOrPauseIcon.getComponent(FocusInfo),
Common.SCREEN_WIDTH, Common.SCREEN_HEIGHT, 6, 4, 1.0);
// this._cFocus.hide(); //所有焦点都是隐藏的
},
keyDownDirection: function (Direct) {
var fiFocusTarget = null;
var fiCurrentFocus = this._fiCurrentFocus;
var oScrollParameter = null;
this.progressBarIcon.getComponent(FocusInfo).setEnable(true); //如果左右跳转只能在下面跳,别跑到进度条去了
if (0 == this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, 0, Direct).node.name.indexOf("ProgressBarIcon")
&& (Direct == Common.MOVE_DIRECTION_LEFT || Direct == Common.MOVE_DIRECTION_RIGHT)) {
this.progressBarIcon.getComponent(FocusInfo).setEnable(false);
}
fiFocusTarget = this._cFocus.findTarget(fiCurrentFocus, this._aFocusTargets, 0, Direct);
fiFocusTarget = this.checkFocusTarget(fiFocusTarget);
if (!fiFocusTarget) { return; }
this._cFocus.flyFocus(this._fiCurrentFocus, fiFocusTarget, Direct, null, oScrollParameter);
},
checkFocusTarget: function (fiFocusTarget) {
return fiFocusTarget;
},
onKeyDown: function (event) {
this._super(event);
var self = this;
if (!this.volumeControlCallback) { //定时隐藏声音函数
this.volumeControlCallback = function () {
this.volumeControl.opacity = 0;
}
}
if (!this.playContainerCallback) { //定时隐藏控制背景函数
this.playContainerCallback = function () {
this.playContainer.opacity = 0;
}
}
this.unschedule(this.playContainerCallback);
this.playContainer.opacity = 255;
this.scheduleOnce(this.playContainerCallback, 5);
switch (event.keyCode) {
case cc.macro.KEY.up:
case Common.ANDROID_KEY.up:
// if (0 == this._fiCurrentFocus.node.name.indexOf('VolumeIcon')) { //测试声音【0,1】
// var currentVolume = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "raiseVolume", "()I");
// if (this.volumeValue.node.height < this._iVolumeContainerHeight) {//播放器声音会出现0.99999999
// this.volumeValue.node.height = this._iVolumeContainerHeight * (currentVolume / this._iMaxVolume);//更新声音进度条
// this.unschedule(this.volumeControlCallback);
// this.volumeControl.opacity = 255;
// this.scheduleOnce(this.volumeControlCallback, 3);
// // this.videoPlay.volume = Math.ceil((this.videoPlay.volume + 0.1) * 10) / 10;
// // this.volumeValue.node.height = this._iVolumeContainerHeight * this.videoPlay.volume;
// }
// return; //焦点框上上下下不允许跳到其他地方
// }
this.keyDownDirection(Common.MOVE_DIRECTION_UP);
break;
case cc.macro.KEY.right:
case Common.ANDROID_KEY.right:
// if (0 == this._fiCurrentFocus.node.name.indexOf('ProgressBarIcon')) { //测试快进
// this.videoPlay.currentTime += this._iPlayProgressStep;
// this.playProgressBarValue.node.width = this._iPlayContainerWidth * (this.videoPlay.currentTime / this._iVideoPlayTotalTime);
// this._cFocus.fly(this.playProgressBarValue.node.width, this._fiCurrentFocus.getTop(),
// this._fiCurrentFocus.getWidth(), this._fiCurrentFocus.getHeight(), Common.FOCUS_FLY_DURATION, 1.0); //焦点框跟上去
// return;
// }
this.keyDownDirection(Common.MOVE_DIRECTION_RIGHT);
break;
case cc.macro.KEY.down:
case Common.ANDROID_KEY.down:
// if (0 == this._fiCurrentFocus.node.name.indexOf('VolumeIcon')) { //测试声音【0,1】
// var currentVolume = jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "lowerVolume", "()I");
// if (this.volumeValue.node.height > 0) {
// this.volumeValue.node.height = this._iVolumeContainerHeight * (currentVolume / this._iMaxVolume);//更新声音进度条
// this.unschedule(this.volumeControlCallback);
// this.volumeControl.opacity = 255;
// this.scheduleOnce(this.volumeControlCallback, 3);
// this.videoPlay.volume = Math.floor((this.videoPlay.volume - 0.1) * 10) / 10;
// // this.volumeValue.node.height = this._iVolumeContainerHeight * this.videoPlay.volume;
// return;
// }
// }
this.keyDownDirection(Common.MOVE_DIRECTION_DOWN);
break;
case cc.macro.KEY.left:
case Common.ANDROID_KEY.left:
// if (0 == this._fiCurrentFocus.node.name.indexOf('ProgressBarIcon')) { //测试快进
// this.videoPlay.currentTime -= this._iPlayProgressStep;
// this.playProgressBarValue.node.width = this._iPlayContainerWidth * (this.videoPlay.currentTime / this._iVideoPlayTotalTime);
// this._cFocus.fly(this.playProgressBarValue.node.width, this._fiCurrentFocus.getTop(),
// this._fiCurrentFocus.getWidth(), this._fiCurrentFocus.getHeight(), Common.FOCUS_FLY_DURATION, 1.0); //焦点框跟上去
// return;
// }
this.keyDownDirection(Common.MOVE_DIRECTION_LEFT);
break;
case cc.macro.KEY.enter:
case cc.macro.KEY.space:
case Common.ANDROID_KEY.enter:
if (0 == this._fiCurrentFocus.node.name.indexOf('PlayOrPauseIcon')) {
if (this.videoPlay.isPlaying()) {
this._bPlay = false;
this.videoPlay.pause();
cc.loader.loadRes('button/stop', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 68, 68, 68));
});
} else {
this._bPlay = true;
this.videoPlay.play();
cc.loader.loadRes('button/play', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 68, 68, 68));
});
}
return;
} else if (0 == this._fiCurrentFocus.node.name.indexOf('CollectIcon')) { //收藏OR取消收藏
if (!this._bCollect) {
this.add2Collection();
} else {
this.removeFromCollection();
}
return;
}
this.doCurrentFocusTVLinkAction(Common.TV_LINK_ACTION_CLICK);
break;
case cc.macro.KEY.backspace:
case Common.ANDROID_KEY.back:
if (this.videoPlay.isPlaying()) { //如果有播放视频就停止
this.videoPlay.stop();
}
this.backAScene();
// cc.log("退出应用测试--------------------------------------》");
// if (cc.sys.isNative) { //考虑放到首页所有图片加载完成后显示
// //Remove Loading Pic
// jsb.reflection.callStaticMethod("org/cocos2dx/javascript/AppActivity", "restartApp", "(Ljava/lang/String;)V", "this is a message from js");
// }
break;
}
},
onBeforeFocusChange: function (event) {
this._super(event);
var self = this;
let fiFrom = event.detail.from;
// if (0 == fiFrom.node.name.indexOf('VolumeIcon') || 0 == fiFrom.node.name.indexOf('OrderButtonIcon') || 0 == fiFrom.node.name.indexOf('ProgressBarIcon')) {
// fiFrom.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
// }
if (0 == fiFrom.node.name.indexOf('VolumeIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/vocal', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
});
}
if (0 == fiFrom.node.name.indexOf('OrderButtonIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/noSubscribe', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
});
}
if (0 == fiFrom.node.name.indexOf('ProgressBarIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('/button/progress_focus', cc.Texture2D, function (err, texture) {
fiFrom.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, fiFrom.node.width, fiFrom.node.height));
});
}
if (0 == fiFrom.node.name.indexOf('CollectIcon')) {
if (this._bCollect) {
cc.loader.loadRes('button/collected', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 124, 60));
});
} else {
cc.loader.loadRes('button/collect', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 124, 60));
});
}
}
if (0 == fiFrom.node.name.indexOf('PlayOrPauseIcon')) { //播放和暂停按钮不一样
if (this._bPlay) {
cc.loader.loadRes('button/play', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 68, 68));
})
} else {
cc.loader.loadRes('button/stop', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 0, 68, 68));
})
}
}
},
onAfterFocusChange: function (event) {
this._super(event);
var self = this;
let fiTo = event.detail.to;
if (0 == fiTo.node.name.indexOf('VolumeIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/vocal', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
});
}
if (0 == fiTo.node.name.indexOf('OrderButtonIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/noSubscribe', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
});
}
if (0 == fiTo.node.name.indexOf('ProgressBarIcon')) {
// fiTo.node.getComponent(cc.Sprite).spriteFrame.setRect(cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
cc.loader.loadRes('button/progress_focus', cc.Texture2D, function (err, texture) {
fiTo.node.getComponent(cc.Sprite).spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, fiTo.node.height, fiTo.node.width, fiTo.node.height));
});
}
if (0 == fiTo.node.name.indexOf('CollectIcon')) {
if (this._bCollect) {
cc.loader.loadRes('button/collected', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 60, 124, 60));
});
} else {
cc.loader.loadRes('button/collect', cc.Texture2D, function (err, texture) {
self.collectIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 60, 124, 60));
});
}
}
if (0 == fiTo.node.name.indexOf('PlayOrPauseIcon')) {
if (this._bPlay) {
cc.loader.loadRes('button/play', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 68, 68, 68));
})
} else {
cc.loader.loadRes('button/stop', cc.Texture2D, function (err, texture) {
self.playOrPauseIcon.spriteFrame = new cc.SpriteFrame(texture, cc.rect(0, 68, 68, 68));
})
}
}
},
doCurrentFocusTVLinkAction: function (strAction) {
let strTVLink = this._fiCurrentFocus.getTVLink();
var joTVLink = null;
try {
joTVLink = JSON.parse(strTVLink);
let jaOperationList = joTVLink.click;
for (let i = 0; i < jaOperationList.length; i++) {
switch (jaOperationList[i].action) {
default:
this.doTVLinkAction(jaOperationList[i]);
break;
}
}
} catch (error) {
cc.log("runTVLinkAction Exception..." + error);
}
},
onDestroy: function () {
cc.director.emit('stop_render'); //分发事件
},
});