Comments (13)
@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.
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.
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.
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.
from react-native-track-player.
@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.
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.
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.
hmm. still cant reproduce. see if that repo above bugs on your end.
from react-native-track-player.
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.
from react-native-track-player.
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.
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)
- [Feature Request] Channel splitting and merging with volume control. HOT 1
- The buffer plays after waiting 20 seconds. HOT 4
- How to use in Web? HOT 1
- RNTP module not loading properly with NextJS / Solito HOT 3
- iOS audio cutting out randomly during live stream HOT 2
- One or more of the events provided to useTrackPlayerEvents is not a valid TrackPlayer event HOT 2
- HSL audio playing issue in android HOT 4
- [Feature Request] Add back a Status that lets us distinguish between the two types of buffering — Play Buffering vs Paused Buffering HOT 4
- Equalizer Integration HOT 1
- [4.0.1] Crash: com.doublesymmetry.trackplayer.service.MusicService.startAndStopEmptyNotificationToAvoidANR HOT 1
- Cannot invoke method toInteger() on null object HOT 5
- TrackPlayer.getProgress() does not return duration on ios HOT 2
- [Feature Request] Support playing files from bundle without require or import HOT 1
- [Feature Request] Auto retry policy on iOS on error
- [iOS] Stream error on specific audio HOT 6
- [Feature Request] How to embed ads in a song HOT 1
- Notification Player not show on lock-screen HOT 4
- Duplicate value for resource 'attr/show_buffering' with config 'DEFAULT' and product '' HOT 1
- Duplicate actions in notification controller on Android 13+
- seekTo not working with slider HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from react-native-track-player.