mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-12-06 15:39:41 +00:00
fix: scrobbling not working for first track or single track
This commit is contained in:
parent
e29a38dfa4
commit
0a6b54da36
@ -213,6 +213,26 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
|||||||
Catcher2.reportCheckedError(e, stackTrace);
|
Catcher2.reportCheckedError(e, stackTrace);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
String? lastScrobbled;
|
||||||
|
audioPlayer.positionStream.listen((position) {
|
||||||
|
try {
|
||||||
|
final uid = state.activeTrack is LocalTrack
|
||||||
|
? (state.activeTrack as LocalTrack).path
|
||||||
|
: state.activeTrack?.id;
|
||||||
|
|
||||||
|
if (state.activeTrack == null ||
|
||||||
|
lastScrobbled == uid ||
|
||||||
|
position.inSeconds < 30) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
scrobbler.scrobble(state.activeTrack!);
|
||||||
|
lastScrobbled = uid;
|
||||||
|
} catch (e, stack) {
|
||||||
|
Catcher2.reportCheckedError(e, stack);
|
||||||
|
}
|
||||||
|
});
|
||||||
}();
|
}();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -609,30 +629,12 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
set state(state) {
|
set state(state) {
|
||||||
final hasActiveTrackChanged = super.state.activeTrack is SpotubeTrack
|
|
||||||
? state.activeTrack?.id != super.state.activeTrack?.id
|
|
||||||
: super.state.activeTrack is LocalTrack &&
|
|
||||||
state.activeTrack is LocalTrack
|
|
||||||
? (super.state.activeTrack as LocalTrack).path !=
|
|
||||||
(state.activeTrack as LocalTrack).path
|
|
||||||
: super.state.activeTrack?.id != state.activeTrack?.id;
|
|
||||||
|
|
||||||
final oldTrack = super.state.activeTrack;
|
|
||||||
|
|
||||||
super.state = state;
|
super.state = state;
|
||||||
if (state.tracks.isEmpty && ref.read(paletteProvider) != null) {
|
if (state.tracks.isEmpty && ref.read(paletteProvider) != null) {
|
||||||
ref.read(paletteProvider.notifier).state = null;
|
ref.read(paletteProvider.notifier).state = null;
|
||||||
} else {
|
} else {
|
||||||
updatePalette();
|
updatePalette();
|
||||||
}
|
}
|
||||||
audioPlayer.position.then((position) {
|
|
||||||
final isMoreThan30secs = position != null &&
|
|
||||||
(position == Duration.zero || position.inSeconds > 30);
|
|
||||||
|
|
||||||
if (hasActiveTrackChanged && oldTrack != null && isMoreThan30secs) {
|
|
||||||
scrobbler.scrobble(oldTrack);
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user