I have this problem: I need to use a listener to determine the end of a sound. Then I need to start a different sound (without a listener).
It works OK when the first sound is completely played. But when the user’s action interrupts the first sound, the listener is not canceled but it is processed after the second sound ends.
[import]uid: 6932 topic_id: 1736 reply_id: 301736[/import]
Have you tried removing the listener after user interrupts the sound?
Could you post some sample code showing the problem?
Thanks,
-Tom [import]uid: 7559 topic_id: 1736 reply_id: 5113[/import]
Well, can you tell me, how can I remove onComplete listener?
There is no solution in API reference
https://developer.anscamobile.com/content/multimedia-features#Completion_Listener-1
There is how I create listener but nothing about removing…
When I tried remove it with
removeEventListener I haven’t assign to. I need remove listener in longe (mp3) sounds and there is no way how could I do it.
function completeFunction1()
--some code
print("1");
end
function completeFunction2()
--some other code
print("2");
end
function myFunctionTwo()
media.playSound("someSound2.mp3",completeFunction2,false);
end
media.playSound("someSound1.mp3",completeFunction1,false);
myButt:addEventListener("touch",myButtTouch);
function myButtTouch(event)
local t = event.target;
local phase = event.phase;
if "began" == phase then
-- Make target the top-most object
t.isFocus = true;
t:stopAtFrame(2);
elseif t.isFocus then
if "ended" == phase or "cancelled" == phase then
t.isFocus = false;
t:stopAtFrame(1);
if phase=="ended" then
myFunctionTwo();
end
end
end
end
If listener is done, everything is OK
but if I click on myButt while sound is still playing, sound1 is interupted and sound2 is going to play, but after complete sound2 is done completeFunction1 and it is bad. I need completeFunction2 to proceed.
thx
Sumeragi [import]uid: 6869 topic_id: 1736 reply_id: 5149[/import]
You can only play one sound at a time with media.playSound. If the user interrupts sound1 then you need to call media.stopSound() before starting sound2. This will remove the event listener for sound1.
Your media.playSound(“someSound1.mp3”,completeFunction1,false); should be written as:
media.playSound(“someSound1.mp3”,completeFunction1);
The “false” parameter should not be there. If you want the sound to loop, you replace the completeFunction1 function with “true”.
-Tom [import]uid: 7559 topic_id: 1736 reply_id: 5150[/import]
I don? wont disappoint you, but unfortunately you are wrong.
removing parameter “false” in playSound(“someSound1.mp3”,completeFunction1,false)
has no effect on removing listener
I also tried media.stopSound() call but it still calls first listener.
Please try this sample and you will see.http://leteckaposta.cz/351045374
after run there will be yellow ring and dog will be barking. after complete first sound console will print “1” and next sound will be played. after second sound conosle will print “2”
try click to yellow ring while dog’s barking and this interrupt this sound and runs next one but it will call first listener because console will print “1”
thx… I am almost sure there is no way how can I remove that listener till sound ends [import]uid: 6869 topic_id: 1736 reply_id: 5152[/import]
I ran your sample app and it does show a problem. The media.stopPlayer() does stop Sound1 but it doesn’t remove Sound1 listener so when Sound2 ends, it still calls Sound1 listener. I filed this as bug #762 in our internal database.
Until it’s fixed I would suggest that you only use one sound Listener function and that you set a flag indicating which sound file is associated with the call.
Thanks.
-Tom [import]uid: 7559 topic_id: 1736 reply_id: 5192[/import]