How can I start music without pressing any key?

0 favourites
  • 7 posts
From the Asset Store
In this template the music plays without looping in your game
  • Hello boys and girl, i'm sorry if this has been already discussed but I I have not found anything.

    Basically everything goes smoothly with my "work-in-progress game"... the only thing I can't understand is that when i run the game (chrome browser) the music and, more in general, all the sounds effects don't start unless I press a key.

    In the exact moment I press anmy key (on the keyboard or on the mouse) everything starts.

    How can I solve it?

    Thank you for your patience and understanding :)

  • Text extracted from Construct manual

    scirra.com/manual/109/audio

    Mobile limitations

    Safari on iOS and Chrome for Android share a limitation in playing music. While sound effects can be played at any time, music is only allowed to start playing when the user touches the screen. This is a limitation in the browsers themselves. As a result, if you play music on the start of layout, you may find in these browsers it does not actually start until the next touch.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • What I usually do to "fix" this problem, is to have a Loader Layout and display a "Touch to start" text to force the user to make the first input.

  • Thank you your kind reply. Anyway, in order to specificate my situation, i’m not talking about mobile devices. I am talking about the game preview opened into Chrome Browser on a Windows-based PC (Construct 2).

    When I press “run the game” button to try the game, it starts normally following all the events (enemies spawn, player idle animation, environment animations... if I get hit in the meanwhile the HUD response correctly to the variables etc...) except for the Audio that does not start until I press a Key.

    To make a simple example, on my main menu I have a suondtrack looping from the start of the Layout and a sound effect set to play when the mouse cursor is over the “Play Now” button.

    If I run the main menu and don’t press any key, the music does not start and the mouse over sound effect works only when i Click the “play menu button”... then game switches on the second layout as planned and the audio is ok (from THIS layout).

    Instead, if I run the main menu and immediatly press anything (any key or mouse button), the music starts and the mouse over effect works perfectly.

    This is nothing so disastrous... I press a key and it’s okay... I just wanted to know it there is a specific setting to avoid it, if I am doing something wrong or if, simply, it works like this.

    Thank you again

  • The same thing happens to me in Chrome for PC.

    There is a Rex plugin to simulate pressed keys, I have not tested it, perhaps simulating the pressing of a key with the plugin so the audio will start immediately.

    Or this:

    gist.github.com/demonixis/57264cd34e2bf7bcd0ae

  • Nefron89 Forgot to mention that it is actually a Chrome "problem". They have changed autoplay policies since 2018:

    developers.google.com/web/updates/2017/09/autoplay-policy-changes

    So, you can use one of the PabloDev solutions.

  • Thank you very much guys for you kindness. As a metter of fact I've set Firefox as default browser and everything is now perfect. Thank you again!

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