How to know if the audio preload is finished?

Get help using Construct 2

Post » Sat Feb 04, 2012 5:20 am

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). rexrainbow2012-02-04 06:41:45
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Sat Feb 04, 2012 4:35 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Sun Feb 05, 2012 12:53 am

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".rexrainbow2012-02-05 00:54:05
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Mon Feb 06, 2012 8:09 am

@Ashley

I insert some code to let "Condition:On all preload finished" support firefox and chrome.rexrainbow2012-02-06 08:12:21
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Mon Feb 06, 2012 1:45 pm

@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?
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 1:59 pm

@smitchell

Sorry, I can't. I have not enough knowledge and time. rexrainbow2012-02-06 14:07:05
B
97
S
22
G
178
Posts: 4,122
Reputation: 104,051

Post » Mon Feb 06, 2012 4:01 pm

@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.Ashley2012-02-06 16:02:08
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Feb 06, 2012 4:06 pm

@Ashley could it be possible for you to implement what I was asking above? It's something quite important to my project..
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Post » Mon Feb 06, 2012 4:15 pm

@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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Mon Feb 06, 2012 4:18 pm

@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.
B
29
S
12
G
7
Posts: 740
Reputation: 7,849

Next

Return to How do I....?

Who is online

Users browsing this forum: Renfd, supreme676 and 27 guests