3

I don't know why but it doesn't work. I have this:

function stop()
{
  audio.pause();
  audio.currentTime = 0;
}

When I change the value of currentTime to 0, nothing changes...that is, currentTime continues having the previous value.

Daniel Garcia Sanchez
  • 2,306
  • 5
  • 21
  • 35
  • What platform or browser are you seeing this behavior on? I could not reproduce your issue: http://jsfiddle.net/8SPs7/ – apsillers Jun 06 '13 at 16:25
  • I'm trying with chrome – Daniel Garcia Sanchez Jun 07 '13 at 06:15
  • 1
    Found the problem!! It doesn't seem work well with .mp3 file, your jsfiddle contains a .ogg file...I changed it adding a mp3, and it doesn't work...http://jsfiddle.net/8SPs7/3/ – Daniel Garcia Sanchez Jun 07 '13 at 06:56
  • I have an mp3 and setting it to currentTime = 0 does not do anything. Chrome or Firefox. No effect.. ‍♂️ The only thing that differs: I pause it, set the time and start playing immediately. (By setting a playhead). It works as soon as currentTime is != 0. – Merc Feb 19 '19 at 14:51

2 Answers2

5

I solved it:

audio.pause();
audio.src = audio.src;

It reload the audio tag, and set currentTime to 0

Daniel Garcia Sanchez
  • 2,306
  • 5
  • 21
  • 35
  • I had the same issue and used your solution. However it introduced a new bug in IE11 + IE 10: the audio elements could not replay a sound already played, unless the user refreshed the whole page. – miner Feb 26 '14 at 09:58
  • readyState = 0 after reassigning the source thus I can't play it. – deathangel908 May 27 '15 at 10:40
0

This could be a browser compatibility issue. Unfortunately the HTML5 Audio API is still not very mature. Consider using a 'wrapper' such as soundmanager2.

Also see older answer here

Community
  • 1
  • 1
hvdd
  • 514
  • 4
  • 7