Ive got an AVAudioPlayer playing sounds from the obj-c code when responding to a href-call in a webview using the "shouldStartLoadWithRequest"-function in obj-c, and a "location.href=pathToSound;"-call in the js-portion of the html-code which lets obj-c understand which file to load.
In another portion of the code (when the webview is closed) I call [myPlayer stop]; .
This has worked fine until now.
However, when I changed the JS-code so that the call to the "location.href=pathToSound;"-code was made from a chain of js-functions (previously it was inside its own function, and was called by an onLoad-call in body), the stop-function stopped working. Everything else is working fine, but not the stop-function.
This seems very strange to me, so Im wondering if anybody else has come across this odd behaviour and would know the solution? Im developing for 2.2, btw.
[update]
It seems that if I make the call that plays the sound ( location.href=pathToSound; ) at the end of the js-function-chain, the stop-function in the obj-c-code will work. Perhaps if I was able to programmatically terminate the chain of js-functions prematurely I would also be able to stop the sound? Anybody knows how to stop a js-function prematurely, or better yet (since Ill have no way of knowing which particular function in the chain is running at any given moment) how can I terminate all js-script running in a webview?
Additionally, Im using a lot of timers in the js-code (setTimeout()). Can this have something to do with it?
[SOLUTION]
Apparently I was calling the audio from inside a loop, ie more than once. This must have resulted in one instance of the AVAudioPlayer being started every time the previous one was stopped.
In another portion of the code (when the webview is closed) I call [myPlayer stop]; .
This has worked fine until now.
However, when I changed the JS-code so that the call to the "location.href=pathToSound;"-code was made from a chain of js-functions (previously it was inside its own function, and was called by an onLoad-call in body), the stop-function stopped working. Everything else is working fine, but not the stop-function.
This seems very strange to me, so Im wondering if anybody else has come across this odd behaviour and would know the solution? Im developing for 2.2, btw.
[update]
It seems that if I make the call that plays the sound ( location.href=pathToSound; ) at the end of the js-function-chain, the stop-function in the obj-c-code will work. Perhaps if I was able to programmatically terminate the chain of js-functions prematurely I would also be able to stop the sound? Anybody knows how to stop a js-function prematurely, or better yet (since Ill have no way of knowing which particular function in the chain is running at any given moment) how can I terminate all js-script running in a webview?
Additionally, Im using a lot of timers in the js-code (setTimeout()). Can this have something to do with it?
[SOLUTION]
Apparently I was calling the audio from inside a loop, ie more than once. This must have resulted in one instance of the AVAudioPlayer being started every time the previous one was stopped.