First time poster, long time lurker/learner here. I love this forum and its community. The wealth of sharing, knowledge, and civility is exemplary.
I discovered a few audio goodies after wrapping my Hype project in an Xcode webView for adhoc iOS distribution, using @Photics wrapping app. Some of the insights might be new and of help to the inquisitive mind.
A wrapped Hype project on iOS will:
-
Continue audio when the app goes into background (such as switching to another app or home screen).
-
Continue audio when switching to lock screen (“switching off” the phone).
-
- Play audio without prior touch event (on scene/layout load for example). This last one isn’t new to this Forum but so refreshing to experience live after experimenting solely in mobile Safari.
These 3 audio behaviors are already well worth the hassle of wrapping your project in Xcode if your project is mobile-mainly and/or you have a sound based app in mind.
From what I understand “Audio on lock screen” is also one of the most searched for audio related topics in Xcode centric posts elsewhere.
There IS a downside to this.
Apple will bemoan that behavior if you intend to submit your app to the App Store because you’re not using the official Background Mode in Xcode’s Capabilities tab. You’re not officially declaring that your app’s audio will persist (such as a music player or VOIP app).
Additionally your audio file will be represented by a confusing and buggy looking audio player in the tray on your locked screen (see image).
It becomes critical if you DON’T want audio to persist after the app goes off-focus. For example, in a game with sound effects. The last audio file played in your Hype project (say a “boing” or a “whoosh”) will persist on a user’s lock screen. This turns into a nightmare (or hilarity) with looped sound effects (for a walk-cycle for instance).
I’d like to kick off this thread for people interested in keeping audio persistent LEGALLY in iOS and folks wanting their audio to gracefully exit upon the app moving to the background (such as me).
Apple’s documentation about sticking to the rules and programmatically handling audio in those cases is here:
Apple Documentation on Background State
Apple Documentation on Persistent Audio
Apple Documentation on Activating and Deactivating Audio Sessions
As for me: I’m trying to stop all audio if the app is not in the foreground. I tried to simply “kill” the app if not in foreground by using UIApplicationExistsOnSuspend “NO” in info.plist but while that method stops the sounds it also resets Hype’s timelines and the last played audio file STILL sits in the device’s buffer (see screenshot).
I KNOW it has to be somewhere in the AppDelegate.swift inside func applicationDidEnterBackground but I don’t know how to declare which player to stop.
@MarkHunte has some brilliant insights in related posts regarding callbacks between Xcode projects and Hype 3 projects: Get Control of & feedback from Webpage Or iOS/Mac App using the (newish) WKWebView
Could that be close? I’m not trying to control one specific audio file. Just all audio used in the Hype 3 project embedded in Xcode.
Can anyone help? Thanks!