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 如何使用simulink建立一个永磁同步直线电机模型?
  • ¥30 天体光谱图的的绘制并得到星表
  • ¥15 PointNet++的onnx模型只能使用一次
  • ¥20 西南科技大学数字信号处理
  • ¥15 有两个非常“自以为是”烦人的问题急期待大家解决!
  • ¥30 STM32 INMP441无法读取数据
  • ¥15 R语言绘制密度图,一个密度曲线内fill不同颜色如何实现
  • ¥100 求汇川机器人IRCB300控制器和示教器同版本升级固件文件升级包
  • ¥15 用visualstudio2022创建vue项目后无法启动
  • ¥15 x趋于0时tanx-sinx极限可以拆开算吗