Merge branch 'feature/play_mix' of kilowatt36/freezer into master
This commit is contained in:
commit
d3c13444e7
@ -439,5 +439,13 @@ class DeezerAPI {
|
|||||||
});
|
});
|
||||||
return data['results']['data'].map<Track>((t) => Track.fromPrivateJson(t)).toList();
|
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
|
//Flow
|
||||||
if (queueSource == null) return;
|
if (queueSource == null) return;
|
||||||
|
|
||||||
if (queueSource.id == 'flow') {
|
List<Track> tracks = [];
|
||||||
List<Track> tracks = await deezerAPI.flow();
|
switch(queueSource.source) {
|
||||||
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
case 'flow':
|
||||||
await AudioService.addQueueItems(mi);
|
tracks = await deezerAPI.flow();
|
||||||
AudioService.skipToNext();
|
break;
|
||||||
return;
|
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
|
List<MediaItem> mi = tracks.map<MediaItem>((t) => t.toMediaItem()).toList();
|
||||||
if (queueSource.source == 'smartradio') {
|
await AudioService.addQueueItems(mi);
|
||||||
List<Track> tracks = await deezerAPI.smartRadio(queueSource.id);
|
AudioService.skipToNext();
|
||||||
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());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
//Play track from album
|
//Play track from album
|
||||||
@ -187,6 +184,16 @@ class PlayerHelper {
|
|||||||
source: 'album'
|
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
|
//Play from artist top tracks
|
||||||
Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async {
|
Future playFromTopTracks(List<Track> tracks, String trackId, Artist artist) async {
|
||||||
await playFromTrackList(tracks, trackId, QueueSource(
|
await playFromTrackList(tracks, trackId, QueueSource(
|
||||||
|
@ -7,6 +7,7 @@ import 'package:fluttertoast/fluttertoast.dart';
|
|||||||
import 'package:freezer/api/cache.dart';
|
import 'package:freezer/api/cache.dart';
|
||||||
import 'package:freezer/api/deezer.dart';
|
import 'package:freezer/api/deezer.dart';
|
||||||
import 'package:freezer/api/download.dart';
|
import 'package:freezer/api/download.dart';
|
||||||
|
import 'package:freezer/api/player.dart';
|
||||||
import 'package:freezer/ui/details_screens.dart';
|
import 'package:freezer/ui/details_screens.dart';
|
||||||
import 'package:freezer/ui/error.dart';
|
import 'package:freezer/ui/error.dart';
|
||||||
import 'package:freezer/translations.i18n.dart';
|
import 'package:freezer/translations.i18n.dart';
|
||||||
@ -132,6 +133,7 @@ class MenuSheet {
|
|||||||
addToPlaylist(track),
|
addToPlaylist(track),
|
||||||
downloadTrack(track),
|
downloadTrack(track),
|
||||||
shareTile('track', track.id),
|
shareTile('track', track.id),
|
||||||
|
playMix(track),
|
||||||
showAlbum(track.album),
|
showAlbum(track.album),
|
||||||
...List.generate(track.artists.length, (i) => showArtist(track.artists[i])),
|
...List.generate(track.artists.length, (i) => showArtist(track.artists[i])),
|
||||||
...options
|
...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
|
// ALBUM
|
||||||
|
Loading…
Reference in New Issue
Block a user