Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

remigis's avatar

Audio.play()

axios.post(route('myRoute'), {goodsFlow: this.goodsFlow})
                .then(response => {
                    if (response.data.to !== null) {
                        this.boxBuildCenterAudios[response.data.to].play();
                        console.log(response.data.mix);
                        if (response.data.mix === true && this.sayMix === true) {
                            this.boxBuildCenterAudios[response.data.to].onended = () => {
                                    this.mixAudio.play();
                            }
                        }
                        this.$toast.add({
                            severity: 'success',
                            summary: 'Success',
                            detail: "Item added to: " + response.data.centerName,
                            life: 6000
                        });
                    } else {
                        this.$toast.add({
                            severity: 'info',
                            summary: 'Info',
                            detail: "Don't need",
                            life: 6000
                        });
                    }

I do 3 requests

response 1 :

to	"1"
mix	false
centerName	"Test"

response 2 :

to	"1"
mix	true
centerName	"Test"

response 3 :

to	"1"
mix	false
centerName	"Test"

The problem is that mix is fales in response 3 but this.mixAudio.play(); is executed

it is not executed in response 1. sayMix is true all the time

0 likes
1 reply
remigis's avatar
remigis
OP
Best Answer
Level 1
axios.post(route('boxBuildSubmitGoodsFlowId'), {goodsFlow: this.goodsFlow})
                .then(response => {
                    if (response.data.to !== null) {
                        this.boxBuildCenterAudios[response.data.to].play();
                        console.log(response.data.mix);
                        this.boxBuildCenterAudios[response.data.to].onended = () => {
                            if (response.data.mix === true && this.sayMix === true) {
                                this.mixAudio.play();
                            }
                        }

                        this.$toast.add({
                            severity: 'success',
                            summary: 'Success',
                            detail: "Item added to: " + response.data.centerName,
                            life: 6000
                        });
                    } else {
                        this.$toast.add({
                            severity: 'info',
                            summary: 'Info',
                            detail: "Don't need",
                            life: 6000
                        });
                    }

You need to do the check inside onended function

Please or to participate in this conversation.