Yes indeed!!
I was able to solve my problem of needing immediate UI feedback from the Player component when running in the background by simply moving that code from the UI to the background . So now the main "show" runs in the background service and the UI executes control via Itoo.CallBackgroundProcedure and the background process updates the UI via the implicit ui_xxxxx mechanism.
No need for any locks or while loops!
However I have encountered a problem when attempting to report a Screen1.ErrorOccurred event when it occurs in the background process. The procedure Screen1_ErrorOccurred is not called. From what I can see in logcat output, it looks like the procedure "null_ErrorOccurred" is being sought and, of course, not found. When I add the procedure null_ErrorOccurred to the project, it DOES get invoked...
Here is a test case made from ItooMusic. The error that is induced (when the KDFC URL is toggled so that it is in error) is "702" and is caught and reported by both the UI and background players. However, if null_ErrorOccurred is disabled/removed from the project, the background player does not report the error.
I have attached the test project as well as some logcat output and screen shots. Let me know if I have not sufficiently explained this.
The test case:
ItooMusic_440_null.aia (4.2 MB)
The blocks:
Both players can be started by the UI and will play the KDFC San Francisco, CA, public radio stream using a URL.
When "Toggle KDFC URL" is clicked the URL is intentionally corrupted and neither player works. They report the error 702 in the label between the two sets of controls.
UI Error:
Background Error:
HOWEVER, If the project is modified to disable/delete procedure null_ErrorOccurred, the UI player reports the error 702, but the background service does not.
Here is some logcat output showing what is happening - null_ErrorOcurred is not found:
null-notFound.txt (1.8 KB)
12-26 23:30:37.450 9034 9034 E Form : Form null ErrorOccurred, errorNumber = 702, componentType = Player, functionName = Source, messages = Unable to prepare https://18323.live.streamtheworld.com:443/KDFCFM_S.
12-26 23:30:37.478 9034 9034 I ItooCreator: AEvent(ErrorOccurred=null) args [com.google.appinventor.components.runtime.Player@44804e8, Source, 702, Unable to prepare https://18323.live.streamtheworld.com:443/KDFCFM_S.] listener = xyz.kumaraswamy.itoo.Itoo$1@1dc8539
12-26 23:30:37.478 9034 9034 I ItooCreator: startProcedureInvoke: null_ErrorOccurred & -1
12-26 23:30:37.478 9034 9034 I ItooCreator: startProcedureInvoke: failed to find name(null_ErrorOccurred)
BTW, if "Toggle KDFC URL" is clicked again, the URL is repaired and both players work once again - no errors.
I need this functionality because the radio stream URLs I have used sometimes change - what works today my not work tomorrow
For now, I can use the null_ErrorOccurred workaround... but I figured it would be something that could be fixed(?) in a future release...and, as always, I may not be understanding this correctly.
Does this make sense?
Kind regards,
Randal