Esempio n. 1
0
		private MediaResource SelectResourceForPlayback(MediaItem mediaItem)
		{
			var resource = mediaItem.Resources.First();

			var imageItem = mediaItem as ImageItem;
			if (imageItem != null)
			{
				var maxWidth = 0.0;
				foreach (var mediaResource in imageItem.Resources)
				{
					if (mediaResource.Resolution.Width > maxWidth)
					{
						maxWidth = mediaResource.Resolution.Width;
						resource = mediaResource;
					}
				}
			}

			return resource;
		}
Esempio n. 2
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);
			}
		}