使用嵌入标签播放 mp3 文件,其中源是 ashx 文件和数据库中的字节数组
我目前将文本到语音 mp3 文件存储为数据库中的 varbinary(max) 。我想要做的是使用嵌入标签播放这些音频文件,其中源是 ashx 文件,该文件将接收数据库记录的 id 并写入字节数组。
我的 ashx 文件具有以下代码
byte[] byteArray = ttsMessage.MessageContents;
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/mpeg";
context.Response.OutputStream.Write(byteArray, 0, byteArray.Length);
context.Response.End();
来自 aspx 页面的调用如下
Panel5.Controls.Add(new LiteralControl(String.Format("<embed src='/TestArea/PreviewWav.ashx?source={0}' type='audio/mpeg' height='60px' width='144px'/>", ttsMessage.Id.ToString())));
我已使其与以下
Panel5.Controls.Add(new LiteralControl(String.Format("<audio controls='controls' autoplay='autoplay'><source src='/TestArea/PreviewWav.ashx?source={0}' type='audio/x-wav' /></audio>", ttsMessage.Id.ToString())));
使用音频标签一起使用,但似乎无法使其与嵌入标签一起使用。
我使用的是IE9/VS2010 有什么想法吗?
I currently store text to speech mp3 files as varbinary(max) in the database. what I want to do is play those audio files using the embed tag where the source is ashx file that will recieve the id of the database record and write the byte array.
My ashx file has the following code
byte[] byteArray = ttsMessage.MessageContents;
context.Response.Buffer = true;
context.Response.Clear();
context.Response.ClearContent();
context.Response.ClearHeaders();
context.Response.ContentType = "audio/mpeg";
context.Response.OutputStream.Write(byteArray, 0, byteArray.Length);
context.Response.End();
The call from the aspx page is as follows
Panel5.Controls.Add(new LiteralControl(String.Format("<embed src='/TestArea/PreviewWav.ashx?source={0}' type='audio/mpeg' height='60px' width='144px'/>", ttsMessage.Id.ToString())));
I have gotten this to work with the following
Panel5.Controls.Add(new LiteralControl(String.Format("<audio controls='controls' autoplay='autoplay'><source src='/TestArea/PreviewWav.ashx?source={0}' type='audio/x-wav' /></audio>", ttsMessage.Id.ToString())));
Using the audio tag but cannot seem to get it to work with the embed tag.
I am using IE9/VS2010
Any ideas?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为嵌入标签的错误在于......
嵌入标签调用像 winmediaplayer ocx 这样的插件,然后首先从网页调用处理程序,然后媒体插件获取 ashx url,然后开始调用处理程序。
但是网页的请求和媒体播放器插件的请求不同,因此如果您检查用户身份验证或其他一些标头信息,则会失败。
您可以在 fiddler 实用程序中轻松看到这一点。 fiddler 右上角显示请求信息。有用户代理部分。仔细看看。
您的处理程序发出了多少请求,请注意它们。有什么不同。对于每个要求。
如果你有这个问题,
您可以使用票证系统或重定向安全区域进行下载,而无需进行标头或其他请求检查。遗憾的是网页请求无法完全传输媒体播放器和其他内容。
希望有帮助
I think the wrong thing with embed tag is that...
Embed tag call a plugin like winmediaplayer ocx than handler firstly called from web page than media plugin get the ashx url than it started to call handler.
But web page's request and mediaplayer plugin's requests are diffent so if you check users Authentication or some other header information it fails.
You can easily see that on fiddler utility. On fiddler top-right side shows the request info. there is a user-agent part. Look it carefully.
How many requests happen from your handler,notice them. What are the differs. for each reqs.
If you have this issue,
You may use a ticket system or redirect a safety area for download without header or other request checks. Sadly web page requst cannot complately transfer media player and others.
hope helps