Getting an audio error in terminal regarding channel 0?

Hi @Appvism,

What happens if you start the next track after, say, a 100 millisecond delay? Perhaps internally, it doesn’t like that you’re instantly starting another stream on the same channel in essentially the same time-step.

Brent

Hi there,

OK, let me try that, thanks for the further suggestions appreciate it!

Regarding my earlier comment: when i use audio.stop(1) before playing the next track, when i then change scene back to the main menu the music (on the menu screen) actually fails to play (though the audio error warning still appears).

Out of curiosity guys, are my functions (from my second post above) to loop continuously between the two tracks ok? Do you have alternative suggestions in which to implement this instead?

Thanks again,

Hi @Appvism,

I’d probably condense it into one local function, but that’s just me. :slight_smile:

Brent

Your method should work.  When I’ve done something like that in the past, I’ve looped the same song for the level and I change songs when the level changes. 

One thing I might recommend is it sounds like your audio is not tied to the scene itself.  If it’s not scene dependent then I would load the sounds in main.lua and have that code in main.lua so it’s not tied to scenes.   

Cheers guys. Actually, i usually just loop a single track for each level but in this case the level is potentially endless (though practically unlikely), hence the need for me to not use a single looping track and at the same time, have the tracks repeat themselves as a sort of playlist.

By the way, i tried adding a slight delay as well before playing the next track but that didn’t work for me. Think i’ll have a rethink about this - perhaps not tie it to the scene or split into mini levels…

Thanks,

Hi @Appvism,

As a loose definition, channel 0 refers to “all channels”, but this is an odd message nonetheless. This doesn’t point so much to setting the channel (volume) but rather trying to play on that channel (but again, it’s odd that it’s reporting 0). Are you stopping the music when you change scenes? Are you possibly exceeding 32 channels by playing many sounds at once?

Best regards,

Brent

Hi there,

Thanks for the quick reply. I’ve had a further look into this to try and debug and fix it. There problem, in my case, seems to be that i am trying to loop through three tracks one after the other in a continuous loop. I believe i am properly stopping, disposing and nilling everything on scene change.

Specifically i having something like this to:

--At top, i load the music local soundMusic1 = audio.loadStream("track1.wav"); local musicChannel1 local soundMusic2 = audio.loadStream("track2.wav"); local musicChannel2          --Then, music is played with the following: local function playNewTrack() musicChannel2 = audio.play(soundMusic2, { channel=2, loops=0, fadein=1000, onComplete=startMusic}) end function startMusic() musicChannel1 = audio.play(soundMusic1, { channel=1, loops=0, fadein=1000, onComplete=playNewTrack}) end startMusic() --play music  

Essentially, what i want to do is after track1 finishes, play track2. When that finishes, loop back and repeat. Is the above sample code correct?

If i just have a single track endlessly looping, everything is fine with no errors. With the above, i get an audio error when the scene changes. Note: in my current code (not the sample above), i think i’ve used the same channel=1 for all the music. Whereas for the above, i think it gives me a data is null error…

Any thoughts?

Cheers,

Why not play them both on Channel 1 and do an audio.stop(1) before you call play?

Rob

Hi there,

So something like:

local function playNewTrack() audio.stop(1); musicChannel2 = audio.play(soundMusic2, { channel=1, loops=0, fadein=1000, onComplete=startMusic}) end function startMusic() audio.stop(1); musicChannel1 = audio.play(soundMusic1, { channel=1, loops=0, fadein=1000, onComplete=playNewTrack}) end startMusic() --play music  

When i try this, the terminal gives: “Warning: audio error: Can’t play because data is NULL”.

Which warning is the less of two evils?..

Is it playing with the warning?

No, the music is playing fine in the simulator. When i change scenes however, the warning pops up in the terminal. This is the case for both of the warnings mentioned above. Before changing scenes, i obviously audio.stop() and then dispose and nil everything.

It doesn’t seem to crash the app for eg, but would prefer to fix this and get rid of the warning message…

Anyone else coming across this audio error?

Cheers,

Hi @Appvism,

What happens if you start the next track after, say, a 100 millisecond delay? Perhaps internally, it doesn’t like that you’re instantly starting another stream on the same channel in essentially the same time-step.

Brent

Hi there,

OK, let me try that, thanks for the further suggestions appreciate it!

Regarding my earlier comment: when i use audio.stop(1) before playing the next track, when i then change scene back to the main menu the music (on the menu screen) actually fails to play (though the audio error warning still appears).

Out of curiosity guys, are my functions (from my second post above) to loop continuously between the two tracks ok? Do you have alternative suggestions in which to implement this instead?

Thanks again,

Hi @Appvism,

I’d probably condense it into one local function, but that’s just me. :slight_smile:

Brent

Your method should work.  When I’ve done something like that in the past, I’ve looped the same song for the level and I change songs when the level changes. 

One thing I might recommend is it sounds like your audio is not tied to the scene itself.  If it’s not scene dependent then I would load the sounds in main.lua and have that code in main.lua so it’s not tied to scenes.   

Cheers guys. Actually, i usually just loop a single track for each level but in this case the level is potentially endless (though practically unlikely), hence the need for me to not use a single looping track and at the same time, have the tracks repeat themselves as a sort of playlist.

By the way, i tried adding a slight delay as well before playing the next track but that didn’t work for me. Think i’ll have a rethink about this - perhaps not tie it to the scene or split into mini levels…

Thanks,

I had the exact same problem and using audio.stop(channel) got rid of the error message.

I had the exact same problem and using audio.stop(channel) got rid of the error message.

I’ve been having the same problem, and for me, it was because in a previous scene I was accidentally calling  scene:exitScene  twice (due to not cancelling a timer, whose listener function was calling it scene:exitScene after it had already been called), which was triggering audio.stop() and audio.reserveChannels() twice. I’m not sure exactly why, but in the next scene, I’d eventually get the same error you were reporting above.

I’ve been having the same problem, and for me, it was because in a previous scene I was accidentally calling  scene:exitScene  twice (due to not cancelling a timer, whose listener function was calling it scene:exitScene after it had already been called), which was triggering audio.stop() and audio.reserveChannels() twice. I’m not sure exactly why, but in the next scene, I’d eventually get the same error you were reporting above.