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

updateMetadataForTrack not working most of the time #1719

Closed
RamProg opened this issue Sep 9, 2022 · 26 comments
Closed

updateMetadataForTrack not working most of the time #1719

RamProg opened this issue Sep 9, 2022 · 26 comments
Assignees
Labels
Bug Dependency An issue caused by one or more project dependencies Platform: Android

Comments

@RamProg
Copy link

RamProg commented Sep 9, 2022

Describe the Bug
updateMetadataForTrack is not changing the notification and the Now Playing Center on Android. I'm leaving an example with the title property changing, but the same happens with the duration and with every other property.

Steps To Reproduce
On Android Add a track to the queue, play it and try to update the notification with the updateMetadataForTrack.
You should see a change in the notification, but that's not happening.
If you get the track you'll see the changes, but the notification always stays the same (I think it worked once or twice, but fails most times).

Code To Reproduce

const oldTitle = (await TrackPlayer.getTrack(0))?.title;
console.log('old Title: ', oldTitle);
await TrackPlayer.updateMetadataForTrack(0, {
    title: 'has changed',
});
const newTitle = (await TrackPlayer.getTrack(0))?.title;
console.log('newTitle', newTitle);
// oldTitle: 'My favourite Song'
// newTitle: 'hasChanged'

Environment Info:

System:
    OS: macOS 12.2.1
    CPU: (10) x64 Apple M1 Max
    Memory: 28.82 MB / 32.00 GB
    Shell: 5.8 - /bin/zsh
  Binaries:
    Node: 14.15.0 - ~/.nvm/versions/node/v14.15.0/bin/node
    Yarn: 1.22.19 - ~/.nvm/versions/node/v14.15.0/bin/yarn
    npm: 6.14.8 - ~/.nvm/versions/node/v14.15.0/bin/npm
    Watchman: 2022.07.04.00 - /opt/homebrew/bin/watchman
  Managers:
    CocoaPods: 1.11.3 - /usr/local/bin/pod
  SDKs:
    iOS SDK:
      Platforms: DriverKit 21.4, iOS 15.5, macOS 12.3, tvOS 15.4, watchOS 8.5
    Android SDK: Not Found
  IDEs:
    Android Studio: 2021.2 AI-212.5712.43.2112.8609683
    Xcode: 13.4.1/13F100 - /usr/bin/xcodebuild
  Languages:
    Java: 11.0.16 - /usr/bin/javac
  npmPackages:
    @react-native-community/cli: Not Found
    react: Not Found
    react-native: Not Found
    react-native-macos: Not Found
  npmGlobalPackages:
    *react-native*: Not Found

react-native-track-player v3.1.0 Also happens in nightly.
Android Studio Simulator and device.
MacOS.

How I can Help
I can provide support and data.

@RamProg RamProg added the Bug label Sep 9, 2022
@Tucker2015
Copy link

Tucker2015 commented Sep 10, 2022

Having the same issue but my Artwork is updating correctly just not title or artist. iOS works fine.

I tried

TrackPlayer.updateNowPlayingMetadata({
title: String(title),
artist: String(artist),
artwork: img === '' ? metadata.artwork : img,
});

This is the same code I used in v2.2.0-rc3 and updated fine with that version.

@RamProg
Copy link
Author

RamProg commented Sep 12, 2022

Yeah, my issue is with the duration because I'm trying to get the duration and then update it, but I noticed it also fails with other properties. I haven't tried the updateNowPlayingMetadata, but if it's not working for you it's probably the same issue.

@VinceBT
Copy link

VinceBT commented Sep 13, 2022

I have the same issue in android, using the same code as before, and I have null for the artist and title, and sometimes the artwork works

@jspizziri jspizziri added Platform: Android Unconfirmed Bugs that have not been confirmed by the core team. labels Sep 20, 2022
@gavrichards
Copy link
Contributor

I've been attempting to debug this.
I've traced the metadata through to KotlinAudio's NotificationManager class.

The notificationMetadata property is set with the artist, title and artworkUrl. If you insert a log here, you can see the values as expected.

That then calls the reload method, which in turn calls the invalidate method on Exoplayer's notification manager.

This is where the trail currently runs cold for me.

If you comment out the call to reload(), you will see the notification no longer updates at all.
Leave the call to reload() in, and only the artwork updates, but not the artist or title.

For anyone looking to replicate, you need to pull this repo and KotlinAudio and set everything up locally as explained in the example project's README.

Then edit PlayerControls.tsx in the example project, to include a way to update metadata, like this:

export const PlayerControls: React.FC = () => {

  const sendMeta = async () => {
    const trackIndex = await TrackPlayer.getCurrentTrack();
    if (trackIndex !== null) {
      const metadata = {
        artist: 'HELLO',
        title: 'WORLD',
        artwork: 'https://is2-ssl.mzstatic.com/image/thumb/Music122/v4/ca/0e/ec/ca0eeccb-eecd-4c72-557d-3d422c6dd1c6/5054197264252.jpg/600x600bb.jpg',
      };

      TrackPlayer.updateMetadataForTrack(trackIndex, metadata);
    }
  };

  return (
    <View style={{ width: '100%' }}>
      <View style={styles.row}>
        <Button
          title="Prev"
          onPress={() => TrackPlayer.skipToPrevious()}
          type="secondary"
        />
        <PlayPauseButton />
        <Button
          title="Next"
          onPress={() => TrackPlayer.skipToNext()}
          type="secondary"
        />
        <Button
            title="Meta"
            onPress={sendMeta}
            type="secondary"
        />
      </View>
    </View>
  );
};

You will note that the notification updates correctly with each track that is played, but when you tap the "Meta" button, only the artwork changes - the artist and title remain as they were.

@jspizziri
Copy link
Collaborator

@mpivchev could use your eyes on this one. I took a high-level look. Not sure why the ExoPlayer invalidate method isn't doing what its supposed to be (at least not entirely).

@gavrichards
Copy link
Contributor

I've stumbled on a fix, but I don't fully understand how/why it works.
It involves this section here.

If you change:

    fun replaceItem(index: Int, item: AudioItem) {
        val mediaSource = getMediaSourceFromAudioItem(item)
        queue[index] = mediaSource

        if (currentIndex == index && automaticallyUpdateNotificationMetadata)
            notificationManager.notificationMetadata = NotificationMetadata(item.title, item.artist, item.artwork)
    }

to:

    fun replaceItem(index: Int, item: AudioItem) {
        val mediaSource = getMediaSourceFromAudioItem(item)
        queue[index] = mediaSource

        if (currentIndex == index && automaticallyUpdateNotificationMetadata) {
            notificationManager.notificationMetadata =
                NotificationMetadata(item.title, item.artist, item.artwork)

            mediaSessionConnector.setMediaMetadataProvider {
                mediaSource.getMediaMetadataCompat()
            }
        }
    }

...then it works.

I discovered this because I noticed how the call to set notificationManager.notificationMetadata in BaseAudioPlayer is followed by a similar snippet (but I was able to simplify it for this fix).

I would definitely appreciate @mpivchev reviewing this.
Particularly how automaticallyUpdateNotificationMetadata is used in both sections I've referenced.

@jspizziri
Copy link
Collaborator

Possibly related to #1653?

@gavrichards if its convenient I'd be curious to see if your fix also fixes the issue above.

@gavrichards
Copy link
Contributor

@jspizziri I'll give it a quick try now.

@mpivchev mpivchev removed their assignment Sep 27, 2022
@jspizziri jspizziri moved this from v3 to In Review in React Native Track Player Sep 27, 2022
@RamProg
Copy link
Author

RamProg commented Oct 7, 2022

I updated to RNTP v3.2 and this issue is still happening.

@gavrichards
Copy link
Contributor

I updated to RNTP v3.2 and this issue is still happening.

The PR doublesymmetry/KotlinAudio#52 hasn't been reviewed yet, so the bug is still present.

@neoassyrian
Copy link

hi, I'm having an issue where the updateMetadataForTrack is not working. I use it when I recieve the song details from a radio live (using icy or icy-headers) inside the "PlaybackMetadataReceived" event

I'm currently on "react-native-track-player": "^3.2.0",

@puckey
Copy link
Collaborator

puckey commented Nov 4, 2022

I was also able to fix this by removing the original mediaSessionConnector.setMediaMetadataProvider call. See doublesymmetry/KotlinAudio@9db93a9

It seems that it was causing exoplayer to update the notification as well. @mpivchev I see you introduced this in the following pr doublesymmetry/KotlinAudio@d2ac459 – perhaps there is a good reason for adding it that I may be missing?

@RamProg
Copy link
Author

RamProg commented Nov 5, 2022

Still happening on 3.2.0-d23c3fb990aaf9d6783881fabe21e059b62b0782

@gianpietro1
Copy link

Hi! I'm also seeing the issue on Android devices & 3.2.0. Any expected version for the review/fix?
Thanks!

@gavrichards
Copy link
Contributor

In the current nightly, artist and title is now working, but the artwork no longer updates, getting stuck on the initial image for the track.

@gianpietro1
Copy link

Not sure if this helps, but I'm not seeing the issue at all in API 28 (ZTE Blade A530 with Android 9)

@DrMickArtisan
Copy link

Hi,
If it can helps, I only view this on android 11 (api 30).
On API 33 it seems to work (but I only try on emulator)

@puckey
Copy link
Collaborator

puckey commented Feb 6, 2023

In the current nightly, artist and title is now working, but the artwork no longer updates, getting stuck on the initial image for the track.

Should be fixed by doublesymmetry/KotlinAudio#59

@jspizziri jspizziri added Dependency An issue caused by one or more project dependencies and removed Unconfirmed Bugs that have not been confirmed by the core team. labels Feb 6, 2023
@jspizziri jspizziri assigned puckey and dcvz and unassigned gavrichards Feb 6, 2023
@jspizziri
Copy link
Collaborator

Now that doublesymmetry/KotlinAudio#59 has been merged we'll need to wait for the build to be available on jitpack.io and then bump the version here https://github.com/doublesymmetry/react-native-track-player/blob/main/android/build.gradle#L52

Any community members interested in creating a PR for that? Should be a chipshot.

@gavrichards
Copy link
Contributor

This is now fixed in nightly, issue can be closed.

@mitchdowney
Copy link
Contributor

mitchdowney commented Mar 6, 2023

I am still running into this issue on Android.

I don't know for sure my problem isn't user error, but I am using the nightly branch, and it seems like KotlinAudio 2.0.0-rc3 is installed (I'm not 100% sure how to check this but I see it in the RNTP build.gradle).

The image on the lockscreen stays whatever the image was that first loaded for the track.

I call await PVAudioPlayer.updateMetadataForTrack(currentIndex, newTrack) and the new track has different artwork URLs (and open the URL in a browser to verify the images are different), yet the lock screen stays the same image.

@tewson
Copy link

tewson commented Aug 1, 2023

This issue was fixed in 4.0.0-rc05 but seems to have come back in 4.0.0-rc06.

@gavrichards
Copy link
Contributor

I can confirm we're seeing this regression too, after updating from 4.0.0-rc04 to 4.0.0-rc06.

@puckey puckey reopened this Aug 2, 2023
@puckey
Copy link
Collaborator

puckey commented Aug 10, 2023

So I think we also need to update the tag of the exoplayer media item here: https://github.com/doublesymmetry/KotlinAudio/blob/main/kotlin-audio/src/main/java/com/doublesymmetry/kotlinaudio/players/QueuedAudioPlayer.kt#L217

Will be able to look into it early September

@dcvz
Copy link
Contributor

dcvz commented Aug 10, 2023

There's a fix for this ongoing here: doublesymmetry/KotlinAudio#87. I'll update this thread when that's done.

@dcvz
Copy link
Contributor

dcvz commented Aug 10, 2023

This should be fixed now in v4.0.0.0-rc07

@dcvz dcvz closed this as completed Sep 22, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Dependency An issue caused by one or more project dependencies Platform: Android
Projects
Development

Successfully merging a pull request may close this issue.