The solution for the applet's createInnerAudioContext to have no sound on iOS

Method 1: If the connection in src contains Chinese characters, you can use encodeURI to transcode it first and then perform play()

innerAudioContext.src = encodeURI(voicePath);

Method 2: If the src does not have Chinese, use autoplay. If it does not work, you can use the play() method to play. If play() does not work, you can add a timer to delay the playback.

const innerAudioContext = wx.createInnerAudioContext();
       
        innerAudioContext.autoplay = true;
        innerAudioContext.src = src;
        innerAudioContext.loop = true;
        innerAudioContext.onPlay(() => {
            console.log('开始播放')
        })
        innerAudioContext.onStop((res) => {
            console.log('停止播放')
        });
        // 第一种
        innerAudioContext.play();
        // 第二种  如果第一种没有效果
        setTimeout(() => {
            innerAudioContext.play();
        }, 10);

Method 3: Because the applet changes according to the mute mode of the system by default, we need to set obeyMuteSwitch to false, so that there will be sound even in mute mode, and configure it in the onLaunch life cycle of APP.JS

// ios端音频不能在静音下播放处理
        wx.setInnerAudioOption({
            obeyMuteSwitch: false,

            success: function (res) {
                console.log("开启静音模式下播放音乐的功能");
            },

            fail: function (err) {
                console.log("静音设置失败");
            },
        });

Guess you like

Origin blog.csdn.net/qq_37564189/article/details/125302980