-
Notifications
You must be signed in to change notification settings - Fork 29
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Shuffle like VLC App #6
Comments
I recently saw this in the docs for
Can you try setting |
@suragch |
@suragch I am gonna close this for now. |
I'm reopening this until I can fix the tutorial. Thank you for your comments. |
@suragch |
@suragch |
@suragch class MediaLibrary {
static const albumsRootId = 'albums';
final items = <String, List<MediaItem>>{
AudioService.browsableRootId: const [MediaItem(id: albumsRootId, title: "Albums", playable: false)],
albumsRootId: [
MediaItem( // <--- I need to include these MediaItem using a function like in PlaylistRepository
id: 'https://s3.amazonaws.com/scifri-episodes/scifri20181123-episode.mp3',
album: "Science Monday",
title: "I can do it",
artist: "Science Friday and WNYC Studios",
duration: const Duration(milliseconds: 5739820),
artUri: Uri.parse('https://media.wnyc.org/i/1400/1400/l/80/1/ScienceFriday_WNYCStudios_1400.jpg'),
),
],
};
} |
No need. I found this as the best solution: class MediaLibrary {
static const albumsRootId = 'albums';
final audioHandler = getIt<AudioHandler>();
int status = -1;
late final Map<String, List<MediaItem>> items; // <-- I declared it here as late variable
List<MediaItem> mediaItems = [];
void init() async {
await loadPlaylist();
}
Future<List<MediaItem>> loadPlaylist() async {
final songRepository = getIt<PlaylistRepository>();
final playlistData = await songRepository.fetchInitialPlaylist();
audioHandler.queue.listen((playlist) async {
int lengthX = playlist.length;
if (lengthX > 0) {
status = 1;
} else if (lengthX == 0) {
status = 0;
}
});
if (status == 0) {
mediaItems = playlistData
.map((song) => MediaItem(
id: song['id'],
album: song['album'],
title: song['title'],
artist: song['artist'],
extras: {'url': song['url']},
))
.toList();
items = {
AudioService.browsableRootId: const [
MediaItem(
id: albumsRootId,
title: "Albums",
playable: false,
),
],
albumsRootId: mediaItems, //I added here the variable of List<MediaItem>, problem solved.
};
audioHandler.updateQueue(mediaItems);
log("List of all indexes in first mediaItems");
for (int i = 0; i < mediaItems.length; i++) {
log("[$i] ${mediaItems[i].title}");
}
} else if (status == 1) {
mediaItems = playlistData
.map((song) => MediaItem(
id: song['id'],
album: song['album'],
title: song['title'],
artist: song['artist'],
extras: {'url': song['url']},
))
.toList();
items = {
AudioService.browsableRootId: const [
MediaItem(
id: albumsRootId,
title: "Albums",
playable: false,
),
],
albumsRootId: mediaItems,
};
audioHandler.updateQueue(mediaItems);
log("List of all indexes in first mediaItems");
for (int i = 0; i < mediaItems.length; i++) {
log("[$i] ${mediaItems[i].title}");
}
}
return mediaItems;
}
} |
Thanks for all your comments. I'm still planning to update the tutorial but haven't gotten around to it. |
Hello,
I found out that just_audio shuffle method only made a random indexes of current playlist for once only. Meanwhile, in VLC app, it doesn't work that way. If we press Shuffle inside the app, and press Next, then the next song will jump into another index. It doesn't change the order of playlist.
Is there anyone who knows how to implement shuffle to work like VLC app?
Any tips and guidance will be a great help.
Thanks.
The text was updated successfully, but these errors were encountered: