feat: now playing metadata changed hook and event #2250
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Resolves #2158.
Added
nowPlayingMetadata
hook,getNowPlayingMetadata
getter andNowPlayingMetadataChanged
event.Reflect these changes in
updateMetadataForTrack
(when it's the active track) andclearNowPlayingMetadata
for time before deprecation.useActiveTrack()
stays intact, as David suggested in issue, I've done changes as per his recommendations, implementing new event, getter and hook, independently ofuseActiveTrack
.activeTrack
event, getter and hook do not provide now playing metadata information - if users would ever changemetadata of track that is currently playing, there would be no update to it
MetadataTimedReceived
event is emitted. But, if user would unmount the screen and then come back to it, now playing metadata is not accessible, until newMetadataTimedReceived
event is emitted - when song on the radio stream changesHow it works
updateNowPlayingMetadata
, orupdateMetadataForTrack
, if it's active track, is called, new metadata is saved into private var insideMusicService
/RNTrackPlayer
andNowPlayingMetadataChanged
event is emitted.clearNowPlayingMetadata
reflects these changes accordingly, until it'll be deprecated as announcedgetNowPlayingMetadata
returns that variable's value, last stored metadatauseNowPlayingMetadata
fetches that variable's value on mount, saves it into state. Every timeNowPlayingMetadataChanged
is emitted, it updates the internal state with new metadata. Hook returns metadataNowPlayingMetadataChanged
is subscribable, event returnsmetadata
objectTesting
Screenshots
Note that artwork gets updated randomly, and because notification metadata and our
nowPlayingMetadata
update at at different time, they're not the same.Note
@dcvz
I've just noticed that notification metadata is "patched", instead of replaced.
E.g., if we update now playing metadata, or metadata for active track, it'll keep old metadata values for any undefined values in object we're updating with.
I'm not sure if this should be the case, I'd expect users to be able to override notification data completely.
nowPlayingMetadata
is replaced completely with new values, even if they're undefined.