douyan1882 2015-02-20 09:46
浏览 48
已采纳

使用PHP流/缓冲大型audiofiles


I'm trying to stream music to play it afterwards.
This is not a download but a direct stream of mp3 files from the source file to an <audio> tag on another page.

    Things I've tried so far:
  1. Use the Web audio API to stream directly from URL (audio.src=url->audio.load())
    -->"text/html is not supported".
    -->Adding the MP3 type to the .htaccess file didn't help (yes I alredy tried to move it to the directory where my MP3s are.)
    -->I have to do it manually with PHP, so I can use the content type header.
  2. Using JQuery, AJAX and a PHP-file to stream the data from a blob on a MySQL database.
    -->It does not buffer the file, but loads it comletely which takes min. 30 secs.
    --> too slow and maybe a bit too complicated for a simple audio stream where security isn't that important
  3. Using JQuery, AJAX and a PHP-file to stream the data from the directory on my Server
    --> same as 2. (besides, that ist isn't that secure anymore)

The code I've used in the .htaccess file is

AddType audio/mpeg3 .mp3
AddType audio/mp3 .mp3
AddType audio/x-mpeg3 .mp3

I have 2 ways to solve my problem, so I have 2 questions
1. How can I tell my server to stream an MP3-File as audio/mpeg3 and not as text/html (in case 1) ?
2. How can I buffer the audio stream (in case 2 or 3) so the visitor hasn't to wait 30+ seconds for it?


corrections are welcome.
  • 写回答

1条回答 默认 最新

  • duanen19871021 2015-02-20 10:35
    关注

    okay, sorry. way 1 DO work. At least if you don't use the FileMatch rules in the .htaccess file to lock every file or directory besides images or pages and forget to include audio files to the allow rule.

    one facepalm is not enough

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器