SpriteVideoPlayer.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. cc.Class({
  2. extends: cc.Component,
  3. properties: {
  4. },
  5. onLoad () {
  6. this.videoTotalIndexNumArr = [
  7. 25,//1
  8. 27,//2
  9. 21,//3
  10. 52,//4
  11. 0,//5
  12. 25,//6
  13. 35,//7 71,//7
  14. 52,//8
  15. 54,//9
  16. 51,//10
  17. 52,//11
  18. 42,//12
  19. 34,//13
  20. 47,//14
  21. 45,//15
  22. 46,//16
  23. 52,//17
  24. 53,//18
  25. 21,//19
  26. 27,//20
  27. 35,//21
  28. 0,//22
  29. 0,//23
  30. 32,//24
  31. 46,//25
  32. ];
  33. this.videoFrameArr = [];
  34. this.currentRound = 0;
  35. },
  36. play(node,index,self,callback)
  37. {
  38. let sprite = node.getComponent(cc.Sprite);
  39. // console.log(this.videoFrameArr)
  40. this.currentPlayer = this.playLocalVideo(this.videoFrameArr,sprite,function () {
  41. callback(self);
  42. });
  43. },
  44. prepareCurrentRoundVideo(index,callback)
  45. {
  46. let self = this;
  47. this.currentRound = index;
  48. if(index!=0)
  49. {
  50. this.stop();
  51. for(let i=0;i<this.videoFrameArr.length;i++)
  52. {
  53. cc.loader.release(cc.loader.getDependsRecursively(this.videoFrameArr[i]));
  54. }
  55. this.videoFrameArr.length = 0;
  56. }
  57. this.scheduleOnce(function () {
  58. let forderName = 'Videos/'+(index+1).toString();
  59. let from = 0;
  60. let to = self.videoTotalIndexNumArr[index];
  61. if(to == 0) to = 1;
  62. self.prepareLocalPic(forderName,from,to,function () {
  63. callback();
  64. });
  65. },0.5);
  66. },
  67. prepareLocalPic(forderName,from,to,callback)
  68. {
  69. let self = this;
  70. let index = 0;
  71. let download = function()
  72. {
  73. if((index+from) == to)
  74. {
  75. callback();
  76. return ;
  77. }
  78. let path = forderName+'/'+(index+from).toString();
  79. cc.loader.loadRes(path, cc.SpriteFrame, function (err, spriteFrame) {
  80. self.videoFrameArr.push(spriteFrame);
  81. // console.log('path=',path)
  82. index++;
  83. download();
  84. });
  85. };
  86. download();
  87. },
  88. playLocalVideo(picArr,sprite,callback)
  89. {
  90. let index = 0;
  91. let playMovie = function () {
  92. if(index==picArr.length)
  93. {
  94. this.unschedule(playMovie);
  95. callback();
  96. return;
  97. }
  98. sprite.spriteFrame = picArr[index];
  99. index++;
  100. };
  101. this.schedule(playMovie,1/30);
  102. return playMovie;
  103. },
  104. stop()
  105. {
  106. // this.unschedule(this.currentPlayer);
  107. this.unscheduleAllCallbacks();
  108. },
  109. });