gpt4 book ai didi

Android 通过 udp 发送 mpegts 流

转载 作者:太空宇宙 更新时间:2023-11-03 11:16:36 30 4
gpt4 key购买 nike

我想在我的 android 应用程序中通过 udp 接收 mpegts。为此,我正在使用 gstreamer。现在,我正在尝试通过 udp 从同一台计算机的 vlc 播放器发送 mpegts 流。

在我的 android 应用程序中,我提供了 uri udp://10.0.2.2:1234 但应用程序给出错误 Could not get/set settings from/on resource。我曾尝试从互联网上获取解决方案,但到目前为止没有成功。

最佳答案

1) UDP地址范围是224.0.0.0到239.255.255.255,所以不能使用10.x.x.x

2)地址处理后,引用this处理编程部分的链接:

Getting the Broadcast Address You need to access the wifi manager to get the DHCP info and construct a broadcast address from that:

InetAddress getBroadcastAddress() throws IOException {
WifiManager wifi = mContext.getSystemService(Context.WIFI_SERVICE);
DhcpInfo dhcp = wifi.getDhcpInfo();
// handle null somehow

int broadcast = (dhcp.ipAddress & dhcp.netmask) | ~dhcp.netmask;
byte[] quads = new byte[4];
for (int k = 0; k < 4; k++)
quads[k] = (byte) ((broadcast >> k * 8) & 0xFF);
return InetAddress.getByAddress(quads);
}

Sending and Receiving UDP Broadcast Packets Having constructed the broadcast address, things work as normal. The following code would send the string data over broadcast and then wait for a response:

DatagramSocket socket = new DatagramSocket(PORT);
socket.setBroadcast(true);
DatagramPacket packet = new DatagramPacket(data.getBytes(), data.length(),
getBroadcastAddress(), DISCOVERY_PORT);
socket.send(packet);

byte[] buf = new byte[1024];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
socket.receive(packet);

关于Android 通过 udp 发送 mpegts 流,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15757270/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com