Add album cover art support.
ClosedPublic

Authored by mtijink on Dec 30 2017, 1:45 PM.

Details

Summary

Fetches http(s) album art urls, as supplied by MPRIS, to display as album art. Fetched urls and failed fetches are cached to prevent unneccessary network activity.

The bulk of the code is in the fetching+caching class AlbumArtCache.

Takes the comments from d52be10 into account:

  • The images (HTTP(S) only for now) are cached. This is limited to 5 MB on disk or 10 entries in memory.
  • The image gets viewing space depending on the remaining screen space. Thus, controls should never be pushed off-screen.
  • "Edge cases" like going from cover art to no cover art is handled correctly (actually a result of earlier mpris code changes).

Additionally, it adds a landscape mode to the MPRIS activity, which shows the cover art and controls side by side.

Desktop part is in D9563.

FEATURE: 345015

Test Plan

Works both with/without album art. Switching players and tracks correctly changes the album art.

Diff Detail

Repository
R225 KDE Connect - Android application
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
mtijink requested review of this revision.Dec 30 2017, 1:45 PM
mtijink created this revision.

Screenshot portrait layout:

Screenshot landscape layout:

If no album art is visible, the controls appear in exactly the same spot, to prevent the controls from jumping around on changing tracks. The disadvantage is that the controls are not centered if there's no album art.

apol added a subscriber: apol.Dec 31 2017, 2:32 AM

Looks good! :)

Do we really need to have the margin around the image? Or is it that the image is too small?

nicolasfella added a subscriber: nicolasfella.
nicolasfella added inline comments.
res/layout/activity_mpris.xml
13

Can this be done by adding a top margin to the ImageView or a padding to the layout?

ngraham added a subscriber: ngraham.Jan 2 2018, 7:22 PM

Landscape looks great! For portrait, the image seems too small, and gets overwhelmed by the margins around it, particularly on the left and right sides.

nicolasfella added inline comments.Jan 2 2018, 7:24 PM
res/layout/mpris_control.xml
7

match_parent instead of 0dp seems to look the same but leaves the visual editor in Android Studio working. Why the change?

A propse:

With the limited Spotify controls:

With full controls:

Without artwork:

The artwork has a fixed aspect ratio. In the first image the artwork uses the full width leaving space at the bottom. In the second image the height of the screen is fully used resulting in the artwork not using the full width.

This is generated by the following activity_mpris.xml:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:paddingLeft="25dp"
    android:paddingTop="25dip"
    android:paddingRight="25dip"
    android:paddingBottom="15dip"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_vertical">

    <ImageView
        android:id="@+id/album_art"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:layout_marginBottom="25dip"
        android:scaleType="fitCenter" />

    <include
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        layout="@layout/mpris_control" />
</LinearLayout>
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
205

View.GONE works better with my suggestion

That looks better to me.

mtijink updated this revision to Diff 24689.Jan 3 2018, 8:02 PM
mtijink marked 2 inline comments as done.

Incorporated the portait layout change.

res/layout/mpris_control.xml
7

At first, I needed a default value, to use while include the file. But I later figured out that I could override these values. I've changed them back.

src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
205

I disagree. Because the image takes some time to be loaded, the controls jump around every time a new track is played. This is even worse when you want to click next a few times quickly.

When no artwork is available the controls stay at the bottom instead of being centered. We could

  1. Leave it this way. Not pretty IMHO, but not too bad
  2. Set the visibility to GONE (hence center the controls) only when no artwork is available at all and set it to INVISIBLE when loading the artwork
  3. Create a default artwork
src/org/kde/kdeconnect/Plugins/MprisPlugin/AlbumArtCache.java
95

Merge the two try blocks with a try-multicatch?

317

else?

src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisActivity.java
205

Agreed.

mtijink updated this revision to Diff 25319.Jan 14 2018, 2:47 PM

I took your third approach: I added a placeholder album art image.

mtijink marked 2 inline comments as done.Jan 14 2018, 2:49 PM

How it looks:

I'm not entirely satisfied with this placeholder image, so suggestions are welcome.

Can you confirm that something like https://bugs.kde.org/show_bug.cgi?id=370890 won't happen?

Can you confirm that something like https://bugs.kde.org/show_bug.cgi?id=370890 won't happen?

I can for portrait mode: the ImageView uses the remaining space instead of a fixed amount. In landscape mode it uses half of the screen, but I think that's not a problem in practice. The height of the layout is more limiting, and that's unchanged in landscape mode.

albertvaka accepted this revision.Feb 17 2018, 10:42 AM
albertvaka added a subscriber: albertvaka.

Looks nice :D

This revision is now accepted and ready to land.Feb 17 2018, 10:42 AM

I've tested it quite some time. Works really well, but I noticed some visual glitches. I will give details in a couple of days.

When using a player that doesn't provide artwork (I tested it with plasma browser integration) the UI glitches when hitting the play/pause button.

It also occurs when the player is played/paused directly

It's because the mpris player reports canPlay as false (for a very small period), so the play/pause button disappears. It's made more obvious by the image, but that's not the cause.

I'd suggest disabling the play/pause button instead of removing it, that's more logical for the user too. What do you think?

That sounds reasonable

I'll do that in a separate diff, as it's more general than only the album art.

This revision was automatically updated to reflect the committed changes.
nicolasfella reopened this revision.Mar 2 2018, 9:06 PM
nicolasfella added inline comments.
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java
288

This should be newAlbumArtUrl.toString(), shouldn't it?

This revision is now accepted and ready to land.Mar 2 2018, 9:06 PM
mtijink closed this revision.Mar 3 2018, 1:46 PM
mtijink marked an inline comment as done.
mtijink added inline comments.
src/org/kde/kdeconnect/Plugins/MprisPlugin/MprisPlugin.java
288

Yes, good catch. Fixed on master.