index.js 1.62 KB
Newer Older
侯体倬 committed
1
const app = getApp();
李嘉林 committed
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
const componentOptions = {
  // 组件选项
  options: {
    multipleSlots: true
  },
  behaviors: [],
  properties: {
    datas: {
      type: Object
    },
    indexs: {
      type:Number
    }
  },
  // 组件数据
  data: {
    isPageHidden: false, // 页面是否处于隐藏状态
    isPlay: false,
    videoContext:"",
  },
  // 数据监听器
  observers: {},
  // 组件方法
  methods: {
    init() {},
侯体倬 committed
27 28
    playVideo(e) {
      app.trackCpn(e, this.data.datas.componentName)
李嘉林 committed
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
      // 视频播放
      if (this.data.datas.componentData['nativeControl']) {
        return
      }
      let { isPlay } = this.data;
      if (isPlay) {
        console.log("暂停")
        this.videoContext.pause();
      } else {
        console.log("播放")
        this.videoContext.play();
      }
      isPlay = !isPlay;
      this.setData({ isPlay });
    }
  },
  // 组件生命周期
  lifetimes: {
    created() {},
    attached() {
      this.init();
    },
    ready() {
      this.videoContext = wx.createVideoContext(`videoId${this.data.indexs}`,this);
    },
    moved() {},
    detached() {}
  },
  definitionFilter() {},
  // 页面生命周期
  pageLifetimes: {
    // 页面被展示
    show() {
      const { isPageHidden } = this.data;

      // show事件发生前,页面不是处于隐藏状态时
      if (!isPageHidden) {
        return;
      }

      // 重新执行定时器等操作
    },
    // 页面被隐藏
    hide() {
      this.setData({
        isPageHidden: true
      });

      // 清除定时器等操作
    },
    // 页面尺寸变化时
    resize() {}
  }
};

Component(componentOptions);