class InitEZUilit2 {
  _player = null;

  _loading = false; // 视频加载状态

  _statusChangeCallback = null; // 函数，注意返回加载状态变化

  url = ""; // 视频播放地址
  width = 367;
  height = 180;

  constructor(token, url, domId) {
    this.url = url;
    this._player = new EZUIKit.EZUIKitPlayer({
      id: domId, // 视频容器ID
      accessToken: token,
      url,
      templete: "security", // 标准版
      header: ["zoom"],
      width: this.width,
      height: this.height,
      footer: ["fullScreen"],
      handleSuccess: () => {
        this.handleSuccess();
      },
    });
  }

  // 视频地址发生变化
  set playUrl(value) {
    this.url = value;
    this._loading = true;
    this.palyEZUillit(value);
  }

  // 设置状态变化的回调函数
  setStatusChangeCallback(callback) {
    this._statusChangeCallback = callback;
  }
  // 播放成功触发
  handleSuccess() {
    this._loading = false;
    if (this._statusChangeCallback) {
      this._statusChangeCallback(false);
    }
  }
  // 视频停止
  stopEZUilit() {
    return this._player.stop();
  }

  // 视频播放
  palyEZUillit(url, accessToken) {
    if (!this._player) return;
    this._loading = true;
    this._player.stop().then((res) => {
      accessToken
        ? this._player.play({ url, accessToken })
        : this._player.play({ url });
    });
  }

  // 销毁
  onDestroy() {
    this._player.destroy();
    this._player = null;
  }
}
// 同个token 只修改地址
// player.playUrl = "ezopen://open.ys7.com/E47425089/1.hd.live"
// 如果是不同设备播放视频 可以使用下面的方式有两个参数 url,token
// player.palyEZUillit("ezopen://open.ys7.com/E47425089/1.hd.live")
