Html WebRTC 实时音频流/广播

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14507542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 05:13:43  来源:igfitidea点击:

WebRTC Live Audio Streaming/Broadcast

htmlhtml5-audiowebrtc

提问by Daniel Humphrey

I'm trying to get my head round WebRTC. I need to be able to capture and stream live audio through a web browser.

我正在努力了解 WebRTC。我需要能够通过网络浏览器捕获和流式传输实时音频。

I'm just having difficulty finding the code examples that I can understand or is up-to-date. If anyone could help me with just first capturing and playing audio in the same browser with HTML5/WebRTC I think that would help me get started and along my way.

我只是很难找到我可以理解或最新的代码示例。如果有人可以帮助我首先使用 HTML5/WebRTC 在同一浏览器中捕获和播放音频,我认为这将帮助我开始并继续我的工作。

Note: I'm only concerned about getting this to work in Chrome (or Chrome Canary for that matter!).

注意:我只关心让它在 Chrome(或 Chrome Canary)中工作!)。

Thanks for any help!

谢谢你的帮助!

回答by HartleySan

The HTML5 Rocks article on WebRTCis probably the best intro article that explains everything in layman's terms.

WebRTC 上HTML5 Rocks 文章可能是最好的介绍性文章,它以外行的方式解释了一切。

For simply capturing local video/audio, you'll want to focus on the MediaStream API (i.e., getUserMedia). Once you get that working, then you'll need to start looking into the RTCPeerConnection API.

为了简单地捕获本地视频/音频,您需要关注 MediaStream API(即 getUserMedia)。一旦你开始工作,那么你就需要开始研究 RTCPeerConnection API。

The client-side code for the RTCPeerConnection API is pretty straightforward, but the server-side code required for signalling (i.e., establishing a peer-to-peer connection) can be tricky.

RTCPeerConnection API 的客户端代码非常简单,但是信令(即建立对等连接)所需的服务器端代码可能很棘手。

I ended up coding my own server-side solution in PHP, but to do so took me about three weeks of banging my head against the wall (i.e., trying to decipher the WebSocket specs) to get it to work properly. If you'd like to see actual code, I can post some of my working code.

我最终用 PHP 编写了我自己的服务器端解决方案,但这样做花了我大约三周的时间(即试图破译WebSocket 规范)以使其正常工作。如果您想查看实际代码,我可以发布一些我的工作代码。

If you're up for the challenge, I recommend trying to code the server-side script yourself, but otherwise, I would look into WebSocket libraries like Socket.IO, which do all the tricky server-side stuff for you.

如果您愿意接受挑战,我建议您尝试自己编写服务器端脚本,否则,我会研究像 Socket.IO 这样的 WebSocket 库,它为您完成所有棘手的服务器端工作。

回答by igorpavlov

If you are talking on WebRTC Live Audio Streaming/Broadcast, not just about peer-to-peer calls, WebRTC is not designed for broadcasts. Check here WebRTC - scalable live stream broadcasting / multicasting

如果您谈论的是WebRTC Live Audio Streaming/Broadcast,而不仅仅是点对点通话,WebRTC 并不是为广播而设计的。在此处查看WebRTC - 可扩展的直播流广播/多播