Exemplo n.º 1
0
 protected void LoadThumbnailFromMediaInformaion(IMediaItemInfo item, IMediaInformation mediaInformation)
 {
     if (mediaInformation != null)
     {
         //재생 시간 설정
         item.Duration = mediaInformation.NaturalDuration;
         mediaInformation.GetBitmapPixelBuffer(ThumbnailSize).Completed = (bufferResult, bufferStatus) =>
         {
             if (bufferStatus == AsyncStatus.Completed)
             {
                 var buffer = bufferResult.GetResults();
                 if (buffer != null)
                 {
                     DispatcherHelper.CheckBeginInvokeOnUI(() =>
                     {
                         WriteableBitmap wb = BitmapFactory.New(0, 0);
                         //wb.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height).AsAsyncOperation().Completed = async (bitmap, bitmapStatus) =>
                         BitmapFactory.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height).AsAsyncOperation().Completed = async(bitmap, bitmapStatus) =>
                         {
                             if (bitmapStatus == AsyncStatus.Completed)
                             {
                                 var newWb             = bitmap.GetResults();
                                 item.ImageItemsSource = newWb;
                                 //썸네일 저장
                                 if (item is StorageItemInfo)
                                 {
                                     await SaveThumbail(item as StorageItemInfo, buffer.ToArray());
                                 }
                                 else if (item is NetworkItemInfo)
                                 {
                                     await SaveThumbail(item as NetworkItemInfo, buffer.ToArray());
                                 }
                             }
                         };
                     });
                 }
             }
             mediaInformation = null;
         };
     }
 }
Exemplo n.º 2
0
        protected async Task <ImageSource> GetThumbnailAsync(IMediaItemInfo item, IMediaInformation mediaInformation)
        {
            ImageSource imageSource = null;

            if (mediaInformation != null)
            {
                var buffer = await mediaInformation.GetBitmapPixelBuffer(ThumbnailSize);

                if (buffer != null)
                {
                    await DispatcherHelper.RunAsync(async() =>
                    {
                        //imageSource = await BitmapFactory.New(0, 0).FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height);
                        imageSource = await BitmapFactory.FromPixelBuffer(buffer, (int)ThumbnailSize.Width, (int)ThumbnailSize.Height);

                        //PNG로 압축 및 DB저장
                        item.Duration = mediaInformation.NaturalDuration;
                        //썸네일 저장
                        if (item is StorageItemInfo)
                        {
                            await SaveThumbail(item as StorageItemInfo, buffer.ToArray());
                        }
                        else if (item is NetworkItemInfo)
                        {
                            await SaveThumbail(item as NetworkItemInfo, buffer.ToArray());
                        }
                        //비동기 처리 임으로 여기서 초기화 해야함.
                        mediaInformation = null;
                    });
                }
                else
                {
                    mediaInformation = null;
                }
            }
            return(imageSource);
        }