admin管理员组文章数量:1391951
I am using the HTML5 AudioElement to play my .mp3 files, but I noticed it is not possible to skip the position. I am fetching the file via PHP from outside the www root.
I am using HTML code :
<audio src="" controls id="appAudio" style="width:1000px;margin-top:10px"></audio>
JavaScript code:
document.getElementById('appAudio').src= 'http://localhost/index.php/player/get_audio_via_php/1';
PHP code:
$file = "/myfolder/1.mp3";
header('Content-Type: audio/mpeg');
header('Content-Length: ' . filesize($file));
return file_get_contents($file);
Like I said it does play the audio file, but skipping position is not possible. Is there a solution to this?
Thank you
I am using the HTML5 AudioElement to play my .mp3 files, but I noticed it is not possible to skip the position. I am fetching the file via PHP from outside the www root.
I am using HTML code :
<audio src="" controls id="appAudio" style="width:1000px;margin-top:10px"></audio>
JavaScript code:
document.getElementById('appAudio').src= 'http://localhost/index.php/player/get_audio_via_php/1';
PHP code:
$file = "/myfolder/1.mp3";
header('Content-Type: audio/mpeg');
header('Content-Length: ' . filesize($file));
return file_get_contents($file);
Like I said it does play the audio file, but skipping position is not possible. Is there a solution to this?
Thank you
Share asked Nov 19, 2012 at 15:01 zer02zer02 4,0214 gold badges33 silver badges68 bronze badges3 Answers
Reset to default 4If the browser doesn't have the file in cache, "skipping" causes the browser to send a new request, with a "range" header. Your PHP file needs to handle this header.
this means:
- get and parse the range header
- respond to the request with status code 206 and corresponding range headers
- output only necessary bytes
Have a look at this post, related to serving mp3 files via php.
The answer suggests changing the content-type to include several types:
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
Old question... I used this, seems to be working on Chrome.
header("Content-Transfer-Encoding: binary");
header("Content-Type: audio/mpeg, audio/x-mpeg, audio/x-mpeg-3, audio/mpeg3");
header('Content-Disposition:: inline; filename="'.$audio->filename.'"');
header('Content-length: '.$fileSize);
header('Cache-Control: no-cache');
header('Accept-Ranges: bytes');
readfile($filepath);
本文标签: javascriptHTML5 Audio Element quot srcgetphp cannot skip positionStack Overflow
版权声明:本文标题:javascript - HTML5 Audio Element " src = get.php cannot skip position - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744651631a2617720.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论