tanguyantoine / react-native-music-control

Display and manage media controls on lock screen and notification center for iOS and Android.
https://www.npmjs.com/package/react-native-music-control
MIT License
697 stars 264 forks source link

Unable to update duration (live stream use case) #390

Open scottg489-tw opened 3 years ago

scottg489-tw commented 3 years ago

Description

We have a live stream which has a dynamic duration. As the stream plays and we receive more stream data, the duration progresses forward and we would like to update the duration in the notification screen. However, MusicControl.updatePlayback does not seem to support supplying a duration.

We attempted to work around this by calling MusicControl.setNowPlaying with the new duration when the duration changes. However, on iPhone this causes the elapsed time to jump to 0 seconds briefly and then back to the correct elapsed time even though we call updatePlayback with the elapsed time right after. This somewhat makes sense because it doesn't seem like setNowPlaying should be used to do updates.

It would seem that to correct this issue MusicControl.updatePlayback needs to be updated to accept duration as a parameter. Is this correct or is there existing functionality that would support our use case?

Example code

componentDidUpdate(prevProps) {
  MediaControl.setNowPlaying({
    title: 'Some title',
    artist: 'Some artist',
    duration: this.props.duration,
  });
  MediaControl.updatePlayback({ elapsedTime: props.time });
}

We are calling setNowPlaying with the new duration which updates the duration to the appropriate time but also sets the elapsed time to 0. We then immediately call updatePlayback to update the elapsed time to the correct time. This seems hacky and likely not how the library should be used, and although it works on Android it unfortunately does not work on iPhone.

Platform

Device