// components/diy-video/currentId.js

Component({
  options: {
    multipleSlots: true, // 在组件定义时的选项中启用多slot支持
  },
  /**
   * 组件的属性列表
   */

  properties: {
    options: null,
  },

  /**
   * 组件的初始数据
   */

  lifetimes: {
    attached: function () {
      // 在组件实例进入页面节点树时执行
      this.videoContext = wx.createVideoContext("myVideo");
      if (this.data.autoplay) {
        this.setData({
          play: false,
        });
      }
      console.log(this.data.play);
    },
    detached: function () {
      // 在组件实例被从页面节点树移除时执行
    },
  },
  // 以下是旧式的定义方式,可以保持对 <2.2.3 版本基础库的兼容
  attached: function () {
    // 在组件实例进入页面节点树时执行
  },
  detached: function () {
    // 在组件实例被从页面节点树移除时执行
  },

  ready: function () {
    // 在组件布局完成后执行,确保options参数中有data信息
    this.loadData();
  },

  data: {
    style: null,
    vdata: null,
    list: [],
  },

  /**
   * 组件的方法列表
   */
  methods: {
    async loadData() {
      let { options } = this.data;
      console.log("视频组", options);
      let { data, style, cloumn } = options;
      let { src, list } = data;
      this.setData({
        list,
        src,
        style,
        cloumn,
        vdata: data,
      });
    },

    bindButtonTap() {
      const that = this;
      wx.chooseVideo({
        sourceType: ["album", "camera"],
        maxDuration: 60,
        camera: ["front", "back"],
        success(res) {
          that.setData({
            src: res.tempFilePath,
          });
        },
      });
    },
    videoTap: function (e) {
      //获取video
      let { play } = this;
      this.videoContext = wx.createVideoContext("myVideo", this);
      if (this.data.play) {
        //开始播放
        this.videoContext.play(); //开始播放
        this.setData({
          play: false,
        });
      } else {
        //当play==false 显示图片 暂停

        this.videoContext.pause(); //暂停播放
        this.setData({
          play: true,
        });
      }
    },
    bindPlayVideo() {
      console.log("1");
      this.videoContext.play();
    },

    videoErrorCallback(e) {
      console.log("视频错误信息:");
      console.log(e.detail.errMsg);
    },
  },
});