create method

DivElement create()

Implementation

DivElement create() {
  DivElement divElement = DivElement();
  divElement.id = "lottie_anim";
  StyleElement styleElement = StyleElement();
  styleElement.type = "text/css";
  styleElement.innerHtml = """
        html,
        body {
          padding:0;
          margin:0;
          height: 100%;
          width: 100%;
        }
        #app{
         height: 100%;
         width: 100%;
        }
        """;
  // divElement.append(bodyNode);
  divElement.append(styleElement);
  var script = """
  //开启声音
  function cancelMute(){
    player.jessibuca.cancelMute();
    player.jessibuca.setKeepScreenOn();
  }
  //禁音
  function mute() {
          player.jessibuca.mute();
   }
   //是否禁音
   function isMute() {
        return player.jessibuca.isMute();
   }
   //暂停
   function pause() {
       player.jessibuca.pause();
   }
   //播放
   function play(res) {
         player.play(res)
   }
   //销毁
   function destroy(res) {
         player.destroy()
   }
  var player = {
    jessibuca:null,
    clearTime:null,
      inits:function(url) {
        this.create();
        this.jessibuca.setScaleMode(2);
        this.jessibuca.setTimeout(10)
        this.jessibuca.onPlay=()=>{
         window.callbackH5(1);
        }
        this.jessibuca.on("play", function (flag) {
            // player.jessibuca.cancelMute();
            window.callbackH5(1);
        })
        this.jessibuca.on('timeout', function () {
            //
            console.log('超时');
            window.callbackH5(2);
        });

      },
      create:function(options) {
        options = options || {};
        this.jessibuca = new window.Jessibuca(
          Object.assign({
              container:document.getElementById('app'),
              videoBuffer: 0.2, // 缓存时长
              loadingText: "",
              debug: false,
              forceNoOffscreen: true,
              isNotMute: false,
              hasVideo: true,
              keepScreenOn:true,
              hasAudio: true,
              encodeType: "h264",
              isResize:true,
              isFullResize:true,
              heartTimeoutReplay:true,
              heartTimeoutReplayTimes:0,
              // useWCS:true,
              // autoWasm:true
            },
            options
          )
        );

        this.jessibuca.on("error", (error) => {
             console.log("error===", error);
             window.callbackH5(2);
        });

      },
      play:function(url) {
        if(!this.jessibuca){
          this.create();
        }
        if(this.clearTime){
            clearTimeOut(this.clearTime);
            this.clearTime=null;
        }
        if (url) {
          if (this.jessibuca.hasLoaded()) {
            this.jessibuca.play(url).then(()=>{window.callbackH5(1);this.jessibuca.setKeepScreenOn(); });
          } else {
            this.jessibuca.on("load", () => {

              this.jessibuca.play(url).then(()=>{window.callbackH5(1);this.jessibuca.setKeepScreenOn();});
            });
          }
        }
      },
      destroy:function() {
        if(this.clearTime){
            clearTimeOut(this.clearTime);
             this.clearTime=null;
        }
        if (this.jessibuca) {
          this.jessibuca.destroy();
        }
        this.jessibuca = null;
      },
    }
    player.inits();
  """;
  ScriptElement scriptElement = ScriptElement();

  scriptElement.type = "text/javascript";
  scriptElement.innerHtml = script;
  DivElement player = DivElement();
  player.id = "app";
  divElement.append(player);
  divElement.append(scriptElement);
  return divElement;
}