react-native-track-player icon indicating copy to clipboard operation
react-native-track-player copied to clipboard

artwork is not loaded on certain conditions

Open DNA-h opened this issue 6 years ago • 0 comments

when you are using TrackPlayer.add and you are setting artwork for the track, if the image for the artwork needs any additional authorization parameters to be load, the library is unable to correctly load the image. for example in React Native itself I am able to load images through specific uri like this:

{
  uri: `https://api.host.com/api/v1/asset?size=medium&id=${currentTrack.img}`,
  method: 'GET',
  headers: {'X-Api-Key': 'xxxxx'}
}

but if I pass same thing as artwork, library is unable to load image, because the 'X-Api-Key' is not sent to native side. Fortunately I had enough experience in Java to be able to resolve this problem myself, basically in MetadtaManger.Java file I changed updateMetadata method to something like this

GlideUrl url = new GlideUrl(track.artwork.toString(), new LazyHeaders.Builder()
                        .addHeader("X-Api-Key", "xxxx").build());
                artworkTarget = rm.asBitmap()
                        .load(url)
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                metadata.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, resource);
                                builder.setLargeIcon(resource);
                                session.setMetadata(metadata.build());
                                updateNotification();
                                artworkTarget = null;
                            }
                        });

another problem in loading artwork was loading from local files i.e. SD card, it seems library had problem loading those kind of assets too, and again hacking through native codes of the library and changing updateMetadata in MetadataManger.Java even more I had succes with somthing like this:

if (track.artwork.toString().substring(0,8).equals("file:///")){
                artworkTarget = rm.asBitmap()
                        .load(new File(track.artwork.toString().substring(7)))
                        .into(new SimpleTarget<Bitmap>() {
                            @Override
                            public void onResourceReady(Bitmap resource, Transition<? super Bitmap> transition) {
                                metadata.putBitmap(MediaMetadataCompat.METADATA_KEY_ART, resource);
                                builder.setLargeIcon(resource);

                                session.setMetadata(metadata.build());
                                updateNotification();
                                artworkTarget = null;
                            }
                        });

however unfortunately I am not experienced enough in Objective-C to fix it myself, my first question is am I doing something wrong and this functionalities that I implemented are they present in library itself or not? and secondly any pointers on how to implement them in iOS would be appreciated, I tested my code on iPhone devices and they had same issues (images not loading when additional credentials where needed, and local images were unable to be load).

"react-native": "0.59.8", "react-native-track-player": "^1.2.0",

DNA-h avatar Jan 09 '20 12:01 DNA-h