示例#1
0
        /// <summary>
        ///     Prepares the <paramref name="item"/> for playback on renderer.
        /// </summary>
        /// <param name="item">
        ///     An item to play on renderer.
        /// </param>
        /// <returns>
        ///     An <see cref="Task"/> instance which notifies about completion the async operation.
        /// </returns>
        /// <exception cref="ArgumentNullException">
        ///     <paramref name="item"/> is <c>null</c>.
        /// </exception>
        /// <exception cref="WebException">
        ///     An error occurred when sending request to service.
        /// </exception>
        /// <exception cref="MediaRendererException">
        ///     An unexpected error occurred when executing request on device.
        /// </exception>
        public async Task OpenAsync(MediaItem item)
        {
            item.EnsureNotNull("item");

            var resource = this.SelectResourceForPlayback(item);

            try
            {
                await this.avTransportService.SetAvTransportURIAsync(0, resource.Uri, resource.Metadata);
            }
            catch (FormatException ex)
            {
                throw new MediaRendererException(this, MediaRendererError.UnexpectedError, "Received result is in a bad format", ex);
            }
            catch (UPnPServiceException ex)
            {
                throw new MediaRendererException(this, ex.ErrorCode.ToMediaRendererError(), "An error occurred when opening '{0}'".F(resource.Uri), ex);
            }
        }