Note that there are some explanatory texts on larger screens.

plurals
  1. POHtml5 Audio - currentTime reseting causes bitty sound
    primarykey
    data
    text
    <p>[Question edited to clarify points by users. My comments below have been deleted and included here instead.]</p> <p>I have a long sound file (mp3), 110 seconds. At the start of this file the music is happy, but it gets progressively more sinister by the end. <strong>Note: The audio will play at the normal speed throughout.</strong></p> <p>I have a variable 'var tension;' which has a value between 0 and 1, eg 0.35. It measures how spooky things are getting in the game. A value of tension = 0.0 means its safe, a value of tension = 0.5 means there is a bit of trouble brewing, and a value of tension = 1.0 means the poop is hitting the fan. But all decimal values between 0.0 and 1.0 can be achieved. It is set by how close you are to danger or if someone is chasing you.</p> <p>The following is a global Audio element created in memory at the start of the program:</p> <pre><code>var g_TensionSound = new Audio(); g_TensionSound.src = "mysoundfile.mp3"; </code></pre> <p>I have waited for the mp3 file to be fully loaded.</p> <p>Every second I use a timer event to call the following bit of code:</p> <pre><code>g_TensionSound.currentTime = 5.0 + 100 * tension; if(g_TensionSound.paused) g_TensionSound.play(); </code></pre> <p>So for example the first time the timer event is triggered tension = 0;, so it plays a friendly sound in the music file (ie at the 5 second mark). Then the next time the timer event is triggered, the player has moved close to some trouble and tension has risen to tension = 0.25; So this time the segment of music at the 30 second (5 + tension * 100) mark in the file will be played.</p> <p>Unfortunately this produces very bitty results, with a slight delay when changing over to the new currentTime. <strong>Does anyone know anything about this, or how to solve it?</strong></p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload