VideoPlayerCtrl.js 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. function getStatus (event) {
  2. switch (event) {
  3. case cc.VideoPlayer.EventType.PLAYING:
  4. return 'PLAYING';
  5. case cc.VideoPlayer.EventType.PAUSED:
  6. return 'PAUSED';
  7. case cc.VideoPlayer.EventType.STOPPED:
  8. return 'STOPPED';
  9. case cc.VideoPlayer.EventType.COMPLETED:
  10. return 'COMPLETED';
  11. case cc.VideoPlayer.EventType.META_LOADED:
  12. return 'META_LOADED';
  13. case cc.VideoPlayer.EventType.CLICKED:
  14. return 'CLICKED';
  15. case cc.VideoPlayer.EventType.READY_TO_PLAY:
  16. return 'READY_TO_PLAY';
  17. default:
  18. return 'NONE';
  19. }
  20. };
  21. cc.Class({
  22. extends: cc.Component,
  23. properties: {
  24. // videoPlayer: cc.VideoPlayer,
  25. // statusLabel: cc.Label,
  26. // currentTime: cc.Label,
  27. // resSwitchBtnLabel: cc.Label,
  28. // controlButtons: cc.Node,
  29. // keep_Ratio_Switch: cc.Node,
  30. // playVideoArea: cc.Node,
  31. },
  32. start () {
  33. // TipsManager.init();
  34. // this.controlButtons.active = false;
  35. // this.keep_Ratio_Switch.active = !cc.sys.isBrowser;
  36. // this.playVideoArea.on('touchstart', () => {
  37. // this.videoPlayer.play();
  38. // this.playVideoArea.active = false;
  39. // });
  40. this.videoPlayer = this.node.getComponent(cc.VideoPlayer);
  41. },
  42. onVideoPlayerEvent (sender, event) {
  43. // this.statusLabel.string = 'Status: ' + getStatus(event);
  44. if (event === cc.VideoPlayer.EventType.CLICKED) {
  45. if (this.videoPlayer.isPlaying()) {
  46. this.videoPlayer.pause();
  47. } else {
  48. this.videoPlayer.play();
  49. }
  50. }
  51. // else if (event === cc.VideoPlayer.EventType.READY_TO_PLAY || event === cc.VideoPlayer.EventType.META_LOADED) {
  52. // this.controlButtons.active = true;
  53. // }
  54. },
  55. toggleFullscreen () {
  56. if (
  57. cc.sys.isBrowser &&
  58. cc.sys.browserType === cc.sys.BROWSER_TYPE_MOBILE_QQ &&
  59. cc.sys.browserVersion <= 7.2 &&
  60. /Nexus 6/.test(navigator.userAgent)
  61. ) {
  62. TipsManager.createTips(i18n.t('cases/02_ui/09_videoplayer/videoPlayer.nonsupport_fullscreen'));
  63. return cc.log('May be crash, so prohibit full screen');
  64. }
  65. this.videoPlayer.isFullscreen = true;
  66. },
  67. toggleVisibility () {
  68. this.videoPlayer.enabled = !this.videoPlayer.enabled;
  69. this.playVideoArea.active = this.videoPlayer.enabled;
  70. },
  71. keepRatioSwitch () {
  72. this.videoPlayer.keepAspectRatio = !this.videoPlayer.keepAspectRatio;
  73. },
  74. switchOnlineVideo () {
  75. this.videoPlayer.remoteURL = 'http://www.w3school.com.cn/i/movie.mp4';
  76. this.videoPlayer.resourceType = cc.VideoPlayer.ResourceType.REMOTE;
  77. this.playVideoArea.active = true;
  78. },
  79. switchLoaclVide () {
  80. this.videoPlayer.resourceType = cc.VideoPlayer.ResourceType.LOCAL;
  81. this.playVideoArea.active = true;
  82. },
  83. play () {
  84. this.videoPlayer.play();
  85. this.playVideoArea.active = false;
  86. },
  87. pause () {
  88. this.videoPlayer.pause();
  89. },
  90. stop () {
  91. this.videoPlayer.stop();
  92. },
  93. update () {
  94. // if (this.currentTime && this.videoPlayer.currentTime >= 0) {
  95. // this.currentTime.string = this.videoPlayer.currentTime.toFixed(2) + ' / ' + this.videoPlayer.getDuration().toFixed(2);
  96. // }
  97. }
  98. });