C++ HTML5 音频的流服务器
是否可以让 HTML5 音频标签的 src 为 C++ 程序,并且 C++ 程序将音频流式传输到音频元素?例如,假设我有一个 HTML5 Audio 元素尝试从本地程序获取音频,如下所示:
<audio src='file://(path to program)'>
如果可能,我应该使用哪些库?我现在只想在本地尝试一下,所以 file:// 就是我想要的。
编辑:将源设置为 file:// 不起作用,那么我如何告诉它从特定的 C++ 程序获取音频?
Is it possible to have the src of an HTML5 Audio tag be a C++ program, and for the C++ program to stream audio to the audio element? For example, let's say I have an HTML5 Audio element trying to get audio from a local program like so:
<audio src='file://(path to program)'>
If it is possible, which libraries should I use? I just want to try it locally for now, so file:// is what I want.
EDIT: Setting the source as file:// won't work, so how can I tell it to get audio from the specific C++ program?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不确定问题的 C++ 方面,但尝试通过
file:
嵌入一个可能的程序是行不通的,因为浏览器只会读取二进制文件foo.exe
而不是调用它并读取标准输出(或其他内容)。相反,出于测试目的,您可能希望在计算机上本地运行服务器,并通过
localhost
引用它。I am not sure about the C++ side of the question, but trying to embed a would-be program via
file:
will not work, as the browser would simply read the binary filefoo.exe
instead of calling it and reading in the standard output (or whatever).Instead, for testing purposes, you would probably like to run the server locally on your machine, referring to it via
localhost
.当然,如果您的 C++ 程序是独立的,您可以编写/包含一个小型 Web 服务器来仅服务传入的音频请求,然后在 C++ 中执行您想要的任何代码以返回数据。
否则,您可以将 C++ 插件/模块写入现有的 Web 服务器(如 IIS 或 apache),并配置 Web 服务器以将特定 url 的流量定向到 C++ 函数以返回数据。这可能有点复杂,但功能更强大,因为它允许您更多地关注音频代码,而不是担心处理 HTTP 协议和 TCP 连接。
无论哪种情况,您的 C++ 代码都会像任何网络服务器一样被引用。 “<音频 src='http://localhost:port/etc'>
Certainly if your C++ program was stand-alone, you could write/include a mini-web server to service only audio requests that come in and then execute whatever code you wanted to in C++ to return the data.
Otherwise you could write a C++ plugin/module to an existing web server like IIS or apache and configure the web server to direct traffic for a specific url to your C++ functions to return the data. This might be a little more complicated but alot more powerful by allowing you to focus more on your audio code than worrying about handling HTTP protocol and TCP connections.
In either case then your C++ code would be referenced the same as any webserver. "<audio src='http://localhost:port/etc'>