mirror of
https://github.com/KRTirtho/spotube.git
synced 2025-09-13 07:55:18 +00:00
fix: cached currently playing track infinite loading
This commit is contained in:
parent
957c085e12
commit
94017189c6
@ -15,6 +15,7 @@ import 'package:spotube/provider/proxy_playlist/proxy_playlist.dart';
|
||||
import 'package:spotube/provider/user_preferences_provider.dart';
|
||||
import 'package:spotube/services/audio_player/audio_player.dart';
|
||||
import 'package:spotube/services/audio_services/audio_services.dart';
|
||||
import 'package:spotube/services/youtube.dart';
|
||||
import 'package:spotube/utils/persisted_state_notifier.dart';
|
||||
import 'package:spotube/utils/type_conversion_utils.dart';
|
||||
|
||||
@ -215,29 +216,35 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
int initialIndex = 0,
|
||||
bool autoPlay = false,
|
||||
}) async {
|
||||
tracks = blacklist.filter(tracks).toList() as List<Track>;
|
||||
final addableTrack = await SpotubeTrack.fetchFromTrack(
|
||||
tracks.elementAt(initialIndex),
|
||||
preferences,
|
||||
);
|
||||
try {
|
||||
tracks = blacklist.filter(tracks).toList() as List<Track>;
|
||||
final addableTrack = await SpotubeTrack.fetchFromTrack(
|
||||
tracks.elementAt(initialIndex),
|
||||
preferences,
|
||||
);
|
||||
|
||||
state = state.copyWith(
|
||||
tracks: mergeTracks([addableTrack], tracks),
|
||||
active: initialIndex,
|
||||
);
|
||||
print('addableTrack: $addableTrack');
|
||||
|
||||
await notificationService.addTrack(addableTrack);
|
||||
state = state.copyWith(
|
||||
tracks: mergeTracks([addableTrack], tracks),
|
||||
active: initialIndex,
|
||||
);
|
||||
|
||||
await audioPlayer.openPlaylist(
|
||||
state.tracks.map(makeAppropriateSource).toList(),
|
||||
initialIndex: initialIndex,
|
||||
autoPlay: autoPlay,
|
||||
);
|
||||
await notificationService.addTrack(addableTrack);
|
||||
|
||||
await storeTrack(
|
||||
tracks.elementAt(initialIndex),
|
||||
addableTrack,
|
||||
);
|
||||
await audioPlayer.openPlaylist(
|
||||
state.tracks.map(makeAppropriateSource).toList(),
|
||||
initialIndex: initialIndex,
|
||||
autoPlay: autoPlay,
|
||||
);
|
||||
|
||||
await storeTrack(
|
||||
tracks.elementAt(initialIndex),
|
||||
addableTrack,
|
||||
);
|
||||
} catch (e) {
|
||||
print('Error: $e');
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> jumpTo(int index) async {
|
||||
@ -404,14 +411,16 @@ class ProxyPlaylistNotifier extends PersistedStateNotifier<ProxyPlaylist>
|
||||
}
|
||||
|
||||
@override
|
||||
onInit() {
|
||||
onInit() async {
|
||||
if (state.tracks.isEmpty) return null;
|
||||
|
||||
return load(
|
||||
state.tracks,
|
||||
initialIndex: state.active ?? 0,
|
||||
autoPlay: false,
|
||||
);
|
||||
if (await PipedSpotube.initialized) {
|
||||
await load(
|
||||
state.tracks,
|
||||
initialIndex: state.active ?? 0,
|
||||
autoPlay: false,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
|
@ -1,8 +1,13 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:piped_client/piped_client.dart';
|
||||
|
||||
PipedClient _defaultClient = PipedClient();
|
||||
|
||||
class PipedSpotube {
|
||||
static final Completer<bool> _initialized = Completer();
|
||||
static Future<bool> get initialized => _initialized.future;
|
||||
|
||||
/// Checks for a working instance of piped.video
|
||||
///
|
||||
/// To distribute the load, in each startup it randomizes public instances
|
||||
@ -15,6 +20,7 @@ class PipedSpotube {
|
||||
try {
|
||||
await client.streams("dQw4w9WgXcQ");
|
||||
_defaultClient = client;
|
||||
_initialized.complete(true);
|
||||
break;
|
||||
} catch (e) {
|
||||
continue;
|
||||
|
Loading…
Reference in New Issue
Block a user