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

[Feature Request] Support for always-on-display

Open austinried opened this issue 2 years ago • 23 comments

Describe the Bug After upgrading from stable to v2.2.0-rc3, my app no longer shows track/artist name on the ambient display on an Android 12 device. The title and artist show up fine in the notification and on the lock screen when the notification is displayed, it's just when the phone is fully locked and the ambient display is on that I see the "No title" where that info used to be.

Steps To Reproduce Play a track with a valid track name/artist name on an Android 12 device, lock it, and observe the ambient display

I don't actually know how to emulate the ambient display feature but I can try to repro there too if someone else can let me know if it's possible.

Code To Reproduce https://github.com/austinried/subtracks/tree/react-native-track-player-next

Environment Info: Paste the results of npx react-native info

System:
    OS: Linux 5.4 Ubuntu 20.04.4 LTS (Focal Fossa)
    CPU: (8) x64 Intel(R) Core(TM) i7-8650U CPU @ 1.90GHz
    Memory: 158.45 MB / 15.39 GB
    Shell: 5.0.17 - /bin/bash
  Binaries:
    Node: 14.19.1 - /tmp/yarn--1650003558066-0.14211410378890887/node
    Yarn: 1.22.18 - /tmp/yarn--1650003558066-0.14211410378890887/yarn
    npm: 6.14.16 - ~/.nvm/versions/node/v14.19.1/bin/npm
    Watchman: 4.9.0 - /usr/bin/watchman
  SDKs:
    Android SDK:
      Android NDK: 22.1.7171670
  IDEs:
    Android Studio: Not Found
  Languages:
    Java: 11.0.12 - /home/austin/.sdkman/candidates/java/current/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: 17.0.2 => 17.0.2 
    react-native: 0.67.4 => 0.67.4 
  npmGlobalPackages:
    *react-native*: Not Found

austinried avatar Apr 18 '22 07:04 austinried

@mpivchev looks like a android rewrite bug.

jspizziri avatar Apr 18 '22 20:04 jspizziri

We try to extract the title from the file metadata:

override fun getCurrentContentTitle(player: Player): CharSequence {
        return metadataProvider.getTitle() ?: player.mediaMetadata.displayTitle ?: ""
    }

If nothing is found, the default will be an empty string, so it looks like the title provided in the metadata of your file is actually "No title". Please check your file metadata and if you still believe this is a bug please update this issue.

mpivchev avatar Apr 21 '22 08:04 mpivchev

I believe the metadata should be alright, as the title and subtitle display in the notification, it's only in the ambient display (when the device is locked) that it says "No title" for all tracks, and I use the same set of tracks for testing between this RC3 version and my standard 2.1.3 branch where this works. I'll see if I can duplicate this in the example app with a track I can link you to as well, though.

austinried avatar Apr 21 '22 09:04 austinried

Actually this happens with the tracks that are already in the example app apparently, so just fire that up on an Android device with ambient display and you can repro this. Here's mine:

Screenshot-20220421185143-758x847 Screenshot-20220421185104-667x610

austinried avatar Apr 21 '22 09:04 austinried

Ah I see. We currently don't handle ambient display at all, so this would have to be implemented.

mpivchev avatar Apr 21 '22 11:04 mpivchev

@mpivchev is this something it would be good to have help on?

@austinried is this something you'd be interested (with guidance) in taking a crack at?

jspizziri avatar Apr 21 '22 11:04 jspizziri

@jspizziri yeah, if anyone is willing to contribute that would be great :)

mpivchev avatar Apr 21 '22 11:04 mpivchev

This does not look like a bug, but a missing feature, so changed accordingly.

mpivchev avatar Apr 21 '22 11:04 mpivchev

Thing is though this works in 2.1.3, here's the same song from the example app:

Screenshot-20220421203603-731x330

So this is more like a feature reinstatement. Either way though, I have been trying to figure out from what I can what's being done in 2.1.3 that isn't in 2.2.0 in this case. I haven't made much progress yet, and I haven't gotten the setup working yet where I can make changes to KotlinAudio locally for testing, but I'm trying to get that going.

One thing I could really use that I'm still missing is actually documentation on what controls the media title/subtitle in the ambient display screen. I'm imagining it's not something that's being controlled directly through an API but probably something to do with how the media session is being set up and this metadata isn't being passed where it used to be.

austinried avatar Apr 21 '22 11:04 austinried

@austinried reach out to me on discord if you want help getting a android test env set up.

@mpivchev can you point @austinried in the right direction here?

jspizziri avatar Apr 21 '22 12:04 jspizziri

Actually I think I just found something close to documentation, I was relying too heavily on calling this "ambient display" in my searching and just found this SO post about media on the "always on display" https://stackoverflow.com/questions/59144878/media-session-has-no-title-on-aod-always-on-display

austinried avatar Apr 21 '22 12:04 austinried

We are using KotlinAudio and ExoPlayer as our audio player libraries. The file that is responsible for the notification content is this one.

From the post you sent it looks like it can be used to set up the AOD content as well.

mpivchev avatar Apr 21 '22 14:04 mpivchev

Same problem here!

DennisdeWitNL avatar Apr 22 '22 15:04 DennisdeWitNL

@mpivchev Thanks for the tip, I've started poking around there and the NotificationManager and I think I've found where that metadata should be passed for the AOD to work, which is into the media session/connector's metadata methods. I'm gonna do a bit more testing here and then put up a PR for review.

austinried avatar Apr 23 '22 03:04 austinried

I've got the PR up for the fix on this over in KotlinAudio here: https://github.com/doublesymmetry/KotlinAudio/pull/23

austinried avatar Apr 23 '22 12:04 austinried

Before this is completely "Done" a new version of KotlinAudio needs to be released and then this project will need to be updated to use the new version.

jspizziri avatar Apr 28 '22 18:04 jspizziri

Will do this soon! There's some other changes we're trying to also get in the next KotlinAudio release

dcvz avatar Apr 29 '22 13:04 dcvz

Thanks, just trying to leave a trail of breadcrumbs for folks.

jspizziri avatar Apr 29 '22 13:04 jspizziri

@austinried how you solved problem? can i make patch or something else

JavoxirNazarov avatar May 30 '22 11:05 JavoxirNazarov

@JavoxirNazarov You need to wait for the upstream patch to be released and then updated here.

jspizziri avatar May 30 '22 11:05 jspizziri

@jspizziri sorry, When will there be a new release?

JavoxirNazarov avatar May 30 '22 12:05 JavoxirNazarov

@JavoxirNazarov I don't know unfortunately.

jspizziri avatar May 30 '22 12:05 jspizziri

got it @jspizziri. but anyway the library is super! thank you guys for all your work!

JavoxirNazarov avatar May 30 '22 12:05 JavoxirNazarov

I just retested this on an Android device and it seems as though the issue has been fixed at some point.

jspizziri avatar Aug 30 '22 18:08 jspizziri

@jspizziri Which version are you using? I haven't found a way to solve it. Thanks!

matteodanelli avatar Oct 27 '22 15:10 matteodanelli