// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html

var httpUtils = require("HttpUtils");
cc.Class({
  extends: require("Base"),
  properties: {
    player: {
      default: null,
      type: cc.VideoPlayer
    },
    seekbar: {
      default: null,
      type: cc.ProgressBar
    },
    btn_click: {
      default: null,
      type: cc.Button
    },
    btn_click_text: {
      default: null,
      type: cc.Label
    },
    player_currentTime: {
      default: null,
      type: cc.Label
    },
    player_duration: {
      default: null,
      type: cc.Label
    }
  },

  // LIFE-CYCLE CALLBACKS:

  onLoad() {
    setViewTouch(
      this.btn_click,
      null,
      function(event) {
        if (this.player.isPlaying()) {
          this.player.pause();
          this.btn_click_text.string = "播放";
        } else {
          this.btn_click_text.string = "暂停";
          this.player.play();
        }
      },
      null,
      this
    );
  },

  start() {},

  update(dt) {
    this.player_currentTime.string = this.player.currentTime + "";
    this.player_duration.string = this.player.getDuration() + "";
    this.seekbar.node.width = this.player.getDuration();
    let aa = this.player.currentTime / this.player.getDuration();
    // cc.log('====', this.seekbar.node.width)
    this.seekbar.progress = aa;
  }
});
