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 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭
  • ¥15 2020长安杯与连接网探
  • ¥15 关于#matlab#的问题:在模糊控制器中选出线路信息,在simulink中根据线路信息生成速度时间目标曲线(初速度为20m/s,15秒后减为0的速度时间图像)我想问线路信息是什么