jmshrv / finamp

A Jellyfin music client for mobile
Mozilla Public License 2.0
1.87k stars 124 forks source link

Last.fm scrobbling is broken on Linux #908

Open vimproved opened 1 day ago

vimproved commented 1 day ago

On Linux (flatpak), it seems like Finamp never properly reports a track as completed to the server. While playing a track, it correctly shows up in last.fm as "playing", however it never gets scrobbled properly. Just from a surface-level inspection, I think this stems from the same base issue as #907, which is that the playbackState never gets properly updated to AudioProcessingState.completed, which is evidenced by the fact that in the logs, PlaybackHistoryService doesn't log a "Stopping playback progress" message when a track is completed, and it instead logs an "Updating playback state" message and just repeats from the beginning of the queue immediately.

vimproved commented 1 day ago

Going a bit further, I think this may actually be an issue in just_audio_media_kit. This is just a theory, so tell me if I'm wildly off base though since I have no experience with flutter.

Whenever something is queued up in Finamp, it throws this error in the console:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: RangeError (length): Invalid value: Valid value range is empty: 0
#0      _Array.[] (dart:core-patch/array.dart)
#1      MediaKitPlayer._currentMedia (package:just_audio_media_kit/mediakit_player.dart:39)
#2      new MediaKitPlayer.<anonymous closure> (package:just_audio_media_kit/mediakit_player.dart:60)
#3      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594)
#4      _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365)
#5      _BufferingStreamSubscription._add (dart:async/stream_impl.dart:297)
#6      _ForwardingStreamSubscription._add (dart:async/stream_pipe.dart:123)
#7      _DistinctStream._handleData (dart:async/stream_pipe.dart:439)
#8      _ForwardingStreamSubscription._handleData (dart:async/stream_pipe.dart:153)
#9      _RootZone.runUnaryGuarded (dart:async/zone.dart:1594)
#10     _BufferingStreamSubscription._sendData (dart:async/stream_impl.dart:365)
#11     _DelayedData.perform (dart:async/stream_impl.dart:541)
#12     _PendingEvents.handleNext (dart:async/stream_impl.dart:646)
#13     _PendingEvents.schedule.<anonymous closure> (dart:async/stream_impl.dart:617)
#14     _microtaskLoop (dart:async/schedule_microtask.dart:40)
#15     _startMicrotaskLoop (dart:async/schedule_microtask.dart:49)

The relevant snippet from just_audio_media_kit is

Media get _currentMedia =>
      _player.state.playlist.medias[_player.state.playlist.index];

This is making me think that the playlist is not getting initialized properly, and that's causing just_audio_media_kit to not properly send out the completed event. I'm wondering if https://github.com/Pato05/just_audio_media_kit/pull/17 would maybe fix this (unfortunately I don't have the means to test this myself).