Audio / Sound on Mobile -- solutions ?

0 favourites
  • 11 posts
From the Asset Store
126 audio files divided in: music, radio voices, SFX
  • I discovered some limitations on mobile. So i wasnt sure what & why exactly. But gladly i found a small-"mention" in the construct2 documentation : (check the Header "Mobile Limitation")

    Than i was serching for a workaround. And i found something interestant. You can achieve audio playback without "user interaction / input". And it works ! (on Android. On iPhone it doesn´t work)

    The workaround is called: "AudioContext"

    ( )

    I was able to handle this with construct 2 and "extern" JS-script. Thanks to a C2 plugin called "ValerypopovJS". It is just nasty to do something by hand. What i also found out, is:

    1.) On 6y old devices i got a sound-Delays

    My guess is, that i cames from the "communication" of C2 to external JS-script. What do you think? Could something like this use too much power of the CPU ?

    Some questions about this topic:

    2.) Is there any plugin out there, which handles this problem in a elegant way ?

    3.) If not, would it be a big deal, if someone could write one ?

    4.) Would it be more performant, to put the AudioContext-JS script inside the C2 sheetboard, instead into an external JS-file ?

    5.) Does anybody else expirienced also the same behaviour on mobile-devices ? And what workarounds did you used ?

  • Construct should already handle this for you automatically. It also already uses AudioContext (the Web Audio API). Browsers mute audio until the first user input; at that point Construct will automatically unmute audio playback, after which there should be no further restrictions.

  • Oh really ?

    Thats great ! But somehow it didn´t worked for me. Maybe i did something wrong?

    I used the "Audio"-item and later on, in the commandsheet i tell the object to "play" the specific file (*.ogg / *.m4a). Usually if the user do his input, it plays. And strangly with a delay... No idea why.

    But also when the "next" Level starts, it should play sound without user input. This didn´t worked. "..Browsers mute audio until the first user input... " <- with my script you really don´t need input. It starts playing sound without any input. Just type the webAdress and it goes on.

    I have C2 r265

    Android 5.1 , newest chrome

    Android 8.1 , newest chrome

    Is there any Tut. about this topic? Or any example files, i can learn form ? I did a search in the formus after "sound mobile" / "delay mobile", etc. But didn´t find any thread about this. (On Desktop for instance, everything runs like a charm).

    I have to mention, that the C2-Engine on mobile is pretty damn fast ! Almost faster as many other HTML5 Engines! And you can run stuff really good as "Web App". Just now ...i am a bit struggleing & i hope to find a good way, with the audio play on mobile with C2

  • By the way ... this is the Script i used :

    var URL_1 = "media/music_menu.m4a";
    var buffer_1; // important
    var audioCtx_1 = new (window.AudioContext || window.webkitAudioContext)(); // maximum 6x are allowed
    var xhr_1 = new XMLHttpRequest();
    // -----------------------------------------------------------------------'GET',URL_1, true);
     xhr_1.responseType = 'arraybuffer';
     xhr_1.onload = function() { audioCtx_1.decodeAudioData(xhr_1.response, onBufferLoad_1);
     }; xhr_1.send();
    function playBeginning_1() {
     source_1 = audioCtx_1.createBufferSource();
     source_1.buffer = buffer_1; // important
    	source_1.loop = true; // true, false
    function onBufferLoad_1(b) {
     buffer_1 = b; // important
     playBeginning_1(); // plays imidiantly, after loaded
     //source_1.stop(0); // prevent direct play & enabels direct trigger
    // -----------------------------------------------------------------
    play_1_snd = function() { // Music - MENU
    stop_1_snd = function() {

    Maybe it can be useful for someone else ....

  • There is also a possible solution to play sound without user-input with the plugin "ToneJS" which is provided by "RexRainbow". It works as expected.

    But it wasn´t that easy to figure out, how to use it. Therefore i will share an example-file with you :!Yglh2apY!Q2mkQuItenkUsHoZR7PaCVSbC7gigT6CQ--PI3gm5Vk

    EDIT (info to the Moderator of this forum):

    My previous post didn´t went through. So it was a test / junk and can be deleted !

  • There is also a possible solution to play sound without user-input

    Browsers block this at the API level. It is not possible to work around it using different JavaScript code. Construct already plays audio at the first possible opportunity.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I am not sure if i understood everything. But yeah, thats right...they block it. But it is possible, to play without user input (w. the code i shared above). I tried it on different mobile-browsers (Android). say it is allready possible by the construct2-intern-Audio Plugin?

    I didn´t expirienced that, sadly. It would be great if you can provide a link + a sample.capx , so i can see how its done internaly by C2.

  • But it is possible, to play without user input

    It's not, with the latest versions of browsers. The change is still in progress though: any that do allow it, will shortly block it as well. So anything you do that can play automatically in certain cases, will soon be broken, so is a waste of time.

  • If you are stating something like this, it would be great if you maybe can mention :

    0.) which System (Android, iOS, both ???)

    1.) which Browsers (its only about mobile-ones)

    2.) from which vers. It will not be possible

    3.) and or simply provide a "link" where all forum-users can read about

    this "change is still in progress"

    We would appreatiate something like this.

  • In the near future, all browsers on all systems will impose autoplay restrictions. Construct already handles this automatically. So I don't see any reason to change anything.

  • "In the near future, ..." This is what i meant. Anyways. I am glad that "...Construct already handles this automatically...", so in the near future, it will work, i guess.

    But now, i still have this problem with audio (don´t mean autoplay) ... can i provide you a file, to check my setup ???

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