Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add android auto support #143

Merged
merged 2 commits into from
Oct 20, 2020
Merged

Add android auto support #143

merged 2 commits into from
Oct 20, 2020

Conversation

Spacetech
Copy link
Contributor

This change adds basic android auto support. A video of it in action for reference: https://youtu.be/Zl-ETVcv5BQ

Main changes:

  • Implements a MediaBrowserServiceCompat which lets Android auto detect Jellyfin as a music player
  • Supports library selection and drilling down into the library by different views (latest, albums, artists, songs, genres)
  • Supports shuffling in the album view
  • Supports prev / next tracks
  • Shows thumbnails when possible

Notes:

  • The MediaService (implementation of MediaBrowserServiceCompat) is a fairly standalone thing. Due to how android auto music players work, it will not rely on the main webview for ui. Instead it will use the ApiClient to load data from Jellyfin.
  • Since it's a separate service and could/will launch independently from the main app, I added preferences for the server url, user id, and access token. Those preferences will be updated when the main app is launched. This makes it so the last used server will be used in android auto. Note: Saving the access token should be safe since the preferences are marked as private.
  • I named the folder car because that's more inline with what Google calls it - Android for Cars
  • I based the url I use to load the audio track in the createMediaSource method on what the web client did. Is there a better way to obtain this url? (is there an api property for it?)

I see this as basic support that should be good enough to merge for now. There's certainly room for improvement. Here's a few ideas:

  • Add shuffle button to more views
  • Most of the lists are currently limited to 100 items. We need to figure out how to display more things in the android auto music ui. Some other music player apps list all the artist initials first and you slowly drill down to find what you're looking for. This has the advantage of supporting a large number of artists/albums. The disadvantage is that it requires a lot more user interaction to pick stuff out
  • Better integration with the main app - Something like auto resuming whatever was last played would be great
  • Add search support - Because clicking through large libraries to find a specific item is not fun
  • Support for some sort of offline mode

This was my first time using Kotlin so let me know if I did anything weird. Thanks

References:

@nielsvanvelzen
Copy link
Member

Before I start reviewing I'd like to point out a few things:

  • We will not include this in the initial 2.0.0 release. (But probably 2.1 as "main feature")
  • We need to look into the publishing guidelines for Android Auto, I know Google is quite strict on those
  • Since none of our Android contributors have Android Auto we won't be able to test it on real hardware, I think the emulator should work sufficiently though
    This means that the PR might be open a while after approval before we merge it.

And lastly, thanks for this contribution! I'm really excited to see our efforts for the app rewrite are enabling features like this.

@nielsvanvelzen nielsvanvelzen added this to In progress in v2.1.0 via automation Sep 24, 2020
@neopc10
Copy link

neopc10 commented Sep 25, 2020

Cool! Does this have playlist support?

@Spacetech
Copy link
Contributor Author

@nielsvanvelzen That all sounds good. For reference, I have been doing the majority of testing on my phone using the Android Auto for phones app

@neopc10 Good idea. I just added that.

Going forward I don't want to add too much more to this pr, otherwise it may become harder to review.

@nielsvanvelzen
Copy link
Member

I had some issues to get the Android Auto app working but fortunately Google made the "Android Media Controller Test" app which is useful for testing the media browser:

https://github.com/googlesamples/android-media-controller

@mholt
Copy link

mholt commented Sep 26, 2020

Sorry I am of no help here whatsoever, but I just want to cheer you on from the sidelines, sooooo yeah! 🥳 🙌 Really looking forward to this!

buildSrc/src/main/kotlin/Dependencies.kt Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/Dependencies.kt Outdated Show resolved Hide resolved
app/src/main/java/org/jellyfin/mobile/car/MediaService.kt Outdated Show resolved Hide resolved
app/src/main/java/org/jellyfin/mobile/car/MediaService.kt Outdated Show resolved Hide resolved
app/src/main/java/org/jellyfin/mobile/car/MediaService.kt Outdated Show resolved Hide resolved
Copy link
Member

@nielsvanvelzen nielsvanvelzen left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Just one tiny change left.

app/build.gradle.kts Outdated Show resolved Hide resolved
Copy link
Member

@Maxr1998 Maxr1998 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the contribution! The changes generally look quite good, I'm not happy with some smaller parts and some of the formatting however. Also, I think some things require advance changes to the rest of the app, as described in the individual comments.

buildSrc/src/main/kotlin/Dependencies.kt Outdated Show resolved Hide resolved
buildSrc/src/main/kotlin/Dependencies.kt Outdated Show resolved Hide resolved
@Maxr1998 Maxr1998 added the enhancement New feature or request label Oct 12, 2020
@Maxr1998
Copy link
Member

Maxr1998 commented Oct 18, 2020

@Spacetech I've decided to not do the database stuff and merge this pretty much as is. I've already rebased it locally onto the latest master and fixed the conflicts and squashed the commits in that process. If it's ok for you, I'd force push the changes to this branch.
Then, both Niels and me will give it another review, so we can hopefully merge it!

@Spacetech
Copy link
Contributor Author

@Maxr1998 Yea that sounds great. Go for it

@Maxr1998
Copy link
Member

Maxr1998 commented Oct 18, 2020

Perfect! I just noticed that since we updated ExoPlayer in the meantime, the MediaService uses deprecated APIs now. I'll fix those in a minute 😁

@Maxr1998
Copy link
Member

Maxr1998 commented Oct 18, 2020

Updated to the latest ExoPlayer APIs, refactored some code, fixed the album covers for the currently playing song (it didn't work for me because for my collection only the albums have images, so now it falls back to those), and gave it a final test, worked perfectly. I'm happy now 😊

@Maxr1998 Maxr1998 requested review from nielsvanvelzen and removed request for nielsvanvelzen October 18, 2020 22:51
"StartTimeTicks=0&" +
"EnableRedirection=true&" +
"EnableRemoteMedia=true"

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at https://github.com/jellyfin/jellyfin-apiclient-java/blob/master/jellyfin-api/src/main/kotlin-generated/org/jellyfin/apiclient/api/operations/UniversalAudioApi.kt#L43

  • The deviceId should probably be plaintext, not base64
  • PlaySessionId doesn't exist
  • StartTimeTicks should default to 0 when missing
  • EnableRedirection is true by default

@dkanada
Copy link
Member

dkanada commented Oct 20, 2020

@Spacetech if you have any interest in adding this to Gelli feel free 😅 lots of people ask about Android Auto but I can't exactly test it easily without a device that supports it.

@Maxr1998 Maxr1998 merged commit 469af86 into jellyfin:master Oct 20, 2020
v2.1.0 automation moved this from In progress to Done Oct 20, 2020
@nielsvanvelzen
Copy link
Member

nielsvanvelzen commented Oct 25, 2020

Hey @Spacetech you mind it if I use your YouTube video in the 2.1 release notes?

edit: I'll go ahead and use it in our blog post (jellyfin-archive/jellyfin-blog#84). Please let us know if you don't like that and we'll remove the video asap.

@Spacetech
Copy link
Contributor Author

@nielsvanvelzen I don't mind, go for it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants