Hello, I'm about to submit my AlphaPod app to Apple's Mac App Store, but there's a problem with the sound of the app. I have an audio loop that I load in Hype via the simple onClick play sound X and I have it as a loop.
But when I open the build on my Mac, play the button that starts the music, and then quit the App the music loops keeps playing for about 20 seconds. Then is stops and I get this message in the console:
That's really interesting that it happens on quit with the Mac. Is this a Catalyst-based app? (Well, if so it is less surprising since I've heard Catalyst is pretty buggy!)
If so, maybe some of the two iOS-related threads could apply:
It sees a solution would be to handle the visibilitychange event and if the document is hidden to run code which pauses the audio. A head html solution would look something like:
<script>
document.addEventListener("visibilitychange", (function () {
if (document['hidden']) {
var hypeDocument = Object.values(HYPE.documents)[0]; // get first hypeDocument
hypeDocument.triggerCustomBehavior("muteAll"); // do something that mutes audio in the Hype document; here I would have setup a custom behavior that sets all of them to pause
}
}));
</script>
Assuming the muteAll trigger does work as expected, perhaps this event doesn't fire on quit. Instead you might want to try something like from this tip:
Basically it uses the native app's NSNotificationCenter to listen to an event and calls into javascript from there. I suspect you'd want to change the event to UIApplicationWillTerminate or use the delegate:
And then just use the javascript from the handler above.
At least that's my best guess .
It's also be interesting to look in Activity Monitor and see what is going on/if the WKWebView process is sticking around. I'm not sure how the lifecycle for Catalyst apps is different than normal Mac apps, but it really should go away immediately when the app is quit!
Apparently WebKit was adding processes from Hype engine to the background thread, so it was preventing the app from quitting. So I added a rough termination of the app on quit actions.