mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix: tracks doesn't change when ended
This commit is contained in:
parent
e3f4344ae9
commit
aa4ac8641a
@ -1,7 +1,6 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:async/async.dart';
|
||||
import 'package:catcher/catcher.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
@ -72,6 +71,7 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
({String source, List<SkipSegment> segments})? currentSegments;
|
||||
|
||||
audioPlayer.activeSourceChangedStream.listen((newActiveSource) async {
|
||||
try {
|
||||
final newActiveTrack =
|
||||
mapSourcesToTracks([newActiveSource]).firstOrNull;
|
||||
|
||||
@ -88,9 +88,13 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
);
|
||||
|
||||
updatePalette();
|
||||
} catch (e, stackTrace) {
|
||||
Catcher.reportCheckedError(e, stackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
audioPlayer.shuffledStream.listen((event) {
|
||||
try {
|
||||
final newlyOrderedTracks = mapSourcesToTracks(audioPlayer.sources);
|
||||
|
||||
final newActiveIndex = newlyOrderedTracks.indexWhere(
|
||||
@ -103,6 +107,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
tracks: newlyOrderedTracks.toSet(),
|
||||
active: newActiveIndex,
|
||||
);
|
||||
} catch (e, stackTrace) {
|
||||
Catcher.reportCheckedError(e, stackTrace);
|
||||
}
|
||||
});
|
||||
|
||||
bool isPreSearching = false;
|
||||
@ -130,6 +137,8 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
track,
|
||||
);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
Catcher.reportCheckedError(e, stackTrace);
|
||||
} finally {
|
||||
isPreSearching = false;
|
||||
}
|
||||
@ -140,6 +149,11 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
bool isFetchingSegments = false;
|
||||
|
||||
audioPlayer.positionStream.listen((position) async {
|
||||
try {
|
||||
if (state.activeTrack == null || state.activeTrack is LocalTrack) {
|
||||
isFetchingSegments = false;
|
||||
return;
|
||||
}
|
||||
// skipping in very first second breaks stream
|
||||
if ((preferences.youtubeApiType == YoutubeApiType.piped &&
|
||||
preferences.searchMode == SearchMode.youtubeMusic) ||
|
||||
@ -172,6 +186,9 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
await audioPlayer.seek(Duration(seconds: segment.end));
|
||||
}
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
Catcher.reportCheckedError(e, stackTrace);
|
||||
}
|
||||
});
|
||||
}();
|
||||
}
|
||||
|
@ -20,7 +20,7 @@ abstract class AudioPlayerInterface {
|
||||
// _mkPlayer = _mkSupportedPlatform ? MkPlayerWithState() : null,
|
||||
// _justAudio = !_mkSupportedPlatform ? ja.AudioPlayer() : null
|
||||
{
|
||||
_mkPlayer.streams.error.listen((event) {
|
||||
_mkPlayer.stream.error.listen((event) {
|
||||
Catcher.reportCheckedError(event, StackTrace.current);
|
||||
});
|
||||
}
|
||||
|
@ -4,7 +4,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
// stream getters
|
||||
Stream<Duration> get durationStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
return _mkPlayer.streams.duration;
|
||||
return _mkPlayer.stream.duration;
|
||||
// } else {
|
||||
// return _justAudio!.durationStream
|
||||
// .where((event) => event != null)
|
||||
@ -15,7 +15,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
|
||||
Stream<Duration> get positionStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
return _mkPlayer.streams.position;
|
||||
return _mkPlayer.stream.position;
|
||||
// } else {
|
||||
// return _justAudio!.positionStream;
|
||||
// }
|
||||
@ -24,7 +24,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
Stream<Duration> get bufferedPositionStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
// audioplayers doesn't have the capability to get buffered position
|
||||
return _mkPlayer.streams.buffer;
|
||||
return _mkPlayer.stream.buffer;
|
||||
// } else {
|
||||
// return _justAudio!.bufferedPositionStream;
|
||||
// }
|
||||
@ -32,7 +32,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
|
||||
Stream<void> get completedStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
return _mkPlayer.streams.completed;
|
||||
return _mkPlayer.stream.completed;
|
||||
// } else {
|
||||
// return _justAudio!.playerStateStream
|
||||
// .where(
|
||||
@ -57,7 +57,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
|
||||
Stream<bool> get playingStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
return _mkPlayer.streams.playing;
|
||||
return _mkPlayer.stream.playing;
|
||||
// } else {
|
||||
// return _justAudio!.playingStream;
|
||||
// }
|
||||
@ -83,7 +83,7 @@ mixin SpotubeAudioPlayersStreams on AudioPlayerInterface {
|
||||
|
||||
Stream<double> get volumeStream {
|
||||
// if (mkSupportedPlatform) {
|
||||
return _mkPlayer.streams.volume.map((event) => event / 100);
|
||||
return _mkPlayer.stream.volume.map((event) => event / 100);
|
||||
// } else {
|
||||
// return _justAudio!.volumeStream;
|
||||
// }
|
||||
|
@ -1,5 +1,6 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:catcher/catcher.dart';
|
||||
import 'package:collection/collection.dart';
|
||||
import 'package:media_kit/media_kit.dart';
|
||||
// ignore: implementation_imports
|
||||
@ -30,22 +31,20 @@ class MkPlayerWithState extends Player {
|
||||
_shuffled = false,
|
||||
_loopMode = PlaylistMode.none {
|
||||
_subscriptions = [
|
||||
streams.buffering.listen((event) {
|
||||
stream.buffering.listen((event) {
|
||||
_playerStateStream.add(AudioPlaybackState.buffering);
|
||||
}),
|
||||
streams.playing.listen((playing) {
|
||||
stream.playing.listen((playing) {
|
||||
if (playing) {
|
||||
_playerStateStream.add(AudioPlaybackState.playing);
|
||||
} else {
|
||||
_playerStateStream.add(AudioPlaybackState.paused);
|
||||
}
|
||||
}),
|
||||
streams.position.listen((position) async {
|
||||
final isComplete = state.duration != Duration.zero &&
|
||||
position != Duration.zero &&
|
||||
state.duration.inSeconds == position.inSeconds;
|
||||
stream.completed.listen((isCompleted) async {
|
||||
try {
|
||||
if (!isCompleted) return;
|
||||
|
||||
if (!isComplete || _playlist == null) return;
|
||||
_playerStateStream.add(AudioPlaybackState.completed);
|
||||
|
||||
if (loopMode == PlaylistMode.single) {
|
||||
@ -54,12 +53,18 @@ class MkPlayerWithState extends Player {
|
||||
await next();
|
||||
await Future.delayed(const Duration(milliseconds: 250), play);
|
||||
}
|
||||
} catch (e, stackTrace) {
|
||||
Catcher.reportCheckedError(e, stackTrace);
|
||||
}
|
||||
}),
|
||||
streams.playlist.listen((event) {
|
||||
stream.playlist.listen((event) {
|
||||
if (event.medias.isEmpty) {
|
||||
_playerStateStream.add(AudioPlaybackState.stopped);
|
||||
}
|
||||
}),
|
||||
stream.error.listen((event) {
|
||||
Catcher.reportCheckedError('[MediaKitError] \n$event', null);
|
||||
}),
|
||||
];
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user