新APP-语音播报

2024-01-10 15:00:36 阅读:3 编辑
 handleNewapConfig(){
    if(this.globalData.is_new_app){
     //需要定计时,直接执行,siteinfo还未加载完毕,会失败
      setTimeout(()=>{
        this.handleTrueNewapConfig();
      },200);
    }

  },
  handleTrueNewapConfig(){
    console.log("handleTrueNewapConfig");
    this.api.postWithPlugin('api_newapp|getConfig', 'newapp', {}).then((res) => {
      console.log(res);

      if(res.data.soundtip_open == 1){
        this.bindSoundTip();
      }
    }).catch((res) => {
      console.log(res);
      //this.tips(res);
    });
  },
  bindSoundTip(){
    if(this.globalData.is_new_app){
      let user_id = 0;
      let zhyshopInfo = wx.getStorageSync('zhyshopInfo');
      if (zhyshopInfo) {
        user_id = zhyshopInfo.id;
      }
      let param = {
        user_id: user_id,
      };
      this.api.postWithPlugin('api_newapp|getSoundTip', 'newapp', param).then((res) => {
        console.log(res);
        this.playSoundTip(res.data.title,res.data.sound_url);
        this.bindSoundTip();

      }).catch((res) => {
        //this.tips(res);
        this.bindSoundTip();
      });
    }
  },
  playSoundTip(title,src){
    /*
     let myaudio = wx.createInnerAudioContext();
        myaudio.autoplay =false;
        myaudio.src = "https://ai.n8y.cn/alipay_100_00.mp3";
        myaudio.onEnded(() => {
          console.log(" myaudio.onEnded");
        });
        myaudio.onError((res) => {
          console.log(" myaudio.onError",res);
        });
        myaudio.play();
    */
   const backgroundAudioManager = wx.getBackgroundAudioManager();
   backgroundAudioManager.stop();
   backgroundAudioManager.title = title;
   backgroundAudioManager.epname = '';
   backgroundAudioManager.singer = '';
   backgroundAudioManager.coverImgUrl = '';
   backgroundAudioManager.src = src;
   backgroundAudioManager.play();
  },