使用Javascript/PHP从MySQL检索和播放mp3文件 [英] Retrieve and play mp3 files from mySQL using Javascript/PHP

查看:65
本文介绍了使用Javascript/PHP从MySQL检索和播放mp3文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在建立一个站点,该站点在mySQL中存储一些mp3音频文件.目前只有5个,因此效率根本不是问题.

I am building a site that stores a few mp3 audio files in mySQL. At the moment only 5, so efficiency is not an issue at all.

目前,我仍在尝试开发一种不需要其他文件格式的跨浏览器/平台解决方案.

CUrrently, I am still trying to make a cross browser/platform solution that will not require other file formats.

我有一个PHP脚本,可检索mp3二进制数据并将适当的标头发送到浏览器.然后,可以通过指定音频元素的src(无论是音频还是嵌入或其他)来检索文件,如下所示:src ="retrieve_audio.php?uniqueAudioID = [PHP变量标识文件]". php文件restore_audio使用URL中提供的数据库ID并检索数据,并将其与标头一起发送到请求的页面...

I have a PHP script that retrieves the mp3 binary data and sends the appropriate header to the browser. The files can then be retrieved by specifying the src of the audio element (whether it be audio or embed, or other) as follows: src="retrieve_audio.php?uniqueAudioID=[PHP variable identifying file]". The retrieve_audio php file take the database ID provided in the URL and retrieves the data, sends it with the header to the requesting page...

这非常适合Safari中的音频和嵌入标签.非常适合嵌入到IE 6、7和8中.

This works well for audio and embed tags in Safari. Works well for embed in IE 6, 7 and 8.

出于某些原因,Safari称它为流-可能是因为未提供文件的大小-并且控件不允许清理文件,而不管所使用的标记(音频或嵌入)如何. IE似乎可以理解所检索文件的长度,尽管未明确给出该文件的长度.

For some reason Safari calls it a stream -probably because the size of the file is not provided - and the controls don't allow for scrubbing the file regardless of tag used (audio or embed). IE appears to understand the length of the retrieved file although it is not explicitly given.

真正的问题是Firefox,Opera和Chrome.这些似乎一点都不了解. FIrefox会显示一个控件几秒钟,然后显示一个X字样-我不能玩这个……我知道Firefox中的标记存在问题.嵌入也是如此. Opera和Chrome要么什么都不显示,要么空白空白.

The real issue, though, is Firefox, Opera and Chrome. These do not appear to understand this at all. FIrefox shows a control for a few secs and then displays an X as in - I can't play this... I am aware of the issues with the tag in Firefox. It does the same with embed. Opera and Chrome just either display nothing or a blank white square.

有什么建议吗?

我从没想过要在IE上运行的东西与Firefox搏斗!

I never thought I would have to wrestle with Firefox on something that works in IE!

任何输入将不胜感激.

M

推荐答案

我以前在Firefox上遇到过问题,它期望Content-length HTTP标头包含几乎所有内容.

I've had problems with Firefox before, it expects a Content-length HTTP header with pretty much everything.

您可以尝试使用SQL SELECT data, LENGTH(data) FROM ...找出MP3文件的内容长度,然后使用header("Content-length: $lengthField");

You could try to find out the content length of the MP3 file using an SQL SELECT data, LENGTH(data) FROM ... and then set the HTTP header using header("Content-length: $lengthField");

这篇关于使用Javascript/PHP从MySQL检索和播放mp3文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆