Android:实现 VoIP 程序
我有一些设计问题想与有兴趣帮助我的人讨论。我计划开发一个简单的VoIP程序,允许同一网络中的两部Android手机使用VoIP。我的目标只是捕获声音,使用 UDP 发送数据,接收 UDP 数据并播放声音。
我当前的设计是有2个线程:一个捕获麦克风并发送数据;另一个线程。另一个接收字节并播放它们。
我开始使用 MediaPlayer 和 MediaRecorder 来实现它。出现的问题是如何录制和播放声音?由此,我想知道我是否需要使用文件,尽管这看起来很慢,或者是否有办法将录音自动发送到我的 UDP 套接字?
基本上,我想知道是否必须录制到文件,然后才能播放它,或者我是否可以只传递一个套接字(用于录制和播放)。
请问有人有什么建议吗?
非常感谢
I have some design questions that I want to discuss with people interested in helping me. I am planning to develop a simple VoIP program that allows two Android phones in the same network to use VoIP. My goal is simply to capture sound, send the data with UDP, receive UDP data and play sound.
My current design is to have 2 threads: one captures the microphone and sends the data; the other one receives bytes and plays them.
I was starting to implement that using MediaPlayer and MediaRecorder. The issue that came up is how do I record and play sound? By that, I would like to know if I need to use a file, although that seems slow, or if there is anyway to have the recording automatically sent to my UDP socket please?
Basically, I wonder if I have to record to a file, then to be able to play it, or if I could just pass a socket (for recording and playing).
Does anyone has any suggestion please?
Thank you very much
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
MediaRecorder 需要 FD,因此您也可以使用套接字。我认为这没有任何问题。这完全取决于您如何设计系统。
MediaRecorder needs an FD so, you can use sockets as well. I dont see any issues with that. It all depends on how you would design your system.
不要使用这些类来传输音频 - 请改用 AudioTrack 和 AudioRecord。
它们提供了播放和录制原始音频数据所需的功能,而无需处理 FD。
当您记录帧(字节[]或短[])时,用UDP数据包包装它。
当收到UDP数据包时,解压相关的byte[]或short[]并播放。
Don't use those classes for streaming audio - use AudioTrack and AudioRecord instead.
They provide the functionality you need for playing and recording raw audio data, without dealing with an FD.
When you record a frame (either byte[] or short[]), wrap it with a UDP packet.
When you receive a UDP packet, unpack the relevant byte[] or short[] and play it.