Esempio n. 1
0
 public Task PlayVideoAsync(string rendererUDN, string mediaId, string mediaServerUDN)
 {
     if (_rendererServers.TryGetValue(rendererUDN, out var renderer))
     {
         var key = AppConstants.GetMediasCacheKey(nameof(VideoItem), mediaServerUDN);
         if (_cache.TryGetValue <IEnumerable <VideoItem> >(key, out var videoItems))
         {
             var media = videoItems.FirstOrDefault(x => x.Id == mediaId);
             if (media != null)
             {
                 return(PlayAsync(renderer, media));
             }
         }
         _logger.LogWarning($"Could not find {mediaId} in videos.");
     }
     _logger.LogWarning($"Could not find {rendererUDN} in found renderer servers.");
     throw new FriendlyException(-404, "视频不存在或者已删除");
 }
Esempio n. 2
0
        public async Task <IEnumerable <TMedia> > GetMediasAsync <TMedia>(MediaServer mediaServer, bool cacheFirst = true) where TMedia : MediaItem
        {
            var key = AppConstants.GetMediasCacheKey(typeof(TMedia).Name, mediaServer.UDN);

            if (!cacheFirst || !_cache.TryGetValue <IEnumerable <TMedia> >(key, out var results))
            {
                results = await mediaServer.SearchAsync <TMedia>();

                foreach (var item in results)
                {
                    foreach (var r in item.Resources)
                    {
                        r.Uri = r.Uri.Replace("127.0.0.1", _localIp);
                    }
                }
                _cache.Set(key, results);
            }

            return(results);
        }