The API indicates that
audio.stop ({channel = 1})
should work. It generates a Runtime error for me. Does audio.stop () only work with an object handle as parameter? [import]uid: 1560 topic_id: 24403 reply_id: 324403[/import]
The API indicates that
audio.stop ({channel = 1})
should work. It generates a Runtime error for me. Does audio.stop () only work with an object handle as parameter? [import]uid: 1560 topic_id: 24403 reply_id: 324403[/import]
Hi
What is exactly the error message you are getting? It would help if you can share some more code
Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 24403 reply_id: 98653[/import]
Hi Raul…here you go…
Runtime error
attempt to index a nil value
stack traceback:
[C]: ?
[C]: in function ‘stop’
/Users/…/main.lua:533: in function ‘stopBackgroundMusic’
audio.reserveChannels( 1 )
...
local function changeMusic (event)
print ("Change Music")
if event.completed then
print ("Completed")
sounds.toggle = not sounds.toggle
audio.rewind(event.handle)
if (musicOn == 1 and gameOn == 1) then
timer.performWithDelay(2000, playBackgroundMusic)
end
else
print ("Not completed")
sounds.toggle = not sounds.toggle
audio.stop(event.handle)
audio.rewind(event.handle)
if (musicOn == 1 and gameOn == 1) then
timer.performWithDelay(2000, playBackgroundMusic)
end
end
end
playBackgroundMusic = function ()
local loopCount = math.random(0,2)
if (sounds.toggle) then
audio.setVolume( 0.75, { channel=1 } )
audio.play(sounds.backgroundMusic, { channel=1, loops=-1, onComplete=changeMusic } )
audio.fadeOut({ channel=1, time=5000 } )
else
audio.setVolume( 0.75, { channel=1 } )
audio.play(sounds.backgroundMusicAlt, { channel=1, loops=-1, onComplete=changeMusic } )
audio.fadeOut({ channel=1, time=5000 } )
end
end
local stopBackgroundMusic = function ()
audio.stop({channel=1})
end
The code works without error if it’s just audio.stop(), but that’s interfering with other sound effects. I was hoping I could just silence the background music channel rather than tracking which background track was playing and silencing that one.
Does audio.fadeOut clear a previous channel assignment? [import]uid: 1560 topic_id: 24403 reply_id: 98656[/import]
I was able to things to work, sort of, using the “secret” Corona audio API:
local stopBackgroundMusic = function ()
local source = audio.getSourceFromChannel(1)
audio.stop(source)
end
audio.stop() seems to like an object better than the channel reference. (Actually, I see now from the docs that audio.fade is clearing that channel, which would be the source of the nil error.)
But this brings up another problem. Audio.stop () appears not to override an audio.fadeOut () on the same channel, probably to let the timer clear itself.
So is there any way to cancel/complete pending fades? [import]uid: 1560 topic_id: 24403 reply_id: 98663[/import]
Hmmm yes… I remember I had this problem on my first project… I recall I managed to solve it by stopping audio like this:
if audio.isChannelPlaying( 1 ) then
audio.stop ( 1 )
end
and ALSO setting the volume of that channel to 1 when playing again:
audio.setVolume( 1, { channel=1 })
Please let me know if that worked.
Raúl Beltrán
MIU Games [import]uid: 44101 topic_id: 24403 reply_id: 98673[/import]
From the API:
Remarks:
Note: When you fade the volume, you are changing the volume of the channel. This value is persistent and it is your responsibility to reset the volume on the channel (see audio.setVolume) if you want to use the channel again later. [import]uid: 44101 topic_id: 24403 reply_id: 98675[/import]
I think you found a bug.
audio.stop({channel=1}) and audio.stop({source=audio.getSourceFromChannel(1)} were intended to work. I think Corona is mistaking looking for the table as the second parameter instead of the first.
audio.stop( nil, {channel=1}) seems to work but it is not supposed to be this way.
audio.stop(channel) does work though. (This is what most people use.) But what you are doing (passing the source) is wrong. I’m surprised that works for you.
Would you please file a bug report so I don’t lose track of this.
[import]uid: 7563 topic_id: 24403 reply_id: 98679[/import]