I have a PHP script that acts as a proxy between the user and the MP3. This is to prevent external embedding or hotlinking and so I can count plays of each MP3 file.
I am experiencing a problem though in Google Chrome and Safari (Opera, Firefox and Internet Explorer work perfectly) where it plays the MP3 fine and I can seek too but only a limited amount of times. After seeking a few times the player greys itself out (native chrome player) or displays an error (audio.js and JWPlayer 6). I can press play again and it will restart but audio.js wont show the play button again after such an error.
JWPlayer throws this error in the console:
MediaError
code: 2
__proto__: MediaError
MEDIA_ERR_ABORTED: 1
MEDIA_ERR_DECODE: 3
MEDIA_ERR_ENCRYPTED: 5
MEDIA_ERR_NETWORK: 2
MEDIA_ERR_SRC_NOT_SUPPORTED: 4
In chromes native player the console reports "Failed to load resource", My server error log shows no errors.
The code I am currently using is from Los Cherone's answer here: Make mp3 seekable PHP
My previous solution was this code which I am not using anymore, but for reference here it is:
<?php
$track = '/public_html/mp3-previews/' . $_GET['stream'];
if(file_exists($track)) {
header('Content-type: audio/mpeg');
header('Accept-Ranges: bytes');
header('Content-length: ' . filesize($track));
print file_get_contents($track);
} else {
echo "no file";
}
?>
Both codes cause this error but it's worth pointing out that both codes stream audio and both of them allow me to seek a few times.
My initial thought was the function apache_request_headers was causing the problem because I am running PHP 5.3 and my host is running PHP as Fast CGI. So for Los Cherone's code I am using this workaround, but then why would my first attempt not work either?
EDIT: This is not the problem. I have updated my PHP version and this is still causing me issues.
Here is my hosted servers example: http://tabbidesign.com/audio/
A combination of Los Cherone's code and my own local Apache server with PHP 5.4.9 works perfectly, this problem does not occur. Here is the example: http://tabbicat.info/proving/audio/
What could be causing this?