Exemple #1
0
        public R <Image> GetThumbnail(PlayResource playResource)
        {
            var uri    = new Uri(playResource.PlayUri);
            var result = GetStreamFromUriUnsafe(uri);

            if (!result)
            {
                return(result.Error);
            }

            using (var stream = result.Value)
            {
                var data = AudioTagReader.GetImage(stream);
                if (data == null)
                {
                    return("No image found");
                }

                using (var memStream = new MemoryStream(data))
                {
                    try
                    {
                        return(new Bitmap(memStream));
                    }
                    catch (ArgumentException)
                    {
                        return("Inavlid image data");
                    }
                }
            }
        }
        private static HeaderData GetStreamHeaderData(Stream stream)
        {
            var headerData = AudioTagReader.GetData(stream) ?? new HeaderData();

            headerData.Title = headerData.Title ?? string.Empty;
            return(headerData);
        }
        public R <Stream, LocalStr> GetThumbnail(ResolveContext _, PlayResource playResource)
        {
            byte[] rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri    = new Uri(playResource.PlayUri);
                var result = GetStreamFromUriUnsafe(uri);
                if (!result)
                {
                    return(result.Error);
                }

                using (var stream = result.Value)
                {
                    rawImgData = AudioTagReader.GetData(stream)?.Picture;
                }
            }

            if (rawImgData is null)
            {
                return(new LocalStr(strings.error_media_image_not_found));
            }

            return(new MemoryStream(rawImgData));
        }
Exemple #4
0
        public async Task GetThumbnail(ResolveContext _, PlayResource playResource, Func <Stream, Task> action)
        {
            byte[]? rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri = new Uri(playResource.PlayUri);

                if (uri.IsWeb())
                {
                    rawImgData = await WebWrapper.Request(uri)
                                 .ToAction(async response => AudioTagReader.GetData(await response.Content.ReadAsStreamAsync())?.Picture);
                }
                else if (uri.IsFile())
                {
                    rawImgData = AudioTagReader.GetData(File.OpenRead(uri.LocalPath))?.Picture;
                }
                else
                {
                    throw Error.LocalStr(strings.error_media_invalid_uri);
                }
            }

            if (rawImgData is null)
            {
                throw Error.LocalStr(strings.error_media_image_not_found);
            }

            await action(new MemoryStream(rawImgData));
        }
Exemple #5
0
 private static void GetStreamData(string id, ref string name, Stream stream)
 {
     if (string.IsNullOrEmpty(name))
     {
         if (stream != null)
         {
             name = AudioTagReader.GetTitle(stream);
             name = string.IsNullOrWhiteSpace(name) ? id : name;
         }
         else
         {
             name = id;
         }
     }
 }
Exemple #6
0
        public R <Image> GetThumbnail(PlayResource playResource)
        {
            byte[] rawImgData;

            if (playResource is MediaPlayResource mediaPlayResource)
            {
                rawImgData = mediaPlayResource.Image;
            }
            else
            {
                var uri    = new Uri(playResource.PlayUri);
                var result = GetStreamFromUriUnsafe(uri);
                if (!result)
                {
                    return(result.Error);
                }

                using (var stream = result.Value)
                {
                    rawImgData = AudioTagReader.GetData(stream)?.Picture;
                }
            }

            if (rawImgData == null)
            {
                return("No image found");
            }

            using (var memStream = new MemoryStream(rawImgData))
            {
                try
                {
                    return(new Bitmap(memStream));
                }
                catch (ArgumentException)
                {
                    return("Inavlid image data");
                }
            }
        }
Exemple #7
0
 private static string GetStreamName(Stream stream)
 => AudioTagReader.GetTitle(stream) ?? string.Empty;