diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java @@ -66,6 +66,10 @@ * A list of urls yet to be fetched. */ private static final ArrayList fetchUrlList = new ArrayList<>(); + /** + * A list of urls currently being fetched + */ + private static final ArrayList isFetchingList = new ArrayList<>(); /** * A integer indicating how many fetches are in progress. */ @@ -138,8 +142,8 @@ return null; } - //We currently only support http(s) urls - if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https")) { + //We currently only support http(s) and file urls + if (!url.getProtocol().equals("http") && !url.getProtocol().equals("https") && !url.getProtocol().equals("file")) { return null; } @@ -206,7 +210,7 @@ } //Only fetch an URL if we're not fetching it already - if (fetchUrlList.contains(url)) { + if (fetchUrlList.contains(url) || isFetchingList.contains(url)) { return; } @@ -323,8 +327,8 @@ memoryCache.put(url.toString(), cacheItem); } - //Remove the url from the to-fetch list - fetchUrlList.remove(url); + //Remove the url from the fetching list + isFetchingList.remove(url); //Fetch the next url (if any) --numFetching; initiateFetch(); @@ -338,10 +342,23 @@ if (numFetching >= 2) return; if (fetchUrlList.isEmpty()) return; - ++numFetching; - //Fetch the last-requested url first, it will probably be needed first URL url = fetchUrlList.get(fetchUrlList.size() - 1); + //Remove the url from the to-fetch list + fetchUrlList.remove(url); + //And add it to the currently-fetching list + isFetchingList.add(url); + + //Ask the plugin to transfer file urls + if (url.getProtocol().equals("file")) { + for (MprisPlugin mpris : registeredPlugins) { + mpris.askTransferAlbumArt(url.toString()); + } + return; + } + + //Otherwise, download the album art ourselves + ++numFetching; try { DiskLruCache.Editor cacheItem = diskCache.edit(urlToDiskCacheKey(url.toString())); if (cacheItem == null) { diff --git a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java --- a/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java +++ b/src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java @@ -205,6 +205,7 @@ public final static String PACKAGE_TYPE_MPRIS_REQUEST = "kdeconnect.mpris.request"; private HashMap players = new HashMap<>(); + private boolean supportAlbumArtPayload = false; private HashMap playerStatusUpdated = new HashMap<>(); private HashMap playerListUpdated = new HashMap<>(); @@ -266,6 +267,11 @@ @Override public boolean onPackageReceived(NetworkPackage np) { + if (np.getBoolean("transferringAlbumArt", false)) { + AlbumArtCache.payloadToDiskCache(np.getString("albumArtUrl"), np.getPayload()); + return true; + } + if (np.has("player")) { MprisPlayer playerStatus = players.get(np.getString("player")); if (playerStatus != null) { @@ -306,6 +312,9 @@ } } + //Remember if the connected device support album art payloads + supportAlbumArtPayload = np.getBoolean("supportAlbumArtPayload", supportAlbumArtPayload); + List newPlayerList = np.getStringList("playerList"); if (newPlayerList != null) { boolean equals = true; @@ -463,4 +472,19 @@ } } } + + public void askTransferAlbumArt(String url) { + //First check if the remote supports transferring album art + if (!supportAlbumArtPayload) return; + if (url.isEmpty()) return; + + for (MprisPlayer player : players.values()) { + if (player.albumArtUrl.equals(url)) { + NetworkPackage np = new NetworkPackage(PACKAGE_TYPE_MPRIS_REQUEST); + np.set("player", player.getPlayer()); + np.set("albumArtUrl", url); + device.sendPackage(np); + } + } + } }