Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I stop embedded sound clips from being downloaded to the browser cache before they are requested to be played?
    primarykey
    data
    text
    <p>I have been scratching my head with this one for a few days,</p> <p>I am building a web app for a client associated with call tracking. One aspect of the system is to allow for short recorded voicemail messages to be played directly from a "play" button beside the message details.</p> <p>I am accessing the sound files as such;</p> <pre><code>$wavefile=$calls_row['recording']; if (file_exists("/var/spool/asterisk/monitor/".$calls_row['recording'].".wav")){ $wavefile=" &lt;form&gt; &lt;input type=\"button\" value=\"Play\" onClick=\"PlaySound('clip-".$stat_id."')\" /&gt; &lt;/form&gt; &lt;embed src=\"pass-thru.php?f=".$calls_row['recording'].".wav\" autostart=\"false\" width=\"0\" height=\"0\" id=\"clip-".$stat_id."\" enablejavascript=\"true\" /&gt; "; } </code></pre> <p>The sound clips are stored outside the web root in a directory I have been told we cannot change. Being unable to get at the files locally I put together a small php pass-through script to pass me the file back to my web page.</p> <p>The sound clip is using a small piece of javascript to get the ID of the link for the specified file before playing it;</p> <pre><code>function PlaySound(soundobj) { var thissound=document.getElementById(soundobj); thissound.Play(); } </code></pre> <p>The files are accessed outside the webroot and passed to the html by the following php code;</p> <pre><code>$basedir = '/var/spool/asterisk/monitor'; $clip = $_GET['f']; $file = $basedir.'/'.$clip; $ext = array_pop(explode ('.', $file)); if(file_exists($file) &amp;&amp; $ext != '' &amp;&amp; isset($allowed[strToLower($ext)])) { $type = $allowed[strToLower($ext)]; } header("Content-type: audio/x-wav"); header("Content-Disposition: filename='{$file}'"); header("Content-Transfer-Encoding: binary"); header('Content-Length: ' . filesize($file)); readfile($file); exit(); </code></pre> <p>Everything works fine as it should, the clips are passed through and the sound clips play in the browser.</p> <p>The problem is that all of the soundclips are loaded into the cache when the page loads, obviously slowing things down a bit. I have the results paginated so its only downloading 25 at a time but I would really love to just have the links to the soundclips available and that they are only downloaded when selected to be played.</p> <p>Any ideas would be appreciated.</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.
 

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