0

I am making a HTML5/javascript browser game and I have problems with my audio.

I have all my clips in a single mp3 file to minmize the number of requests sent and when I want to play a clip I seek to the clips starting position (audio.currentTime = startTime) and play (audio.play()) when the audio tag fires the "seeked" event via an event listner.

When I pause playback I use the audio.pause() method.

The problem I have is that, before the sound I want to play starts, a split second of the file is played from where the audio was playing before the seek.

Anyone else that has encountered this problem?

Anyone know what to do about it?

  • Could you provide a few more details? In which browser does this happen? – Harsha Venkataramu Aug 14 '12 at 15:07
  • I mostly use mobile safari. I have a single mp3 containing several sounds separated by a few secs of silence. When i seek in the file and then play i get a split second of sound from the beginning of the file before the playback position is updated properly (not all the time, mainly the first time) – matrixsmurfen Jul 03 '13 at 09:33

1 Answers1

0

If you're using Safari, this might be your problem.

Also, I'm finding that Web Audio API is looking more and more appealing (see my possible answer to my own question, haha)

Edit: Lastly, if you want to stick with the whole HTML5 Audio object, this question might point you in a different direction.

Community
  • 1
  • 1
BCDeWitt
  • 4,540
  • 2
  • 21
  • 34
  • I'm afraid none of these really capture my problem. I have no real problem starting or stopping the audio per se. The problem is that when I start the audio after setting the playback position (with `seek()`) I get a split second of audio from the previous playback position when i do `play()` – matrixsmurfen Jul 03 '13 at 09:32