Audio not playing in scenes

Hi all,

I’ve been updating an existing project which has worked fine in the past which has a short audio clip ‘On Scene Load’ and also timeline audio clips in following scenes triggered by both user interaction and scene loading, pretty simple.
When playing the exported HTML5 app on a mobile device the first scene loads and also the scenes with timeline animations work as they should but the audio doesn’t play on any of them on first load, however, if I navigate back to the pages with the audio they then work perfectly, as if they hadn’t had time to load on the first attempt, however all the audio files in question are set to Preload and of course some are only triggered after a user button press and the timeline starts.
Any ideas?



There’s your problem.

You interacted with the Hype project. On mobile, the Hype project needs to be tapped before the sound plays. It’s not just your project. Here’s an example…

Load the game up on Desktop, the intro music plays right away. Load the game up on Mobile, the music isn’t heard until the game is touched.

It used to work though on the previous under OS10 and previous XCode version on previous builds though, even used a PhoneGap Build version which also worked, only the pinch zoom didn’t function that time.

Also, most of the issues on audio events within the timeline are triggered by user interaction, the user presses a ‘play’ button and the timeline is then triggered.

Here is an example:

A scene is loaded with four symbols on two lines of musical stave, 2 bass drums and 2 snare drums. If you press ‘play’, the timeline starts and each symbol briefly scales up then down in sequence and the appropriate drum audio file is meant to play with each of the symbols.
What actually happens is the timeline plays but no audio occurs. If you press each symbol, the correct audio is triggered and then if the ‘play’ button is touched after this, that sound is then played in the timeline, if you only press one of the snare drums, only the snare drums will then play in the timeline, but both snare drum symbols will sound off.
It’s as if the program requires, as you say, each sound to be manually triggered or ‘unlocked’ initially by a user, but before the latest xCode & iOS11 upgrade, this wasn’t the case, they would behave as they do in the browser test phase.
Any ideas?

Hmm, that’s interesting :thinking:

I don’t have the lasted version of Xcode installed. I looked online though. Here’s what I found…

Are you using those two settings?

Also, are you using Howler.js?

Hi Photics,
thanks for the reply.
I’m now using the new WKWebview as the older UIWebview(deprecated) builds would throw up errors in the new Xcode.
I’m not using Howler.js, not even sure what it is but I’ll have a read, everything I’ve done to date has been done in Hype (or PhoneGap Build when I needed it previously)

I’ve been battling with this issue too, but I haven’t quite figured it out. The background music doesn’t play in the iOS / Xcode WKWebView.

@jonathan posted a reply about this issue here…

…and I’ve seen a few posts about this on Stack Overflow

Apple’s documentationis here…

I’m tired, so I won’t solve this problem tonight, but I’m planning to work on fixing this issue tomorrow. (I’m trying to launch Circles with Grandma on iOS.) There are a still few tweaks to the WKWebView to make the HTML content feel more app-like…like disabling pinch-zoom, hiding the status bar and actually getting audio to play. :smile:

1 Like

Good luck figuring it out, I’m sending you good vibes!!

Here you are friend…

import UIKit
import WebKit
class ViewController: UIViewController, WKUIDelegate {

var webView: WKWebView!

override func loadView() {
    let webConfiguration = WKWebViewConfiguration()

That’s the start of apple’s code. The trick is to add this…

But how do you do that? :thinking:

It’s attached to “webConfiguration”… which appears to be variable, where you can give it a different name. But if you keep the same name, the following code should fix the sound problem…

webConfiguration.mediaTypesRequiringUserActionForPlayback = []

So basically, it’s saying no media types require user action to play. After many hours of fighting with Xcode, on this issue and Mac app issues, I thought it didn’t work. Heh, but then I heard the music playing.


Hi Photics,
imagine you are talking to a coding dunce…because you are! Following again a very helpful tutorial on Youtube by Nick Gressle that has helped me build an app from Hype output in the past I end up with the following:

import UIKit
import WebKit

class ViewController: UIViewController, WKNavigationDelegate {
override func viewDidLoad() {
let webView = WKWebView()
let htmlPath = Bundle.main.path(forResource: “index”, ofType: “html”)
let folderPath = Bundle.main.bundlePath
let baseUrl = URL(fileURLWithPath: folderPath, isDirectory: true)
do {
let htmlString = try NSString(contentsOfFile: htmlPath!, encoding: String.Encoding.utf8.rawValue)
webView.loadHTMLString(htmlString as String, baseURL: baseUrl)
} catch {
// catch error

    webView.navigationDelegate = self
    view = webView


Where would I implement your solution in the lines of code because I’m clueless!