Search in sources :

Example 6 with FileBinaryResource

use of com.facebook.binaryresource.FileBinaryResource in project remusic by aa112901.

the class RadioDetailActivity method setAlbumart.

private void setAlbumart() {
    albumTitle.setText(albumName);
    albumArtSmall.setImageURI(Uri.parse(albumPath));
    try {
        ImageRequest imageRequest = ImageRequest.fromUri(albumPath);
        CacheKey cacheKey = DefaultCacheKeyFactory.getInstance().getEncodedCacheKey(imageRequest);
        BinaryResource resource = ImagePipelineFactory.getInstance().getMainDiskStorageCache().getResource(cacheKey);
        File file = ((FileBinaryResource) resource).getFile();
        if (file != null) {
            new setBlurredAlbumArt().execute(ImageUtils.getArtworkQuick(file, 300, 300));
            return;
        }
        imageRequest = ImageRequestBuilder.newBuilderWithSource(Uri.parse(albumPath)).setProgressiveRenderingEnabled(true).build();
        ImagePipeline imagePipeline = Fresco.getImagePipeline();
        DataSource<CloseableReference<CloseableImage>> dataSource = imagePipeline.fetchDecodedImage(imageRequest, RadioDetailActivity.this);
        dataSource.subscribe(new BaseBitmapDataSubscriber() {

            @Override
            public void onNewResultImpl(@Nullable Bitmap bitmap) {
                // No need to do any cleanup.
                if (bitmap != null) {
                    new setBlurredAlbumArt().execute(bitmap);
                }
                ;
            }

            @Override
            public void onFailureImpl(DataSource dataSource) {
            // No cleanup required here.
            }
        }, CallerThreadExecutor.getInstance());
    //drawable = Drawable.createFromStream( new URL(albumPath).openStream(),"src");
    } catch (Exception e) {
    }
}
Also used : CloseableReference(com.facebook.common.references.CloseableReference) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) BaseBitmapDataSubscriber(com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber) DataSource(com.facebook.datasource.DataSource) Bitmap(android.graphics.Bitmap) BinaryResource(com.facebook.binaryresource.BinaryResource) FileBinaryResource(com.facebook.binaryresource.FileBinaryResource) ImageRequest(com.facebook.imagepipeline.request.ImageRequest) ImagePipeline(com.facebook.imagepipeline.core.ImagePipeline) File(java.io.File) CacheKey(com.facebook.cache.common.CacheKey)

Aggregations

FileBinaryResource (com.facebook.binaryresource.FileBinaryResource)6 File (java.io.File)4 BinaryResource (com.facebook.binaryresource.BinaryResource)3 CacheKey (com.facebook.cache.common.CacheKey)3 ImageRequest (com.facebook.imagepipeline.request.ImageRequest)3 Bitmap (android.graphics.Bitmap)1 CloseableReference (com.facebook.common.references.CloseableReference)1 DataSource (com.facebook.datasource.DataSource)1 ImagePipeline (com.facebook.imagepipeline.core.ImagePipeline)1 BaseBitmapDataSubscriber (com.facebook.imagepipeline.datasource.BaseBitmapDataSubscriber)1 FileOutputStream (java.io.FileOutputStream)1 Test (org.junit.Test)1 PrepareOnlyThisForTest (org.powermock.core.classloader.annotations.PrepareOnlyThisForTest)1