Giter Site home page Giter Site logo

Comments (13)

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024 1

@Vashiru Because you are firing the command every few seconds and the artist and title did not change yet.

You could first check if the artist and title ar not the same as the values the activeTrack already have. If they are the same, do nothing. If they are not the same, then update the values.

   const activeTrack = await TrackPlayer.getActiveTrack();

    if (activeTrack?.title != obj?.songtitle) {

          TrackPlayer.updateMetadataForTrack(currentTrack, {
            title: obj.songtitle,
            artwork: require('./assets/afterhours-fm.jpg'),
          });

     } else {
      console.log("Not updating metadata yet");

   }
  }

Something like that. That's how I worked around this problem.

from react-native-track-player.

Vashiru avatar Vashiru commented on June 12, 2024 1

I think I've found a workaround just now:

If I call both updateMetadataForTrack and updateNowPlayingMetadata, my artwork will actually stay:

TrackPlayer.updateMetadataForTrack(currentTrack, {
  title: obj.songtitle,
  artwork: require('./assets/afterhours-fm.jpg'),
});
TrackPlayer.updateNowPlayingMetadata({
  title: obj.songtitle,
  artwork: require('./assets/afterhours-fm.jpg'),
});

Edit: but adding your code in as an optimization is probably a good idea.

Edit2: The issue is specifically in updateMetadataForTrack, if I don't set artwork there, but always call it in updateNowPlayingMetadata, it doesn't disappear either.

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on June 12, 2024

i can see this in example by just commenting out title and duration in onUpdateCurrentTrackMetadata(). it only messes up when replacing currentIndex Tracks.
though I dont see the same behavior for onUpdateNotificationMetadata() though, so my suggestion is check TP.currentIndex and use updateNowPlayingMetadata if === current index. otherwise I can do this in the js TP module, unless someone wants to try figuring this out in KA
i see one uses
notificationManager.overrideAudioItem = overrideAudioItem
the other uses
player.notificationManager.overrideMetadata(track.toAudioItem())
which should be the same thing

from react-native-track-player.

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024

Thanks, @lovegaoshi , I will try that tomorrow. Although I am not sure how to get the TP.currentIndex? What is the function I should use for that? :)

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on June 12, 2024

from react-native-track-player.

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024

@lovegaoshi Unfortunately, both functions render the same issue.

This is the code I have used

      TrackPlayer.updateNowPlayingMetadata({
        artist: streamValues.song_artist,
        title: streamValues.song_title,
        artwork: streamValues.song_artwork,
      });

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on June 12, 2024

well, i actually dont see any problem on my end if artist and title are also set. so you're probably looking at a different issue than what i observed, unless you have a repo from the example i'm at a dead end.
my repo for the bug i described:
https://github.com/lovegaoshi/react-native-track-player/tree/bug-notif-artwork

from react-native-track-player.

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024

Hi @lovegaoshi, yes. We tried this before. You can change the title to ‘foo’, and the artist to ‘foo’, too.

If these fields stay the same, the artwork blanks out. When title and artist are regenerated, there’s no problem. What comes to my mind for now is making a workaround that checks if the new info is the same as the old info, before invoking the updateMetadata command.

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on June 12, 2024

hmm. still cant reproduce. see if that repo above bugs on your end.

from react-native-track-player.

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024

So, for now I have worked my way around this issue, by reading the previous issue once again.

Still needs to be solved, but at least I can work around it now.

from react-native-track-player.

lovegaoshi avatar lovegaoshi commented on June 12, 2024

from react-native-track-player.

DennisdeWitNL avatar DennisdeWitNL commented on June 12, 2024

are you sure you are running tje example app following tje instructions in that folder?

On Thu, Apr 4, 2024, 12:38 AM DennisdeWitNL @.> wrote: So, for now I have worked my way around with this code: const updateMetadata = async (streamValues) => { const activeTrack = await TrackPlayer.getActiveTrack(); if (activeTrack?.artist != streamValues.artist && activeTrack?.title != streamValues.title) { console.log("Updating metadata") const currentTrack = await TrackPlayer.getActiveTrackIndex(); if (currentTrack == null) { // getStreamInfoAndTriggerInitTrackPlayer(); } else { TrackPlayer.updateMetadataForTrack(currentTrack, { artist: streamValues.artist, title: streamValues.title, artwork: streamValues.artwork, }); } } else { console.log("doing nothing") } } It seems it clears out the artwork when the title and artist are still the same. So I will only update the metadata when all new info is available. That works fine. :) Still needs to be solved, but at least I can work around it now. — Reply to this email directly, view it on GitHub <#2287 (comment)>, or unsubscribe https://github.com/notifications/unsubscribe-auth/AZMOVVUASIQ55SYJTE5ZHP3Y3T7OTAVCNFSM6AAAAABFVUZR4WVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDAMZWGQYTENJSGI . You are receiving this because you were mentioned.Message ID: @. com>

Will check tomorrow. I have had a busy evening, sorry. For my info: did you change something ‘under the hood’ of RNTP that might be on influence of the bug?

from react-native-track-player.

Vashiru avatar Vashiru commented on June 12, 2024

Having the same issue as Dennis using a local file:

const fetchMetadata = async () => {
  await fetch('https://fr2.ah.fm/stats?sid=1&json=1')
    .then(data => data.json())
    .then(async obj => {
      if (obj.songtitle && typeof obj.songtitle === 'string') {
        const currentTrack = await TrackPlayer.getActiveTrackIndex();
        if (currentTrack !== undefined) {
          TrackPlayer.updateMetadataForTrack(currentTrack, {
            title: obj.songtitle,
            artwork: require('./assets/afterhours-fm.jpg'),
          });
        }
      }
    })
    .catch(function (error) {
      console.log(error);
    });
};

This is being ran every 5 seconds through:

  useEffect(() => {
    const intervalId = setInterval(() => fetchMetadata(), 5000);

    return () => clearInterval(intervalId);
  }, []);

Initially the artwork will load, but as soon as updateMetadataForTrack gets called again, the image disappears.

from react-native-track-player.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.