Example #1
0
        /// <summary>
        /// Play a media HTTP link to a media renderer
        /// </summary>
        /// <param name="mediaRenderer">media renderer</param>
        /// <param name="mediaInfo">informations about the media</param>
        /// <returns>Task</returns>
        public async Task PlayAsync(Device mediaRenderer, MediaInfo mediaInfo)
        {
            using (var httpClient = CreateHttpClient())
            {
                await SetMimeTypeAsync(httpClient, mediaInfo);

                var avTransportService = GetService(mediaRenderer, SERVICE_NAME);
                var requestUri         = GetControlUri(mediaRenderer, avTransportService);

                var setAVTransportURIAction = new SetAVTransportURIAction()
                {
                    CurrentUri  = mediaInfo.Uri,
                    UriMetadata = new DIDL_Lite()
                    {
                        Item = new Item()
                        {
                            Title   = mediaInfo.Title,
                            Creator = mediaInfo.Author,
                            Class   = $"object.item.{GetMimeTypeUPnPClass(mediaInfo.Type)}",
                            Res     = new Resource()
                            {
                                ProtocolInfo = $"http-get:*:{mediaInfo.Type}:*", Uri = mediaInfo.Uri
                            }
                        }
                    }
                };

                var response = await PostActionAsync(httpClient, avTransportService, requestUri, setAVTransportURIAction,
                                                     Tuple.Create("transferMode.dlna.org", "Streaming"));

                if (response.IsSuccessStatusCode)
                {
                    await PostActionAsync(httpClient, avTransportService, requestUri, new PlayAction());
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }
        /// <summary>
        /// Play a media HTTP link to a media renderer
        /// </summary>
        /// <param name="mediaRenderer">media renderer</param>
        /// <param name="mediaInfo">informations about the media</param>
        /// <returns>Task</returns>
        public async Task Play(Device mediaRenderer, MediaInfo mediaInfo)
        {
            using (var httpClient = CreateHttpClient())
            {
                mediaInfo = await CheckUri(httpClient, mediaInfo);
                if (mediaInfo == null)
                {
                    return;
                }

                var avTransportService = mediaRenderer.Services.First(service => service.ServiceName == "AVTransport");
                var requestUri = GetControlUri(mediaRenderer, avTransportService);

                var setAVTransportURIAction = new SetAVTransportURIAction();
                setAVTransportURIAction.CurrentUri = mediaInfo.Uri;
                setAVTransportURIAction.UriMetadata = new DIDL_Lite()
                {
                    Item = new Item()
                    {
                        Title = mediaInfo.Title,
                        Creator = mediaInfo.Author,
                        Class = $"object.item.{GetMimeTypeUPnPClass(mediaInfo.Type)}",
                        Res = new Resource() { ProtocolInfo = $"http-get:*:{mediaInfo.Type}:*", Uri = mediaInfo.Uri }
                    }
                };

                var response = await PostActionAsync(httpClient, avTransportService, requestUri, setAVTransportURIAction,
                    Tuple.Create("transferMode.dlna.org", "Streaming"));
                if (response.IsSuccessStatusCode)
                {
                    await PostActionAsync(httpClient, avTransportService, requestUri, new PlayAction());
                }
                else
                {
                    throw new Exception(response.ReasonPhrase);
                }
            }
        }