playVideo.js 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Learn cc.Class:
  2. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
  3. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
  4. // Learn Attribute:
  5. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
  6. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
  7. // Learn life-cycle callbacks:
  8. // - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
  9. // - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
  10. var httpUtils = require("HttpUtils");
  11. cc.Class({
  12. extends: require("Base"),
  13. properties: {
  14. player: {
  15. default: null,
  16. type: cc.VideoPlayer
  17. },
  18. seekbar: {
  19. default: null,
  20. type: cc.ProgressBar
  21. },
  22. btn_click: {
  23. default: null,
  24. type: cc.Button
  25. },
  26. btn_click_text: {
  27. default: null,
  28. type: cc.Label
  29. },
  30. player_currentTime: {
  31. default: null,
  32. type: cc.Label
  33. },
  34. player_duration: {
  35. default: null,
  36. type: cc.Label
  37. }
  38. },
  39. // LIFE-CYCLE CALLBACKS:
  40. onLoad() {
  41. setViewTouch(
  42. this.btn_click,
  43. null,
  44. function(event) {
  45. if (this.player.isPlaying()) {
  46. this.player.pause();
  47. this.btn_click_text.string = "播放";
  48. } else {
  49. this.btn_click_text.string = "暂停";
  50. this.player.play();
  51. }
  52. },
  53. null,
  54. this
  55. );
  56. },
  57. start() {},
  58. update(dt) {
  59. this.player_currentTime.string = this.player.currentTime + "";
  60. this.player_duration.string = this.player.getDuration() + "";
  61. this.seekbar.node.width = this.player.getDuration();
  62. let aa = this.player.currentTime / this.player.getDuration();
  63. // cc.log('====', this.seekbar.node.width)
  64. this.seekbar.progress = aa;
  65. }
  66. });