How do I make sound files work when the project is previewed?

0 favourites
  • 12 posts
From the Asset Store
_______ Huge collection of metal fixtures ________
  • I'm currently stuck with this infuriating bug in which none of the audio files in my game play on preview, I've opened other projects and copied those sound files and the exact line of code used to play it and it doesn't seem to work in my specific project.

    for instance:

    This does nothing. But in other projects it would work. (I've also tried putting the sound effects in the music or sounds folder but that doesn't work either)

    I think I've figured out that it must be something to do with the project as a whole, video audio works, and preload sounds is checked, have I accidentally unchecked something that makes it so sounds and music will just never play?

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • It may be browser limitation. Try playing the audio in "Touch on Tap" event instead of "On start of layout".

    Also press F12 in preview and check if there are any error messages in the browser console.

  • Thank you for the reply! The touch on tap event didn't work either but I did get these error messages:

    Perhaps it could be one of these?

  • I don't know what all these errors mean. Are you running the project in preview mode, or is it exported? I would try a different browser.

  • I’ve tried other browsers and unfortunately nothing :( other projects sounds work so it must be something to do with my project

  • Browsers restrict audio playback until the user interacts with the page, in order to prevent random web pages annoying you with audio ads and such.

    You can play audio in 'Start of layout', but it won't actually be heard until the first click or touch on the page.

    There's more information in the "Autoplay restrictions" section of the Audio manual page.

  • That could well be it. What I use, is an 'Audio' layout before the menu is presented.

    There you can ask the player if they want to use audio with a Yes or No button. When either clicked, and in the case of Yes, the on Start of layout event should work. For No, I set audio silent.

    But you could use anything to trigger audio this way, with a little creativity.

  • CowboyToadTeam claims that audio doesn't work in preview. Browser autoplay restriction should not affect the preview. Also, if this was related to autoplay restriction, playing audio in "On Tap" event should have fixed the issue, but it didn't.

    CowboyToadTeam Have you tried other audio files? Maybe there is a problem with this particular track. Try converting it to other formats, like mp3 or wav. Also, try running the project in Debug mode and check if Audio object is playing this track or not.

  • dop2000 Browser Autoplay restriction does affect audio playback in the preview and debug windows in Chrome for sure. Not sure about it not working on tap though without seeing more info.

  • Construct's preview window doesn't get any special treatment: it's still subject to the usual autoplay restrictions.

    What might make this confusing though is IIRC Chrome tracks statistics about how often media playback is used on different websites, and may decide to allow autoplay automatically based on usage patterns. In other words if you usually play audio on some page, then it will start allowing autoplay. So you might get autoplay allowed in the preview window if you usually play audio in preview. In the end that could create the impression that autoplay works inconsistently, as it ends up working for some people but not others.

  • Ashley yes that is correct. Typically in a new session, chrome will not autoplay sound the first time a preview is run, and occasionally the second time also, but after that autoplay tends to work. More info here: developer.chrome.com/blog/autoplay

  • I don't know why, but for me Chrome always autoplays music straight away - I can launch chrome, load C3, open a project with music, press F4 to preview and the music will play without any interaction from me.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)