【发布时间】:2021-12-24 19:08:27
【问题描述】:
是否可以在通过 TCP 或 UDP 从网络接收的 Xamarin.Forms(仅限 Android,不需要 iOS)上播放音频?在 WPF 中,我使用的是NAudio,我有这样的东西:
// set output device
var provider = new BufferedWaveProvider(codec.RecordFormat);
outputDevice = new WaveOut();
outputDevice.DeviceNumber = 0;
outputDevice.Init(provider);
outputDevice.Play();
从 TCP 连接接收数据:
if (outputDevice != null)
{
byte[] decoded = codec.Decode(data, 0, data.Length);
provider.AddSamples(decoded, 0, decoded.Length);
}
在这种情况下,data 是 byte[] - 它被添加到循环缓冲区,WaveOut 像流一样处理它,连续播放。该解决方案效果很好。
我在 Xamarin 中需要同样的东西 - 我想我需要某种包装器来围绕 AudioTrack,因为它是 apparently supports playing from byte stream。我应该怎么做,什么是“最好的”或首选的方式?基本上,如何播放通过纯 TCP/UDP 套接字接收的流式音频?
【问题讨论】:
标签: c# xamarin.forms naudio