我需要播放HTTP直播流(m3u8播放列表),但它在示例AVPlay应用中无效。我想知道问题是模拟器是否不支持HLS。但是,我可以播放播放列表中的各个流。
我从URL获得以下响应:(我随机修改了值以确保无法访问流)
bool repeat = true;
while (repeat)
{
UdpClient udpClient = null;
try
{
// Creates the socket.
udpClient = new UdpClient(10140);
udpClient.Client.ReceiveTimeout = 2000;
IPAddress broadcastIpAddress = IPAddress.Parse("239.255.255.250");
IPEndPoint broadcastIpEndPoint = new IPEndPoint(broadcastIpAddress, 1900);
udpClient.JoinMulticastGroup(broadcastIpAddress);
// Sends SSDP.
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.Append("M-SEARCH * HTTP/1.1\r\n");
stringBuilder.Append("ST: urn:Belkin:service:basicevent:1\r\n");
stringBuilder.Append("MX: 1\r\n");
stringBuilder.Append("MAN: \"ssdp:discover\"\r\n");
stringBuilder.Append("HOST: 239.255.255.250:1900\r\n");
stringBuilder.Append("\r\n");
byte[] bytesToSend = Encoding.UTF8.GetBytes(stringBuilder.ToString());
udpClient.Send(bytesToSend, bytesToSend.Length, broadcastIpEndPoint);
// Receives response.
IPEndPoint remoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0);
byte[] receivedBytes = udpClient.Receive(ref remoteIpEndPoint);
string receivedString = Encoding.UTF8.GetString(receivedBytes);
Console.WriteLine(receivedString);
repeat = false;
}
catch (SocketException) { }
finally
{
udpClient.Close();
}
}