HTML5音频元素" SRC = get.php不能跳过位置 [英] HTML5 Audio Element " src = get.php cannot skip position
问题描述
我使用的是HTML5 AudioElement发挥我的.mp3文件,但我发现这是不可能跳过的位置。我从WWW根目录外获取通过PHP文件。
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.
我使用的HTML code:
I am using HTML code :
<audio src="" controls id="appAudio" style="width:1000px;margin-top:10px"></audio>
JavaScript的code:
JavaScript code:
document.getElementById('appAudio').src= 'http://localhost/index.php/player/get_audio_via_php/1';
PHP code:
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?
感谢您
推荐答案
如果浏览器不具有高速缓存中的文件,跳绳会导致浏览器发送一个新的请求,用的范围头。你的PHP文件需要处理这个头。
If 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.
这意味着:
- get和解析头 的范围内
- respond与状态code 206和相应的范围头 请求
- 输出只需要字节
- get and parse the range header
- respond to the request with status code 206 and corresponding range headers
- output only necessary bytes
这篇关于HTML5音频元素&QUOT; SRC = get.php不能跳过位置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!