0

Audio playback via web audio API (SourceNode.start()) works fine.

But I would like to have the start time of the playback as Unix time stamp. Is this possible, if yes, how?

I know, that I get the unix time by using +new Date(), but the problem is that I don't know where to place it, so that it's really the starttime of my audiofile.

Thank you in advance!

Samson
  • 1
  • 1
  • Did you check this one https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/start The time, in seconds, at which the sound should begin to play, in the same time coordinate system used by the AudioContext. If when is less than (AudioContext.currentTime, or if it's 0, the sound begins to play at once. The default value is 0. hence, Unix timestamp is a full date and what you want is only seconds which you can calculate based on the date as well. – Behrouz Pooladrak Oct 05 '21 at 14:37
  • Please provide enough code so others can better understand or reproduce the problem. – Community Oct 10 '21 at 09:34

1 Answers1

0

If you are using audio tag, you can add play event:

document.getElementById('myAudioElement').addEventListener('play', function(){
    console.log(new Date().getTime());
});