How to know if the audio preload is finished?

  • The audio plugin had provided "action: preload" to download audio before playing.

    How to know if the preload is finished? So that I can switch the game from wait to playable.

    I find that there is a "readyState" in C2AudioBuffer.bufferObject (in audio plugin source code). I guess that the audio can be played if (readyState == 4).

  • There's no clear time to know when the preload has finished: do you count "finished" as "enough has downloaded to stream to end without stopping" or "all data has downloaded"?

    Since audio streams, it's best just to start the game without waiting for preloads to complete.

  • The answer might be "enough has downloaded to stream to end without stopping".

    On the other word, the player will not feel the music is delay.

    Here is the fixed audio plugin to test if readyState can notify the music can be played (playable). I add a condition "On all preload finished".

  • Ashley

    I insert some code to let "Condition:On all preload finished" support firefox and chrome.

  • rexrainbow, can you add a feature that allows us to get the exact point in the audio?

    For example, In my game I need to know if the audio track is at 0:30, 0.24 etc, is this possible?

  • smitchell

    Sorry, I can't. I have not enough knowledge and time.

  • rexrainbow you shouldn't modify the built-in plugins - it will make your project totally unportable to other installations other than your own, which could make bug reporting and sharing projects difficult in future. Also, for legal reasons, strictly speaking I don't think we should be using your code. So I'll see if I can get this in to a future build, but it may be incompatible with the changes you have already made.

  • Ashley could it be possible for you to implement what I was asking above? It's something quite important to my project..

  • smitchell the Audio object actually now uses 4 different audio APIs under the hood because audio support is very patchy and we have to use different engines on different platforms. I think only one of them supports getting the time like that. So it would not be well supported at all. Whenever we add features that aren't supported everywhere people come back and report the fact they don't work as bugs when it's just not supported on the platform they happen to be using. So I would prefer not to add it. Audio support is very rough in HTML5 and unfortunately the current state of the audio object is about as far as it will stretch without almost everything being broken somewhere.

    You can work around it by measuring the time since you played the sound yourself.

  • Ashley, Yeah I understand the workaround, But I would need to be able to set the audio to a specific time if you know what I mean.

  • Yeah, that wouldn't work in Chrome, or in AppMobi or PhoneGap.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • May I ask why is it like this? Is it cos it is still being developed or is it cos of corporate bull?

  • It's because audio still isn't well supported on the web:

    HTML5 audio has glitches, high latency and bugs, and isn't supported well on mobile

    Web Audio API only works on Chrome, but has different tradeoffs, like you don't seem to be able to set the position of a currently playing sound

    PhoneGap and AppMobi provide other APIs to play audio, but they are limited to simple "play sound" functionality.

    Basically, there's still no widely supported decent audio library for HTML5, so we're stuck with limited features for the time being.

  • Ashley

    Thanks.

    I understand the complex of audio plugin after read the source code. It will take a lot of effort to maintain audio plugin.

    That's why I just propose a patch code, and hope this feature will be added in the future.

    (PS. My team member put his game on server so I need to solve this problem by the patch audio plugin, but I really hope Scirra will provide the solution in the future)

  • When does C2 start to load the "streamed" audio? Preload doesn't seem to have any effect on it. Would it be possible for me to slice my music track and play them as a sound fx?

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