cc.audioEngine.play changed ?( Cocoscreator2.4.2 )

I want to update a myapp working in an old version.(cocoscreator 1.9.3)

I downloaded Cocoscreator2.4.2 and I made my app by this new version Cocoscreator.

There was music I wanted to play forever(Even if the scene changes).
So I use this source↓↓↓

var timeCallback = function (dt) {
cc.audioEngine.play(this.start_bgm, true, 1);
}
this.scheduleOnce(timeCallback, 1);

I could play music forever in cocoscreator 1.9.3.

If I made this code↓

var timeCallback = function (dt) {
cc.audioEngine.play(this.start_bgm, true, 1);
this.scheduleOnce(timeCallback, 1);

var timeCallback_2 = function (dt) {
cc.director.loadScene("1day")
}
this.scheduleOnce(timeCallback_2, 3);

But… I could not play music forever in this program(cocoscreator 2.4.2)

Is there easy solution?

I would be grateful if someone teach me…

I test your code on web browser, but didn’t reproduce your problem.


        var timeCallback = function (dt) {
            cc.audioEngine.play(this.start_bgm, true, 1);
        }
        this.scheduleOnce(timeCallback, 1);
        
        var timeCallback_2 = function (dt) {
            cc.director.loadScene("test")
        }
        this.scheduleOnce(timeCallback_2, 3);

do you mean that the bgm stopped when the scene changes and can’t be played anymore ?
and can you tell which platform you meet this problem ?

1 Like

Thank you for reply.

Yes…


  1. (Scene 1)bgmA start
    →After Scene1 is loaded, I’m running this program →cc.director.loadScene(“Scene2”)

  2. (Scene 2)bgmA stop…
    ※I want to play bgmA forever.


I use macbookpro 2020(os Catalina).
This phenomenon occurs cocoscreator’s defalut simulator.

bgmA(audioclip) is mp3 data.

※I appreciate your efforts. Thank you for your cooperation.
※I’m working on improving my English.

Strange, I can’t even reproduce the problem you met on the Simulator Preview,
Could you upload a demo project so i can check out what the problem is ?

Sorry for the late reply.
I uploaded a sample project.

Would you mind checking my App project?

Sample.zip (7.8 MB)

hey hi, sorry for late reply too

I checked the Sample project you uploaded, thought that it was because the scene ‘1day’ you loaded has no ‘start_music’ script,

you can’t play your audio just because the script doesn’t execute

thank you for reply.

I loaded ‘start_music’ script in ‘copyright’.
After being displayed for a few seconds, I load the next ‘1day’ Scene.

The back music used in copyright stoped… when ‘1day’ Scene Loaded.

sorry to bother you,Could you check this, please?

it is because you’ve checked the auto release assets in the scene asset ‘copyright’
so the audio asset is auto released after you load scene

1 Like

Thank you very much!

I’m sorry I didn’t notice the simple part.
This was the cause. Now there is no problem.

Thanks again and keep in touch.
:smile:

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.