fix: send last position for Stopped event
instead of the current position, which is `0` when we move to a new track
This commit is contained in:
@@ -17,11 +17,12 @@ const RepeatModeMap: Record<RepeatMode, string> = {
|
||||
*/
|
||||
export async function sendPlaybackEvent(
|
||||
path: string,
|
||||
track?: Track
|
||||
track?: Track,
|
||||
lastPosition?: number,
|
||||
) {
|
||||
// Extract all data from react-native-track-player
|
||||
const [
|
||||
activeTrack, { position }, repeatMode, volume, { state },
|
||||
activeTrack, { position: currentPosition }, repeatMode, volume, { state },
|
||||
] = await Promise.all([
|
||||
track || TrackPlayer.getActiveTrack(),
|
||||
TrackPlayer.getProgress(),
|
||||
@@ -37,7 +38,7 @@ export async function sendPlaybackEvent(
|
||||
IsPaused: state === State.Paused,
|
||||
RepeatMode: RepeatModeMap[repeatMode],
|
||||
ShuffleMode: 'Sorted',
|
||||
PositionTicks: Math.round(position * 10_000_000),
|
||||
PositionTicks: Math.round((lastPosition || currentPosition) * 10_000_000),
|
||||
PlaybackRate: 1,
|
||||
PlayMethod: 'transcode',
|
||||
MediaSourceId: activeTrack?.backendId || null,
|
||||
|
||||
@@ -45,7 +45,7 @@ export default async function() {
|
||||
if (settings.enablePlaybackReporting && 'track' in e) {
|
||||
// GUARD: End the previous track if it's about to end
|
||||
if (e.lastTrack) {
|
||||
await sendPlaybackEvent('/Sessions/Playing/Stopped', e.lastTrack);
|
||||
await sendPlaybackEvent('/Sessions/Playing/Stopped', e.lastTrack, e.lastPosition);
|
||||
}
|
||||
|
||||
await sendPlaybackEvent('/Sessions/Playing', e.track);
|
||||
|
||||
Reference in New Issue
Block a user