gpt4 book ai didi

c# - 如何使用 UPnP C# 发送 SetAVTransportURI?

转载 作者:太空狗 更新时间:2023-10-29 20:13:19 27 4
gpt4 key购买 nike

我正在尝试向我的电视 (Sony Bravia KDL-42W800A) 发送命令以通过 UPnP 播放视频。我可以使用 SSDP 发现网络上的所有 UPnP 设备。以下是电视的示例响应:

HTTP/1.1 200 OK
CACHE-CONTROL: max-age=1800
EXT:
LOCATION: http://192.168.1.11:52323/dmr.xml
SERVER: Linux/2.6 UPnP/1.0 KDL-42W800A/1.7
ST: urn:schemas-upnp-org:service:AVTransport:1
USN: uuid:00000000-0000-1010-8000-d8d43c73618b::urn:schemas-upnp-org:service:AVTransport:1
X-AV-Physical-Unit-Info: pa="BRAVIA KDL-42W800A";
X-AV-Server-Info: av=5.0; cn="Sony Corporation"; mn="BRAVIA KDL-42W800A"; mv="1.7";

据此,我按照位置检索了包含有关电视的更多细节的 XML 文件。给出如下:

<?xml version="1.0"?>
<root xmlns="urn:schemas-upnp-org:device-1-0"
xmlns:pnpx="http://schemas.microsoft.com/windows/pnpx/2005/11"
xmlns:df="http://schemas.microsoft.com/windows/2008/09/devicefoundation">
<specVersion>
<major>1</major>
<minor>0</minor>
</specVersion>
<device>
<deviceType>urn:schemas-upnp-org:device:MediaRenderer:1</deviceType>
<friendlyName>BRAVIA KDL-42W800A</friendlyName>
<manufacturer>Sony Corporation</manufacturer>
<manufacturerURL>http://www.sony.net/</manufacturerURL>
<modelName>KDL-42W800A</modelName>
<modelNumber>MINT1.7.0.1</modelNumber>
<UDN>uuid:00000000-0000-1010-8000-d8d43c73618b</UDN>
<dlna:X_DLNADOC xmlns:dlna="urn:schemas-dlna-org:device-1-0">DMR-1.50</dlna:X_DLNADOC>
<microsoft:magicPacketWakeSupported xmlns:microsoft="urn:schemas-microsoft-com:WMPNSS-1-0">1</microsoft:magicPacketWakeSupported>
<iconList>
<icon>
<mimetype>image/png</mimetype>
<width>32</width>
<height>32</height>
<depth>24</depth>
<url>/MediaRenderer_32x32.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<width>48</width>
<height>48</height>
<depth>24</depth>
<url>/MediaRenderer_48x48.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<width>60</width>
<height>60</height>
<depth>24</depth>
<url>/MediaRenderer_60x60.png</url>
</icon>
<icon>
<mimetype>image/png</mimetype>
<width>120</width>
<height>120</height>
<depth>24</depth>
<url>/MediaRenderer_120x120.png</url>
</icon>
<icon>
<mimetype>image/jpeg</mimetype>
<width>32</width>
<height>32</height>
<depth>24</depth>
<url>/MediaRenderer_32x32.jpg</url>
</icon>
<icon>
<mimetype>image/jpeg</mimetype>
<width>48</width>
<height>48</height>
<depth>24</depth>
<url>/MediaRenderer_48x48.jpg</url>
</icon>
<icon>
<mimetype>image/jpeg</mimetype>
<width>60</width>
<height>60</height>
<depth>24</depth>
<url>/MediaRenderer_60x60.jpg</url>
</icon>
<icon>
<mimetype>image/jpeg</mimetype>
<width>120</width>
<height>120</height>
<depth>24</depth>
<url>/MediaRenderer_120x120.jpg</url>
</icon>
</iconList>
<serviceList>
<service>
<serviceType>urn:schemas-upnp-org:service:RenderingControl:1</serviceType>
<serviceId>urn:upnp-org:serviceId:RenderingControl</serviceId>
<SCPDURL>/RenderingControlSCPD.xml</SCPDURL>
<controlURL>/upnp/control/RenderingControl</controlURL>
<eventSubURL>/upnp/event/RenderingControl</eventSubURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:ConnectionManager:1</serviceType>
<serviceId>urn:upnp-org:serviceId:ConnectionManager</serviceId>
<SCPDURL>/ConnectionManagerSCPD.xml</SCPDURL>
<controlURL>/upnp/control/ConnectionManager</controlURL>
<eventSubURL>/upnp/event/ConnectionManager</eventSubURL>
</service>
<service>
<serviceType>urn:schemas-upnp-org:service:AVTransport:1</serviceType>
<serviceId>urn:upnp-org:serviceId:AVTransport</serviceId>
<SCPDURL>/AVTransportSCPD.xml</SCPDURL>
<controlURL>/upnp/control/AVTransport</controlURL>
<eventSubURL>/upnp/event/AVTransport</eventSubURL>
</service>
<service>
<serviceType>urn:dial-multiscreen-org:service:dial:1</serviceType>
<serviceId>urn:dial-multiscreen-org:serviceId:dial</serviceId>
<SCPDURL>/DIALSCPD.xml</SCPDURL>
<controlURL>/upnp/control/DIAL</controlURL>
<eventSubURL></eventSubURL>
</service>
<service>
<serviceType>urn:schemas-sony-com:service:IRCC:1</serviceType>
<serviceId>urn:schemas-sony-com:serviceId:IRCC</serviceId>
<SCPDURL>/IRCCSCPD.xml</SCPDURL>
<controlURL>http://192.168.1.11/sony/IRCC</controlURL>
<eventSubURL></eventSubURL>
</service>
<service>
<serviceType>urn:schemas-sony-com:service:ScalarWebAPI:1</serviceType>
<serviceId>urn:schemas-sony-com:serviceId:ScalarWebAPI</serviceId>
<SCPDURL>/ScalarWebApiSCPD.xml</SCPDURL>
<controlURL>/upnp/control/ScalarAPI</controlURL>
<eventSubURL></eventSubURL>
</service>
</serviceList>
<av:X_MaxBGMCount xmlns:av="urn:schemas-sony-com:av">64</av:X_MaxBGMCount>
<av:X_StandardDMR xmlns:av="urn:schemas-sony-com:av">1.1</av:X_StandardDMR>
<av:X_ScreenResolution xmlns:av="urn:schemas-sony-com:av">2K</av:X_ScreenResolution>
<av:X_IRCCCodeList xmlns:av="urn:schemas-sony-com:av">
<av:X_IRCCCode command="Power">AAAAAQAAAAEAAAAVAw==</av:X_IRCCCode>
<av:X_IRCCCode command="Power ON">AAAAAQAAAAEAAAAuAw==</av:X_IRCCCode>
<av:X_IRCCCode command="Power OFF">AAAAAQAAAAEAAAAvAw==</av:X_IRCCCode>
</av:X_IRCCCodeList>
<pnpx:X_compatibleId>MS_DigitalMediaDeviceClass_DMR_V001</pnpx:X_compatibleId>
<pnpx:X_deviceCategory>MediaDevices</pnpx:X_deviceCategory>
<pnpx:X_hardwareId>VEN_0106&amp;DEV_0006&amp;REV_01</pnpx:X_hardwareId>
<df:X_deviceCategory>Display.TV Multimedia.DMR</df:X_deviceCategory>
<av:X_TrackID_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_TrackID_BaseURL>http://192.168.1.11/sony/BgmSearch</av:X_TrackID_BaseURL>
</av:X_TrackID_DeviceInfo>
<av:X_DIALEX_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_DIALEX_AppsListURL>http://192.168.1.11/DIAL/sony/applist</av:X_DIALEX_AppsListURL>
</av:X_DIALEX_DeviceInfo>
<av:X_ScalarWebAPI_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_ScalarWebAPI_Version>1.0</av:X_ScalarWebAPI_Version>
<av:X_ScalarWebAPI_BaseURL>http://192.168.1.11/sony</av:X_ScalarWebAPI_BaseURL>
<av:X_ScalarWebAPI_ServiceList>
<av:X_ScalarWebAPI_ServiceType>guide</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>system</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>videoScreen</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>audio</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>avContent</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>recording</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>appControl</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>browser</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>notification</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>cec</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>accessControl</av:X_ScalarWebAPI_ServiceType>
<av:X_ScalarWebAPI_ServiceType>irCommandProxy</av:X_ScalarWebAPI_ServiceType>
</av:X_ScalarWebAPI_ServiceList>
</av:X_ScalarWebAPI_DeviceInfo>
<av:X_RDIS_DeviceInfo xmlns:av="urn:schemas-sony-com:av">
<av:X_RDIS_Version>1.0</av:X_RDIS_Version>
<av:X_RDIS_SESSION_CONTROL>false</av:X_RDIS_SESSION_CONTROL>
<av:X_RDIS_ENTRY_PORT>20677</av:X_RDIS_ENTRY_PORT>
</av:X_RDIS_DeviceInfo>
</device>
</root>

如果我有链接,如何使用此信息请求电视播放视频?到目前为止,我已经尝试根据我在网上阅读的内容获得这段代码,它应该设置 AVTransportURI,但它一直出现错误 500 内部服务器错误。

    private const string SetAvTransportURIXml = "<?xml version=\"1.0\" encoding=\"utf-8\"?>" +
"<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\" s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\">" +
"<s:Body>" +
"<u:SetAVTransportURI xmlns:u=\"urn:schemas-upnp-org:service:AVTransport:1\">" +
"<InstanceID>0</InstanceID>" +
"<CurrentURI>{0}</CurrentURI>" +
"<CurrentURIMetaData></CurrentURIMetaData>" +
"</u:SetAVTransportURI>" +
"</s:Body>" +
"</s:Envelope>";

public void PlayVideo(string videoLink)
{
byte[] bytes;
bytes = Encoding.UTF8.GetBytes(String.Format(SetAvTransportURIXml, videoLink));

HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://192.168.1.11:52323/upnp/control/AVTransport");
request.Headers.Add("SOAPAction", "\"urn:schemas-upnp-org:service:AVTransport:1#SetAVTransportURI\"");
request.ContentType = "text/xml; encoding=\"utf-8\"";
request.ContentLength = bytes.Length;
request.Method = "POST";
Stream requestStream = request.GetRequestStream();
requestStream.Write(bytes, 0, bytes.Length);
requestStream.Flush();
requestStream.Close();
var response = (HttpWebResponse) request.GetResponse();
if (response.StatusCode == HttpStatusCode.OK)
{
Stream responseStream = response.GetResponseStream();
if (responseStream == null) return;
string responseStr = new StreamReader(responseStream).ReadToEnd();
Console.WriteLine(responseStr);
}
}

如有任何帮助,我们将不胜感激。

最佳答案

尝试将一些 DIDL-Lite 元数据放入 CurrentURIMetaData 参数中。如果我将该字段留空,我的 LG 电视将拒绝播放任何内容。

例如以下对我有用(当嵌入到外部 XML 结构中时自然需要转义):

<?xml version="1.0"?>
<DIDL-Lite xmlns="urn:schemas-upnp-org:metadata-1-0/DIDL-Lite/" xmlns:upnp="urn:schemas-upnp-org:metadata-1-0/upnp/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:sec="http://www.sec.co.kr/">
<item id="f-0" parentID="0" restricted="0">
<dc:title>Video</dc:title>
<dc:creator>Anonymous</dc:creator>
<upnp:class>object.item.videoItem</upnp:class>
<res protocolInfo="http-get:*:video/mp4:DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000">{0}</res>
</item>
</DIDL-Lite>

此外,可能需要在对电视媒体请求(在您提供的 URL 中)的 HTTP 响应中包含一些特殊的 header 。我的 LG 电视拒绝播放,除非媒体文件响应具有以下 header (顺便说一句,区分大小写!):

contentFeatures.dlna.org: DLNA.ORG_OP=01;DLNA.ORG_CI=0;DLNA.ORG_FLAGS=01700000000000000000000000000000
transferMode.dlna.org: Streaming

实现 UPnP/DLNA 时可能会出现很多问题。如果电视有什么不喜欢的,它只会拒绝接受。错误消息可能相当不明确。需要大量的测试迭代来确定如何强制不同的 DLNA 设备实现进行协作。市场上的许多/大多数电视设备仅实现了一小部分规范。以他们自己的方式。

在 Github 代码搜索中搜索 SetAVTransportURI 等有助于了解其他人是如何实现的。

关于c# - 如何使用 UPnP C# 发送 SetAVTransportURI?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28422609/

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