WeChat Mini Programs uses wx.createInnerAudioContext () to get InnerAudioContext instance

problem description

in WeChat Mini Programs, I want to click the button to play or pause music. I use wx.createInnerAudioContext () to get the InnerAudioContext instance, then save InnerAudioContext to data, and control the music through the src property. Theoretically, after I call the play () method, InnerAudioContext.paused should be false, but it is not. InnerAudioContext.paused is false, only after I call the InnerAudioContext.onPlay () method to listen for audio playback events. The same is true for pausing music. You have to listen to the corresponding event to change the state of the paused. I would like to ask why you have to change the state after listening to the event. Or is there any other way to change the state of paused immediately? To ask the great god to solve the doubt, the code

is attached below.

related codes

    play(order) {
        if (this.data.playingSong) {
            // 
            if (this.data.playingSong.paused) {
                this.setData({
                    playerControlIcon: "../../assets/icon/play.jpg"
                })
                this.data.playingSong.play();
            } else {
                this.setData({
                    playerControlIcon: "../../assets/pause.jpg"
                })
                this.data.playingSong.pause();
                // 
                this.data.playingSong.offPause();
                this.data.playingSong.onPause(() => {
                    console.log("this.data.playingSong.paused", this.data.playingSong.paused)
                })
            }
        } else {
            // 
            this.setData({
                playerControlIcon: "../../assets/icon/play.jpg"
            })
            let audioContext = wx.createInnerAudioContext();
            audioContext.src = cdnUrl + "Dream It Possible.mp3";
            audioContext.play();
            // 
            audioContext.offPlay();
            audioContext.onPlay( () => {
                console.log("audioContext.paused", audioContext.paused)
                this.setData({
                    playingSong: audioContext
                })
            })
        }
    },
Oct.19,2021
Menu