Add "Play mix" button in player
This commit is contained in:
parent
df3b7d3d63
commit
8ea510ac5b
|
@ -430,5 +430,13 @@ class DeezerAPI {
|
|||
});
|
||||
return data['results']['data'].map<Track>((t) => Track.fromPrivateJson(t)).toList();
|
||||
}
|
||||
|
||||
// Get similar tracks for track with id [trackId]
|
||||
Future<List<Track>> playMix(String trackId) async {
|
||||
Map data = await callApi('song.getContextualTrackMix', params: {
|
||||
'sng_ids': [trackId]
|
||||
});
|
||||
return data['results']['data'].map<Track>((t) => Track.fromPrivateJson(t)).toList();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -150,33 +150,30 @@ class PlayerHelper {
|
|||
//Flow
|
||||
if (queueSource == null) return;
|
||||
|
||||
if (queueSource.id == 'flow') {
|
||||
List<Track> tracks = await deezerAPI.flow();
|
||||
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
||||
await AudioService.addQueueItems(mi);
|
||||
AudioService.skipToNext();
|
||||
return;
|
||||
List<Track> tracks = [];
|
||||
switch(queueSource.source) {
|
||||
case 'flow':
|
||||
tracks = await deezerAPI.flow();
|
||||
break;
|
||||
case 'smartradio': //SmartRadio/Artist radio
|
||||
tracks = await deezerAPI.smartRadio(queueSource.id);
|
||||
break;
|
||||
case 'libraryshuffle': //Library shuffle
|
||||
tracks = await deezerAPI.libraryShuffle(start: AudioService.queue.length);
|
||||
break;
|
||||
case 'mix':
|
||||
tracks = await deezerAPI.playMix(queueSource.id);
|
||||
// Deduplicate tracks with the same id
|
||||
List<String> queueIds = AudioService.queue.map((e) => e.id).toList();
|
||||
tracks.removeWhere((track) => queueIds.contains(track.id));
|
||||
break;
|
||||
default:
|
||||
print(queueSource.toJson());
|
||||
}
|
||||
|
||||
//SmartRadio/Artist radio
|
||||
if (queueSource.source == 'smartradio') {
|
||||
List<Track> tracks = await deezerAPI.smartRadio(queueSource.id);
|
||||
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
||||
await AudioService.addQueueItems(mi);
|
||||
AudioService.skipToNext();
|
||||
return;
|
||||
}
|
||||
|
||||
//Library shuffle
|
||||
if (queueSource.source == 'libraryshuffle') {
|
||||
List<Track> tracks = await deezerAPI.libraryShuffle(start: AudioService.queue.length);
|
||||
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
||||
await AudioService.addQueueItems(mi);
|
||||
AudioService.skipToNext();
|
||||
return;
|
||||
}
|
||||
|
||||
print(queueSource.toJson());
|
||||
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
||||
await AudioService.addQueueItems(mi);
|
||||
AudioService.skipToNext();
|
||||
}
|
||||
|
||||
//Play track from album
|
||||
|
@ -187,6 +184,16 @@ class PlayerHelper {
|
|||
source: 'album'
|
||||
));
|
||||
}
|
||||
|
||||
//Play mix by track
|
||||
Future playMix(String trackId, String trackTitle) async {
|
||||
List<Track> tracks = await deezerAPI.playMix(trackId);
|
||||
playFromTrackList(tracks, tracks[0].id, QueueSource(
|
||||
id: trackId,
|
||||
text: 'Mix based on'.i18n + ' $trackTitle',
|
||||
source: 'mix'
|
||||
));
|
||||
}
|
||||
//Play from artist top tracks
|
||||
Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async {
|
||||
await playFromTrackList(tracks, trackId, QueueSource(
|
||||
|
|
|
@ -7,6 +7,7 @@ import 'package:fluttertoast/fluttertoast.dart';
|
|||
import 'package:freezer/api/cache.dart';
|
||||
import 'package:freezer/api/deezer.dart';
|
||||
import 'package:freezer/api/download.dart';
|
||||
import 'package:freezer/api/player.dart';
|
||||
import 'package:freezer/ui/details_screens.dart';
|
||||
import 'package:freezer/ui/error.dart';
|
||||
import 'package:freezer/translations.i18n.dart';
|
||||
|
@ -132,6 +133,7 @@ class MenuSheet {
|
|||
addToPlaylist(track),
|
||||
downloadTrack(track),
|
||||
shareTile('track', track.id),
|
||||
playMix(track),
|
||||
showAlbum(track.album),
|
||||
...List.generate(track.artists.length, (i) => showArtist(track.artists[i])),
|
||||
...options
|
||||
|
@ -289,6 +291,14 @@ class MenuSheet {
|
|||
},
|
||||
);
|
||||
|
||||
Widget playMix(Track track) => ListTile(
|
||||
title: Text('Play mix'.i18n),
|
||||
leading: Icon(Icons.online_prediction),
|
||||
onTap: () async {
|
||||
playerHelper.playMix(track.id, track.title);
|
||||
_close();
|
||||
},
|
||||
);
|
||||
|
||||
//===================
|
||||
// ALBUM
|
||||
|
|
Loading…
Reference in New Issue