public static async Task <WebBoolResult> ProcessAsync(IOwinContext context, string itemId, string clientDescription, string identifier, WebMediaType type, int?idleTimeout) { if (itemId == null) { throw new BadRequestException("InitStream: itemId is null"); } if (clientDescription == null) { throw new BadRequestException("InitStream: clientDescription is null"); } if (identifier == null) { throw new BadRequestException("InitStream: identifier is null"); } StreamItem streamItem = new StreamItem { ItemType = type, ClientDescription = clientDescription, IdleTimeout = idleTimeout ?? -1, ClientIp = context.Request.RemoteIpAddress }; MediaItem mediaItem = new LiveTvMediaItem(Guid.Empty); if (streamItem.ItemType == WebMediaType.TV || streamItem.ItemType == WebMediaType.Radio) { int channelIdInt; if (!int.TryParse(itemId, out channelIdInt)) { throw new BadRequestException(string.Format("InitStream: Couldn't convert channelId to int: {0}", itemId)); } streamItem.Title = "Live TV"; if (streamItem.ItemType == WebMediaType.Radio) { streamItem.Title = "Live Radio"; } streamItem.LiveChannelId = channelIdInt; var info = await MediaAnalyzer.ParseChannelStreamAsync(channelIdInt, (LiveTvMediaItem)mediaItem); if (info == null) { throw new BadRequestException(string.Format("InitStream: Couldn't parse channel stream: {0}", channelIdInt)); } } else { Guid itemGuid; if (!Guid.TryParse(itemId, out itemGuid)) { throw new BadRequestException(string.Format("InitStream: Couldn't parse itemId: {0}", itemId)); } ISet <Guid> necessaryMIATypes = new HashSet <Guid>(); necessaryMIATypes.Add(MediaAspect.ASPECT_ID); necessaryMIATypes.Add(ProviderResourceAspect.ASPECT_ID); ISet <Guid> optionalMIATypes = new HashSet <Guid>(); optionalMIATypes.Add(VideoAspect.ASPECT_ID); optionalMIATypes.Add(AudioAspect.ASPECT_ID); optionalMIATypes.Add(ImageAspect.ASPECT_ID); mediaItem = MediaLibraryAccess.GetMediaItemById(context, itemGuid, necessaryMIATypes, optionalMIATypes); if (mediaItem == null) { throw new NotFoundException(string.Format("InitStream: Couldn't init stream! No MediaItem found with id: {0}", itemId)); } streamItem.Title = mediaItem[MediaAspect.Metadata.AspectId][0].GetAttributeValue <string>(MediaAspect.ATTR_TITLE); } streamItem.RequestedMediaItem = mediaItem; // Add the stream to the stream controller bool result = await StreamControl.AddStreamItemAsync(identifier, streamItem); return(new WebBoolResult { Result = result }); }