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(
|
export async function sendPlaybackEvent(
|
||||||
path: string,
|
path: string,
|
||||||
track?: Track
|
track?: Track,
|
||||||
|
lastPosition?: number,
|
||||||
) {
|
) {
|
||||||
// Extract all data from react-native-track-player
|
// Extract all data from react-native-track-player
|
||||||
const [
|
const [
|
||||||
activeTrack, { position }, repeatMode, volume, { state },
|
activeTrack, { position: currentPosition }, repeatMode, volume, { state },
|
||||||
] = await Promise.all([
|
] = await Promise.all([
|
||||||
track || TrackPlayer.getActiveTrack(),
|
track || TrackPlayer.getActiveTrack(),
|
||||||
TrackPlayer.getProgress(),
|
TrackPlayer.getProgress(),
|
||||||
@@ -37,7 +38,7 @@ export async function sendPlaybackEvent(
|
|||||||
IsPaused: state === State.Paused,
|
IsPaused: state === State.Paused,
|
||||||
RepeatMode: RepeatModeMap[repeatMode],
|
RepeatMode: RepeatModeMap[repeatMode],
|
||||||
ShuffleMode: 'Sorted',
|
ShuffleMode: 'Sorted',
|
||||||
PositionTicks: Math.round(position * 10_000_000),
|
PositionTicks: Math.round((lastPosition || currentPosition) * 10_000_000),
|
||||||
PlaybackRate: 1,
|
PlaybackRate: 1,
|
||||||
PlayMethod: 'transcode',
|
PlayMethod: 'transcode',
|
||||||
MediaSourceId: activeTrack?.backendId || null,
|
MediaSourceId: activeTrack?.backendId || null,
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ export default async function() {
|
|||||||
if (settings.enablePlaybackReporting && 'track' in e) {
|
if (settings.enablePlaybackReporting && 'track' in e) {
|
||||||
// GUARD: End the previous track if it's about to end
|
// GUARD: End the previous track if it's about to end
|
||||||
if (e.lastTrack) {
|
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);
|
await sendPlaybackEvent('/Sessions/Playing', e.track);
|
||||||
|
|||||||
Reference in New Issue
Block a user