doublesymmetry / react-native-track-player

A fully fledged audio module created for music apps. Provides audio playback, external media controls, background mode and more!
https://rntp.dev/
Apache License 2.0
3.25k stars 1k forks source link

feat: now playing metadata changed hook and event #2250

Closed tomislav-arambasic closed 3 months ago

tomislav-arambasic commented 7 months ago

Summary

Resolves https://github.com/doublesymmetry/react-native-track-player/issues/2158.

Added nowPlayingMetadata hook, getNowPlayingMetadata getter and NowPlayingMetadataChanged event. Reflect these changes in updateMetadataForTrack (when it's the active track) and clearNowPlayingMetadata 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 of useActiveTrack.

How it works

Testing

Screenshots

Note that artwork gets updated randomly, and because notification metadata and our nowPlayingMetadata update at at different time, they're not the same.

Now playing metadata updated on "Update Notification Metadata Randomly" action Now playing metadata updated on "Update Current Track Metadata Randomly" action
iOS
Android
Now playing metadata updated for each track via PlaybackService
iOS
Android

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.

dcvz commented 7 months ago

Thanks for taking the time @tomislav-arambasic ! As you saw there's been some conversation on the other thread around options and possibilities.

I'll review this PR later this week!

dcvz commented 6 months ago

Sorry for the delay here! I'm hoping to go through this soon

github-actions[bot] commented 3 months ago

This PR is stale because it has been open 90 days with no activity. Remove stale label or comment or this will be closed in 7 days.

github-actions[bot] commented 3 months ago

This PR was closed because it has been stalled for 7 days with no activity.

tomislav-arambasic commented 3 months ago

@dcvz Not rushing anything, I've just noticed it got auto-closed and I thought you might be interested in feature :)